Move _setPosition from L.Popup to L.PopupBase so it can be inherited

Idea is to make it easier for plugins to create custom popups or
labels or whatever HTML element that would be bound to a map layer.
This commit is contained in:
Yohan Boniface 2015-11-15 19:18:29 +01:00
parent d8b7f6fcbe
commit 850ba7fe62
2 changed files with 20 additions and 20 deletions

View File

@ -98,26 +98,6 @@ L.Popup = L.PopupBase.extend({
this._tip = L.DomUtil.create('div', prefix + '-tip', this._tipContainer);
},
_updatePosition: function () {
if (!this._map) { return; }
var pos = this._map.latLngToLayerPoint(this._latlng),
offset = L.point(this.options.offset);
if (this._zoomAnimated) {
L.DomUtil.setPosition(this._container, pos);
} else {
offset = offset.add(pos);
}
var bottom = this._containerBottom = -offset.y,
left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
// bottom position the popup in case the height of the popup changes (images loading etc)
this._container.style.bottom = bottom + 'px';
this._container.style.left = left + 'px';
},
_updateLayout: function () {
var container = this._contentNode,
style = container.style;

View File

@ -151,6 +151,26 @@ L.PopupBase = L.Layer.extend({
node.appendChild(content);
}
this.fire('contentupdate');
},
_updatePosition: function () {
if (!this._map) { return; }
var pos = this._map.latLngToLayerPoint(this._latlng),
offset = L.point(this.options.offset);
if (this._zoomAnimated) {
L.DomUtil.setPosition(this._container, pos);
} else {
offset = offset.add(pos);
}
var bottom = this._containerBottom = -offset.y,
left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
// bottom position the popup in case the height of the popup changes (images loading etc)
this._container.style.bottom = bottom + 'px';
this._container.style.left = left + 'px';
}
});