vendor: 3,273 bytes, lines 1-119
1L.SimpleShape = {}; 2/** 3 * @class L.Draw.SimpleShape 4 * @aka Draw.SimpleShape 5 * @inherits L.Draw.Feature 6 */ 7L.Draw.SimpleShape = L.Draw.Feature.extend({ 8 options: { 9 repeatMode: false 10 }, 11 12 // @method initialize(): void 13 initialize: function (map, options) { 14 this._endLabelText = L.drawLocal.draw.handlers.simpleshape.tooltip.end; 15 16 L.Draw.Feature.prototype.initialize.call(this, map, options); 17 }, 18 19 // @method addHooks(): void 20 // Add listener hooks to this handler. 21 addHooks: function () { 22 L.Draw.Feature.prototype.addHooks.call(this); 23 if (this._map) { 24 this._mapDraggable = this._map.dragging.enabled(); 25 26 if (this._mapDraggable) { 27 this._map.dragging.disable(); 28 } 29 30 //TODO refactor: move cursor to styles 31 this._container.style.cursor = 'crosshair'; 32 33 this._tooltip.updateContent({text: this._initialLabelText}); 34 35 this._map 36 .on('mousedown', this._onMouseDown, this) 37 .on('mousemove', this._onMouseMove, this) 38 .on('touchstart', this._onMouseDown, this) 39 .on('touchmove', this._onMouseMove, this); 40 41 // we should prevent default, otherwise default behavior (scrolling) will fire, 42 // and that will cause document.touchend to fire and will stop the drawing 43 // (circle, rectangle) in touch mode. 44 // (update): we have to send passive now to prevent scroll, because by default it is {passive: true} now, which means, 45 // handler can't event.preventDefault 46 // check the news https://developers.google.com/web/updates/2016/06/passive-event-listeners 47 document.addEventListener('touchstart', L.DomEvent.preventDefault, {passive: false}); 48 } 49 }, 50 51 // @method removeHooks(): void 52 // Remove listener hooks from this handler. 53 removeHooks: function () { 54 L.Draw.Feature.prototype.removeHooks.call(this); 55 if (this._map) { 56 if (this._mapDraggable) { 57 this._map.dragging.enable(); 58 } 59 60 //TODO refactor: move cursor to styles 61 this._container.style.cursor = ''; 62 63 this._map 64 .off('mousedown', this._onMouseDown, this) 65 .off('mousemove', this._onMouseMove, this) 66 .off('touchstart', this._onMouseDown, this) 67 .off('touchmove', this._onMouseMove, this); 68 69 L.DomEvent.off(document, 'mouseup', this._onMouseUp, this); 70 L.DomEvent.off(document, 'touchend', this._onMouseUp, this); 71 72 document.removeEventListener('touchstart', L.DomEvent.preventDefault); 73 74 // If the box element doesn't exist they must not have moved the mouse, so don't need to destroy/return 75 if (this._shape) { 76 this._map.removeLayer(this._shape); 77 delete this._shape; 78 } 79 } 80 this._isDrawing = false; 81 }, 82 83 _getTooltipText: function () { 84 return { 85 text: this._endLabelText 86 }; 87 }, 88 89 _onMouseDown: function (e) { 90 this._isDrawing = true; 91 this._startLatLng = e.latlng; 92 93 L.DomEvent 94 .on(document, 'mouseup', this._onMouseUp, this) 95 .on(document, 'touchend', this._onMouseUp, this) 96 .preventDefault(e.originalEvent); 97 }, 98 99 _onMouseMove: function (e) { 100 var latlng = e.latlng; 101 102 this._tooltip.updatePosition(latlng); 103 if (this._isDrawing) { 104 this._tooltip.updateContent(this._getTooltipText()); 105 this._drawShape(latlng); 106 } 107 }, 108 109 _onMouseUp: function () { 110 if (this._shape) { 111 this._fireCreatedEvent(); 112 } 113 114 this.disable(); 115 if (this.options.repeatMode) { 116 this.enable(); 117 } 118 } 119});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.