Style.StylePicker.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. L.Style = {};
  2. L.Style.StylePicker = L.Handler.extend({
  3. includes: L.Mixin.Events,
  4. statics: {
  5. TYPE: 'stylePicker'
  6. },
  7. options:{},
  8. initialize: function (map, options) {
  9. this._map = map;
  10. this._container = map._container;
  11. this._overlayPane = map._panes.overlayPane;
  12. this._popupPane = map._panes.popupPane;
  13. this.type = L.Style.StylePicker.TYPE;
  14. // Merge default shapeOptions options with custom shapeOptions
  15. if (options && options.shapeOptions) {
  16. options.shapeOptions = L.Util.extend({}, this.options.shapeOptions, options.shapeOptions);
  17. }
  18. L.Util.extend(this.options, options);
  19. },
  20. enable: function () {
  21. if (this._enabled) {
  22. this.disable();
  23. return;
  24. }
  25. L.Handler.prototype.enable.call(this);
  26. this.fire('enabled', { handler: this.type });
  27. },
  28. fireEnable:function(){
  29. if (this._enabled) {
  30. return;
  31. }
  32. L.Handler.prototype.enable.call(this);
  33. this.fire('enabled', { handler: this.type });
  34. },
  35. disable: function () {
  36. if (!this._enabled) {
  37. //this.enable();
  38. return;
  39. }
  40. L.Handler.prototype.disable.call(this);
  41. this.fire('disabled', { handler: this.type });
  42. },
  43. addHooks: function () {
  44. if (this._map) {
  45. L.DomUtil.disableTextSelection();
  46. //this._tooltip = new L.DrawTooltip(this._map);
  47. //L.DomEvent.addListener(this._container, 'keyup', this._cancelDrawing, this);
  48. }
  49. },
  50. removeHooks: function () {
  51. if (this._map) {
  52. L.DomUtil.enableTextSelection();
  53. //this._tooltip.dispose();
  54. //this._tooltip = null;
  55. //L.DomEvent.removeListener(this._container, 'keyup', this._cancelDrawing);
  56. }
  57. },
  58. setOptions: function (options) {
  59. L.setOptions(this, options);
  60. },
  61. _fireCreatedEvent: function (layer) {
  62. this._map.fire('style:created', { layer: layer, layerType: this.type });
  63. },
  64. // Cancel drawing when the escape key is pressed
  65. _cancelDrawing: function (e) {
  66. if (e.keyCode === 27) {
  67. this.disable();
  68. }
  69. }
  70. });