From 937f7f613edb0034750ad7fc851609096a79e963 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Sat, 12 Oct 2019 21:13:34 +0100 Subject: [PATCH] Resolve constraints using anchor Resolve constraints using anchor if view state is the result of cancelling an animation with anchor --- src/ol/View.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ol/View.js b/src/ol/View.js index a3fde0570f..aa6b287369 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -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 }); } }