vendor: 3,193 bytes, lines 1-127
1/** 2 * @class L.Draw.Marker 3 * @aka Draw.Marker 4 * @inherits L.Draw.Feature 5 */ 6L.Draw.Marker = L.Draw.Feature.extend({ 7 statics: { 8 TYPE: 'marker' 9 }, 10 11 options: { 12 icon: new L.Icon.Default(), 13 repeatMode: false, 14 zIndexOffset: 2000 // This should be > than the highest z-index any markers 15 }, 16 17 // @method initialize(): void 18 initialize: function (map, options) { 19 // Save the type so super can fire, need to do this as cannot do this.TYPE :( 20 this.type = L.Draw.Marker.TYPE; 21 22 this._initialLabelText = L.drawLocal.draw.handlers.marker.tooltip.start; 23 24 L.Draw.Feature.prototype.initialize.call(this, map, options); 25 }, 26 27 // @method addHooks(): void 28 // Add listener hooks to this handler. 29 addHooks: function () { 30 L.Draw.Feature.prototype.addHooks.call(this); 31 32 if (this._map) { 33 this._tooltip.updateContent({text: this._initialLabelText}); 34 35 // Same mouseMarker as in Draw.Polyline 36 if (!this._mouseMarker) { 37 this._mouseMarker = L.marker(this._map.getCenter(), { 38 icon: L.divIcon({ 39 className: 'leaflet-mouse-marker', 40 iconAnchor: [20, 20], 41 iconSize: [40, 40] 42 }), 43 opacity: 0, 44 zIndexOffset: this.options.zIndexOffset 45 }); 46 } 47 48 this._mouseMarker 49 .on('click', this._onClick, this) 50 .addTo(this._map); 51 52 this._map.on('mousemove', this._onMouseMove, this); 53 this._map.on('click', this._onTouch, this); 54 } 55 }, 56 57 // @method removeHooks(): void 58 // Remove listener hooks from this handler. 59 removeHooks: function () { 60 L.Draw.Feature.prototype.removeHooks.call(this); 61 62 if (this._map) { 63 this._map 64 .off('click', this._onClick, this) 65 .off('click', this._onTouch, this); 66 if (this._marker) { 67 this._marker.off('click', this._onClick, this); 68 this._map 69 .removeLayer(this._marker); 70 delete this._marker; 71 } 72 73 this._mouseMarker.off('click', this._onClick, this); 74 this._map.removeLayer(this._mouseMarker); 75 delete this._mouseMarker; 76 77 this._map.off('mousemove', this._onMouseMove, this); 78 } 79 }, 80 81 _onMouseMove: function (e) { 82 var latlng = e.latlng; 83 84 this._tooltip.updatePosition(latlng); 85 this._mouseMarker.setLatLng(latlng); 86 87 if (!this._marker) { 88 this._marker = this._createMarker(latlng); 89 // Bind to both marker and map to make sure we get the click event. 90 this._marker.on('click', this._onClick, this); 91 this._map 92 .on('click', this._onClick, this) 93 .addLayer(this._marker); 94 } 95 else { 96 latlng = this._mouseMarker.getLatLng(); 97 this._marker.setLatLng(latlng); 98 } 99 }, 100 101 _createMarker: function (latlng) { 102 return new L.Marker(latlng, { 103 icon: this.options.icon, 104 zIndexOffset: this.options.zIndexOffset 105 }); 106 }, 107 108 _onClick: function () { 109 this._fireCreatedEvent(); 110 111 this.disable(); 112 if (this.options.repeatMode) { 113 this.enable(); 114 } 115 }, 116 117 _onTouch: function (e) { 118 // called on click & tap, only really does any thing on tap 119 this._onMouseMove(e); // creates & places marker 120 this._onClick(); // permanently places marker & ends interaction 121 }, 122 123 _fireCreatedEvent: function () { 124 var marker = new L.Marker.Touch(this._marker.getLatLng(), {icon: this.options.icon}); 125 L.Draw.Feature.prototype._fireCreatedEvent.call(this, marker); 126 } 127});
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.