fix popup offseting

This commit is contained in:
Patrick Arlt 2015-07-01 13:00:05 -07:00 committed by Vladimir Agafonkin
parent 3687ed81e6
commit 6bf0f98796
2 changed files with 17 additions and 1 deletions

View File

@ -41,6 +41,7 @@
var poly = new L.Polygon([[0, 10], [0, 15.5], [0, 50], [20, 20.5]]);
map.addLayer(poly);
poly.bindPopup("Polygon");
markerDraggable.on('click', function(e) {

View File

@ -26,6 +26,9 @@ L.Layer.include({
this._popupHandlersAdded = true;
}
// save the originally passed offset
this._originalPopupOffset = this._popup.options.offset;
return this;
},
@ -60,9 +63,16 @@ L.Layer.include({
}
if (this._popup && this._map) {
// set the popup offset for this layer
this._popup.options.offset = this._popupAnchor(layer);
// set popup source to this layer
this._popup._source = layer;
// update the popup (content, layout, ect...)
this._popup.update();
// open the popup on the map
this._map.openPopup(this._popup, latlng);
}
@ -126,8 +136,13 @@ L.Layer.include({
},
_popupAnchor: function (layer) {
// where shold we anchor the popup on this layer?
var anchor = layer._getPopupAnchor ? layer._getPopupAnchor() : [0, 0];
var offsetToAdd = layer._popup ? layer._popup.options.offset : L.Popup.prototype.options.offset;
// add the users passed offset to that
var offsetToAdd = this._originalPopupOffset || L.Popup.prototype.options.offset;
// return the final point to anchor the popup
return L.point(anchor).add(offsetToAdd);
},