Merge pull request #10120 from mike-000/patch-9

Resolve constraints using anchor if following a cancelled animation
This commit is contained in:
Olivier Guyot
2019-12-03 09:37:48 +01:00
committed by GitHub

View File

@@ -312,6 +312,12 @@ class View extends BaseObject {
*/
this.targetRotation_;
/**
* @private
* @type {import("./coordinate.js").Coordinate|undefined}
*/
this.cancelAnchor_ = undefined;
if (options.center) {
options.center = fromUserCoordinate(options.center, this.projection_);
}
@@ -584,13 +590,19 @@ class View extends BaseObject {
*/
cancelAnimations() {
this.setHint(ViewHint.ANIMATING, -this.hints_[ViewHint.ANIMATING]);
let anchor;
for (let i = 0, ii = this.animations_.length; i < ii; ++i) {
const series = this.animations_[i];
if (series[0].callback) {
animationCallback(series[0].callback, false);
}
anchor = anchor ||
series.filter(function(animation) {
return !animation.complete;
})[0].anchor;
}
this.animations_.length = 0;
this.cancelAnchor_ = anchor;
}
/**
@@ -1390,6 +1402,7 @@ class View extends BaseObject {
if (this.getAnimating() && !opt_doNotCancelAnims) {
this.cancelAnimations();
}
this.cancelAnchor_ = undefined;
}
/**
@@ -1410,7 +1423,7 @@ class View extends BaseObject {
const newResolution = this.constraints_.resolution(this.targetResolution_, direction, size);
const newCenter = this.constraints_.center(this.targetCenter_, newResolution, size);
if (duration === 0) {
if (duration === 0 && !this.cancelAnchor_) {
this.targetResolution_ = newResolution;
this.targetRotation_ = newRotation;
this.targetCenter_ = newCenter;
@@ -1418,6 +1431,9 @@ class View extends BaseObject {
return;
}
const anchor = opt_anchor || (duration === 0 ? this.cancelAnchor_ : undefined);
this.cancelAnchor_ = undefined;
if (this.getResolution() !== newResolution ||
this.getRotation() !== newRotation ||
!this.getCenterInternal() ||
@@ -1433,7 +1449,7 @@ class View extends BaseObject {
resolution: newResolution,
duration: duration,
easing: easeOut,
anchor: opt_anchor
anchor: anchor
});
}
}