From f67baa0dc0b784337881a37c2b580c8f55465ddb Mon Sep 17 00:00:00 2001 From: Olivier Guyot Date: Fri, 22 Feb 2019 15:00:57 +0100 Subject: [PATCH] Interactions / fix zoom level when a zoom interaction ends --- src/ol/interaction/DragRotateAndZoom.js | 2 +- src/ol/interaction/MouseWheelZoom.js | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ol/interaction/DragRotateAndZoom.js b/src/ol/interaction/DragRotateAndZoom.js index 2a43740c03..3e750df327 100644 --- a/src/ol/interaction/DragRotateAndZoom.js +++ b/src/ol/interaction/DragRotateAndZoom.js @@ -109,7 +109,7 @@ class DragRotateAndZoom extends PointerInteraction { const map = mapBrowserEvent.map; const view = map.getView(); - const direction = this.lastScaleDelta_ - 1; + const direction = this.lastScaleDelta_ > 1 ? 1 : -1; view.endInteraction(this.duration_, direction); this.lastScaleDelta_ = 0; return false; diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index a08e657956..30548d2587 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -57,7 +57,13 @@ class MouseWheelZoom extends Interaction { * @private * @type {number} */ - this.delta_ = 0; + this.totalDelta_ = 0; + + /** + * @private + * @type {number} + */ + this.lastDelta_ = 0; /** * @private @@ -134,7 +140,7 @@ class MouseWheelZoom extends Interaction { endInteraction_() { this.trackpadTimeoutId_ = undefined; const view = this.getMap().getView(); - view.endInteraction(); + view.endInteraction(undefined, Math.sign(this.lastDelta_), this.lastAnchor_); } /** @@ -181,6 +187,8 @@ class MouseWheelZoom extends Interaction { if (delta === 0) { return false; + } else { + this.lastDelta_ = delta; } const now = Date.now(); @@ -208,7 +216,7 @@ class MouseWheelZoom extends Interaction { return false; } - this.delta_ += delta; + this.totalDelta_ += delta; const timeLeft = Math.max(this.timeout_ - (now - this.startTime_), 0); @@ -228,10 +236,10 @@ class MouseWheelZoom extends Interaction { view.cancelAnimations(); } const maxDelta = MAX_DELTA; - const delta = clamp(this.delta_, -maxDelta, maxDelta); + const delta = clamp(this.totalDelta_, -maxDelta, maxDelta); zoomByDelta(view, -delta, this.lastAnchor_, this.duration_); this.mode_ = undefined; - this.delta_ = 0; + this.totalDelta_ = 0; this.lastAnchor_ = null; this.startTime_ = undefined; this.timeoutId_ = undefined;