From bfc94d3176cb213e1cb700fb448ab048149b4b6f Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Wed, 31 Oct 2012 15:34:19 +0200 Subject: [PATCH] add Path closePopup method, fix a couple of issues --- CHANGELOG.md | 2 +- src/layer/vector/Path.Popup.js | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8ff8999..469e4010 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ An in-progress version being developed on the master branch. * Added optional `delta` argument to `Map` `zoomIn` and `zoomOut` (1 by default). * Added `isValid` method to `LatLngBounds` and `Bounds` (by [@domoritz](https://github.com/domoritz)). [#972](https://github.com/CloudMade/Leaflet/pull/972) * Improved markers and vectors click event so that it propagates to map if no one is listening to it (by [@danzel](https://github.com/danzel)). [#834](https://github.com/CloudMade/Leaflet/issues/834) [#1033](https://github.com/CloudMade/Leaflet/pull/1033) - * Added `Path` `unbindPopup` method. + * Added `Path` `unbindPopup` and `closePopup` methods. * Added `Path` `remove` event. * Added `Marker` `riseOnHover` and `riseOffset` options (for bringing markers to front on hover, disabled by default) (by [jacobtoye](https://github.com/jacobtoye)). [#914](https://github.com/CloudMade/Leaflet/pull/914) [#920](https://github.com/CloudMade/Leaflet/issues/920) * Added `Marker` `move` and `remove` events. diff --git a/src/layer/vector/Path.Popup.js b/src/layer/vector/Path.Popup.js index f0b9d97f..5b40726c 100644 --- a/src/layer/vector/Path.Popup.js +++ b/src/layer/vector/Path.Popup.js @@ -6,7 +6,7 @@ L.Path.include({ bindPopup: function (content, options) { - if (!this._popup || this._popup.options !== options) { + if (!this._popup || options) { this._popup = new L.Popup(options, this); } @@ -15,7 +15,8 @@ L.Path.include({ if (!this._popupHandlersAdded) { this .on('click', this._openPopup, this) - .on('remove', this._closePopup, this); + .on('remove', this.closePopup, this); + this._popupHandlersAdded = true; } @@ -28,6 +29,8 @@ L.Path.include({ this .off('click', this.openPopup) .off('remove', this.closePopup); + + this._popupHandlersAdded = false; } return this; }, @@ -35,6 +38,7 @@ L.Path.include({ openPopup: function (latlng) { if (this._popup) { + // open the popup from one of the path's points if not specified latlng = latlng || this._latlng || this._latlngs[Math.floor(this._latlngs.length / 2)]; @@ -44,12 +48,15 @@ L.Path.include({ return this; }, + closePopup: function () { + if (this._popup) { + this._popup._close(); + } + return this; + }, + _openPopup: function (e) { this._popup.setLatLng(e.latlng); this._map.openPopup(this._popup); - }, - - _closePopup: function () { - this._popup._close(); } });