mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-15 22:36:58 +00:00
Fix: autoPan doesn't work when popup-content gets updated while a panning-animation is running (#6365)
* Add test for autoPan-option * stop any running paning animation when popup autoPan gets adjusted * Fixed some spelling errors
This commit is contained in:

committed by
Per Liedman

parent
dc8bb15b68
commit
55755f41be
@ -295,6 +295,56 @@ describe('Popup', function () {
|
||||
expect(map.hasLayer(layer._popup)).to.be(true);
|
||||
});
|
||||
|
||||
describe("autoPan option should pan popup into visibility", function () {
|
||||
|
||||
// Helper function which calculates the offset of the map-container & popup-container in pixel
|
||||
function getPopupOffset(map, popup) {
|
||||
var mapOffset = map._container.getBoundingClientRect().top;
|
||||
var popupOffset = popup._container.getBoundingClientRect().top;
|
||||
return popupOffset - mapOffset;
|
||||
}
|
||||
|
||||
it("should not pan map to show popup content if autoPan is disabled", function (done) {
|
||||
map.on('popupopen', function (e) {
|
||||
var popupTopOffset = getPopupOffset(map, e.popup);
|
||||
expect(popupTopOffset).to.be.below(0, "The upper edge of the popup should not be visible");
|
||||
done();
|
||||
});
|
||||
map.openPopup('<div style="height: 400px;"></div>', L.latLng(58.4, 37.6), {
|
||||
autoPan: false
|
||||
});
|
||||
});
|
||||
|
||||
it("should pan map to show popup content if autoPan is enabled", function (done) {
|
||||
map.on('popupopen', function (e) {
|
||||
var popupTopOffset = getPopupOffset(map, e.popup);
|
||||
expect(popupTopOffset).to.be(10, "The upper edge of the popup have a padding of 10");
|
||||
done();
|
||||
});
|
||||
map.openPopup('<div style="height: 400px;"></div>', L.latLng(58.4, 37.6), {
|
||||
autoPan: true,
|
||||
autoPanPadding: L.point(10, 10)
|
||||
});
|
||||
});
|
||||
|
||||
it("should pan map to show popup content if autoPan is enabled even when animating", function (done) {
|
||||
map.on('popupopen', function (e) {
|
||||
var popupTopOffset = getPopupOffset(map, e.popup);
|
||||
expect(popupTopOffset).to.be(10);
|
||||
done();
|
||||
});
|
||||
|
||||
map.panTo([55.8, 40.7], {
|
||||
animate: true,
|
||||
duration: 1
|
||||
});
|
||||
|
||||
map.openPopup('<div style="height: 400px;"></div>', L.latLng(58.4, 37.6), {
|
||||
autoPan: true,
|
||||
autoPanPadding: L.point(10, 10)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("L.Map#openPopup", function () {
|
||||
|
@ -235,7 +235,8 @@ export var Popup = DivOverlay.extend({
|
||||
},
|
||||
|
||||
_adjustPan: function () {
|
||||
if (!this.options.autoPan || (this._map._panAnim && this._map._panAnim._inProgress)) { return; }
|
||||
if (!this.options.autoPan) { return; }
|
||||
if (this._map._panAnim) { this._map._panAnim.stop(); }
|
||||
|
||||
var map = this._map,
|
||||
marginBottom = parseInt(DomUtil.getStyle(this._container, 'marginBottom'), 10) || 0,
|
||||
|
Reference in New Issue
Block a user