Add map events for popup open/close.

This commit is contained in:
Andy Chosak 2011-11-22 10:45:43 -05:00
parent bd511151a0
commit eb9be64bd8
5 changed files with 18 additions and 11 deletions

View File

@ -11,8 +11,10 @@ L.Popup = L.Class.extend({
autoPanPadding: new L.Point(5, 5)
},
initialize: function(options) {
initialize: function(options, source) {
L.Util.setOptions(this, options);
this._source = source;
},
onAdd: function(map) {
@ -64,7 +66,7 @@ L.Popup = L.Class.extend({
_close: function() {
if (this._opened) {
this._map.removeLayer(this);
this._map.closePopup();
}
},

View File

@ -24,7 +24,7 @@ L.Marker.include({
this.on('click', this.openPopup, this);
}
this._popup = new L.Popup(options);
this._popup = new L.Popup(options, this);
this._popup.setContent(content);
return this;
@ -37,4 +37,4 @@ L.Marker.include({
}
return this;
}
});
});

View File

@ -30,13 +30,13 @@ L.Marker = L.Class.extend({
onRemove: function(map) {
this._removeIcon();
this._map = null;
// TODO move to Marker.Popup.js
if (this.closePopup) {
this.closePopup();
}
this._map = null;
map.off('viewreset', this._reset, this);
},

View File

@ -5,7 +5,7 @@
L.Path.include({
bindPopup: function(content, options) {
if (!this._popup || this._popup.options !== options) {
this._popup = new L.Popup(options);
this._popup = new L.Popup(options, this);
}
this._popup.setContent(content);
@ -21,4 +21,4 @@ L.Path.include({
this._popup.setLatLng(e.latlng);
this._map.openPopup(this._popup);
}
});
});

View File

@ -3,13 +3,18 @@ L.Map.include({
openPopup: function(popup) {
this.closePopup();
this._popup = popup;
return this.addLayer(popup);
this.addLayer(popup);
this.fire('popupopen', { popup: this._popup });
return this;
},
closePopup: function() {
closePopup: function(popup) {
if (this._popup) {
this.removeLayer(this._popup);
this.fire('popupclose', { popup: this._popup });
this._popup = null;
}
return this;
}
});
});