View / avoid solving constraints related to map size change during anim

This commit is contained in:
Olivier Guyot
2020-04-02 14:14:40 +02:00
parent a073c5ab1e
commit 32321e381c
3 changed files with 53 additions and 2 deletions

View File

@@ -989,7 +989,7 @@ class PluggableMap extends BaseObject {
* @private
*/
handleSizeChanged_() {
if (this.getView()) {
if (this.getView() && !this.getView().getAnimating()) {
this.getView().resolveConstraints(0);
}

View File

@@ -762,12 +762,15 @@ 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];
if (!this.getAnimating()) {
this.resolveConstraints(0);
}
}
/**
* Get the view center.

View File

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