add Path closePopup method, fix a couple of issues

This commit is contained in:
Vladimir Agafonkin 2012-10-31 15:34:19 +02:00
parent 82ca621091
commit bfc94d3176
2 changed files with 14 additions and 7 deletions

View File

@ -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.

View File

@ -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();
}
});