From 32321e381cead34f231724120ea834bb2320c69b Mon Sep 17 00:00:00 2001 From: Olivier Guyot Date: Thu, 2 Apr 2020 14:14:40 +0200 Subject: [PATCH] View / avoid solving constraints related to map size change during anim --- src/ol/PluggableMap.js | 2 +- src/ol/View.js | 5 +++- test/spec/ol/view.test.js | 48 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index 792215e1cc..5cd3ad7f22 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -989,7 +989,7 @@ class PluggableMap extends BaseObject { * @private */ handleSizeChanged_() { - if (this.getView()) { + if (this.getView() && !this.getView().getAnimating()) { this.getView().resolveConstraints(0); } diff --git a/src/ol/View.js b/src/ol/View.js index bcccad7e04..3d5be60121 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -762,11 +762,14 @@ class View extends BaseObject { * Stores the viewport size on the view. The viewport size is not read every time from the DOM * to avoid performance hit and layout reflow. * This should be done on map size change. + * Note: the constraints are not resolved during an animation to avoid stopping it * @param {import("./size.js").Size=} opt_size Viewport size; if undefined, [100, 100] is assumed */ setViewportSize(opt_size) { this.viewportSize_ = Array.isArray(opt_size) ? opt_size.slice() : [100, 100]; - this.resolveConstraints(0); + if (!this.getAnimating()) { + this.resolveConstraints(0); + } } /** diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 3e186909e9..e10af8c0cb 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -1090,6 +1090,54 @@ describe('ol.View', function() { }); + it('completes even though Map#setSize is called', function(done) { + + const view = new View({ + center: [0, 0], + zoom: 0 + }); + const map = new Map({ + view + }); + map.setSize([110, 90]); + + view.animate({ + zoom: 1, + duration: 25 + }, function() { + expect(view.getZoom()).to.be(1); + done(); + }); + + setTimeout(function() { + map.setSize([100, 100]); + }, 10); + + }); + + it('completes even though Map#updateSize is called', function(done) { + + const view = new View({ + center: [0, 0], + zoom: 0 + }); + const map = new Map({ + view + }); + + view.animate({ + zoom: 1, + duration: 25 + }, function() { + expect(view.getZoom()).to.be(1); + done(); + }); + + setTimeout(function() { + map.updateSize(); + }, 10); + + }); }); describe('#cancelAnimations()', function() {