From 4dadf840af1c58ab2494e4f038d20df815cd4923 Mon Sep 17 00:00:00 2001 From: Falke Design Date: Thu, 25 Nov 2021 19:34:19 +0100 Subject: [PATCH] Fix Popup keepInView if the map needs to panned over a long distance (#7792) * Fix keepInView recursion #5035 * Fix test Co-authored-by: Vladimir Agafonkin --- spec/suites/layer/PopupSpec.js | 9 ++++----- src/layer/Popup.js | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/spec/suites/layer/PopupSpec.js b/spec/suites/layer/PopupSpec.js index 02264f777..c85fcdcc6 100644 --- a/spec/suites/layer/PopupSpec.js +++ b/spec/suites/layer/PopupSpec.js @@ -413,7 +413,7 @@ describe("L.Map#openPopup", function () { .down().moveBy(10, 10, 20).up(); }); - it('keeps the popup in the view (keepInView)', function (done) { + it('moves the map over a long distance to the popup if it is not in the view (keepInView)', function (done) { c.style.position = 'absolute'; c.style.left = 0; c.style.top = 0; @@ -423,14 +423,13 @@ describe("L.Map#openPopup", function () { map.options.inertia = false; var spy = sinon.spy(); - var p = new L.Popup({keepInView: true}).setContent('Popup').setLatLng(center); - map.openPopup(p); map.on('autopanstart', spy); + var p = new L.Popup({keepInView: true}).setContent('Popup').setLatLng([center[0], center[1] + 50]); + map.openPopup(p); - map.panBy([200, 0]); setTimeout(function () { expect(spy.called).to.be(true); - expect(map.getCenter().equals([55.801280971180454, 40.86914062500001])).to.be(true); + expect(map.getBounds().contains(p.getLatLng())).to.be(true); done(); }, 800); }); diff --git a/src/layer/Popup.js b/src/layer/Popup.js index aa8d9057d..810a37917 100644 --- a/src/layer/Popup.js +++ b/src/layer/Popup.js @@ -235,7 +235,7 @@ export var Popup = DivOverlay.extend({ DomUtil.setPosition(this._container, pos.add(anchor)); }, - _adjustPan: function () { + _adjustPan: function (e) { if (!this.options.autoPan) { return; } if (this._map._panAnim) { this._map._panAnim.stop(); } @@ -275,7 +275,7 @@ export var Popup = DivOverlay.extend({ if (dx || dy) { map .fire('autopanstart') - .panBy([dx, dy]); + .panBy([dx, dy], {animate: e && e.type === 'moveend'}); } },