PageSourceSearch

https://geo.stat.gov.lv/stage2/lib/leaflet-draw/draw/handler/Draw.Marker.js

js stat.gov.lv collected 2026-10-02 03:35:21 UTC 3,058 bytes, 120 lines download raw bytes

vendor: 3,058 bytes, lines 1-120
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		L.Draw.Feature.prototype.initialize.call(this, map, options);
23	},
24
25	// @method addHooks(): void
26	// Add listener hooks to this handler.
27	addHooks: function () {
28		L.Draw.Feature.prototype.addHooks.call(this);
29
30		if (this._map) {
31			this._tooltip.updateContent({ text: L.drawLocal.draw.handlers.marker.tooltip.start });
32
33			// Same mouseMarker as in Draw.Polyline
34			if (!this._mouseMarker) {
35				this._mouseMarker = L.marker(this._map.getCenter(), {
36					icon: L.divIcon({
37						className: 'leaflet-mouse-marker',
38						iconAnchor: [20, 20],
39						iconSize: [40, 40]
40					}),
41					opacity: 0,
42					zIndexOffset: this.options.zIndexOffset
43				});
44			}
45
46			this._mouseMarker
47				.on('click', this._onClick, this)
48				.addTo(this._map);
49
50			this._map.on('mousemove', this._onMouseMove, this);
51			this._map.on('click', this._onTouch, this);
52		}
53	},
54
55	// @method removeHooks(): void
56	// Remove listener hooks from this handler.
57	removeHooks: function () {
58		L.Draw.Feature.prototype.removeHooks.call(this);
59
60		if (this._map) {
61			if (this._marker) {
62				this._marker.off('click', this._onClick, this);
63				this._map
64					.off('click', this._onClick, this)
65					.off('click', this._onTouch, this)
66					.removeLayer(this._marker);
67				delete this._marker;
68			}
69
70			this._mouseMarker.off('click', this._onClick, this);
71			this._map.removeLayer(this._mouseMarker);
72			delete this._mouseMarker;
73
74			this._map.off('mousemove', this._onMouseMove, this);
75		}
76	},
77
78	_onMouseMove: function (e) {
79		var latlng = e.latlng;
80
81		this._tooltip.updatePosition(latlng);
82		this._mouseMarker.setLatLng(latlng);
83
84		if (!this._marker) {
85			this._marker = new L.Marker(latlng, {
86				icon: this.options.icon,
87				zIndexOffset: this.options.zIndexOffset
88			});
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	_onClick: function () {
102		this._fireCreatedEvent();
103
104		this.disable();
105		if (this.options.repeatMode) {
106			this.enable();
107		}
108	},
109
110	_onTouch: function (e) {
111		// called on click & tap, only really does any thing on tap
112		this._onMouseMove(e); // creates & places marker
113		this._onClick(); // permanently places marker & ends interaction
114	},
115
116	_fireCreatedEvent: function () {
117		var marker = new L.Marker.Touch(this._marker.getLatLng(), { icon: this.options.icon });
118		L.Draw.Feature.prototype._fireCreatedEvent.call(this, marker);
119	}
120});

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.