/* * Popup extension to L.Marker, adding popup-related methods. */ L.Marker.include({ openPopup: function () { if (this._popup && this._map && !this._map.hasLayer(this._popup)) { 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 || [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); } if (content instanceof L.Popup) { L.setOptions(content, options); this._popup = content; } else { this._popup = new L.Popup(options, this) .setContent(content); } return this; }, setPopupContent: function (content) { if (this._popup) { this._popup.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); } });