Resolve constraints using anchor
Resolve constraints using anchor if view state is the result of cancelling an animation with anchor
This commit is contained in:
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user