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:
René Schleusner
2018-10-28 11:48:33 +01:00
committed by Per Liedman
parent dc8bb15b68
commit 55755f41be
2 changed files with 52 additions and 1 deletions

View File

@ -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 () {

View File

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