1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/*
* L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable.
*/
L.Handler.MarkerDrag = L.Handler.extend({
initialize: function(marker) {
this._marker = marker;
},
enable: function() {
if (this._enabled) { return; }
if (!this._draggable) {
this._draggable = new L.Draggable(this._marker._icon, this._marker._icon);
this._draggable.on('dragstart', this._onDragStart, this);
this._draggable.on('drag', this._onDrag, this);
this._draggable.on('dragend', this._onDragEnd, this);
}
this._draggable.enable();
this._enabled = true;
},
disable: function() {
if (!this._enabled) { return; }
this._draggable.disable();
this._enabled = false;
},
moved: function() {
return this._draggable && this._draggable._moved;
},
_onDragStart: function(e) {
this._marker.closePopup();
this._marker.fire('movestart');
this._marker.fire('dragstart');
},
_onDrag: function(e) {
// update shadow position
var iconPos = L.DomUtil.getPosition(this._marker._icon);
L.DomUtil.setPosition(this._marker._shadow, iconPos);
this._marker._latlng = this._marker._map.layerPointToLatLng(iconPos);
this._marker.fire('move');
this._marker.fire('drag');
},
_onDragEnd: function() {
this._marker.fire('moveend');
this._marker.fire('dragend');
}
});
|