forked from Leaflet/Leaflet
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Marker.Popup.js
60 lines (48 loc) · 1.23 KB
/
Marker.Popup.js
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
55
56
57
58
59
60
/*
* Popup extension to L.Marker, adding popup-related methods.
*/
L.Marker.include({
openPopup: function () {
if (this._popup && this._map) {
this._popup.setLatLng(this._latlng);
this._map.openPopup(this._popup);
}
return this;
},
closePopup: function () {
if (this._popup) {
this._popup._close();
}
return this;
},
bindPopup: function (content, options) {
var anchor = L.point(this.options.icon.options.popupAnchor) || new L.Point(0, 0);
anchor = anchor.add(L.Popup.prototype.options.offset);
if (options && options.offset) {
anchor = anchor.add(options.offset);
}
options = L.extend({offset: anchor}, options);
if (!this._popup) {
this
.on('click', this.openPopup, this)
.on('remove', this.closePopup, this)
.on('move', this._movePopup, this);
}
this._popup = new L.Popup(options, this)
.setContent(content);
return this;
},
unbindPopup: function () {
if (this._popup) {
this._popup = null;
this
.off('click', this.openPopup)
.off('remove', this.closePopup)
.off('move', this._movePopup);
}
return this;
},
_movePopup: function (e) {
this._popup.setLatLng(e.latlng);
}
});