From fc4ec899ca055d3a27167f2728de40b477b32a84 Mon Sep 17 00:00:00 2001 From: wussup Date: Mon, 20 Apr 2020 15:36:19 +0200 Subject: [PATCH 1/6] Add constrainResolution option Sometimes we may have the functionality to set scale/resolution provided by a user and it can be any number (so constrainResolution in View class is not useful), but we would like to have constrainResolution in mouse wheel zoom event. --- src/ol/interaction/MouseWheelZoom.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index cb52c97542..b9e89b35ae 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -29,6 +29,9 @@ export const Mode = { * @property {boolean} [useAnchor=true] Enable zooming using the mouse's * location as the anchor. When set to `false`, zooming in and out will zoom to * the center of the screen instead of zooming on the mouse's location. + * @property {boolean} [constrainResolution=false] If true, the mouse wheel zoom + * event will always animate to the closest zoom level after an interaction; + * false means intermediary zoom levels are allowed. */ /** @@ -84,6 +87,12 @@ class MouseWheelZoom extends Interaction { this.useAnchor_ = options.useAnchor !== undefined ? options.useAnchor : true; + /** + * @private + * @type {boolean} + */ + this.constrainResolution_ = options.constrainResolution !== undefined ? options.constrainResolution : false; + /** * @private * @type {import("../events/condition.js").Condition} @@ -214,7 +223,7 @@ class MouseWheelZoom extends Interaction { } const view = map.getView(); - if (this.mode_ === Mode.TRACKPAD && !view.getConstrainResolution()) { + if (this.mode_ === Mode.TRACKPAD && !(view.getConstrainResolution() || this.constrainResolution_)) { if (this.trackpadTimeoutId_) { clearTimeout(this.trackpadTimeoutId_); } else { @@ -260,7 +269,7 @@ class MouseWheelZoom extends Interaction { -this.maxDelta_ * this.deltaPerZoom_, this.maxDelta_ * this.deltaPerZoom_ ) / this.deltaPerZoom_; - if (view.getConstrainResolution()) { + if (view.getConstrainResolution() || this.constrainResolution_) { // view has a zoom constraint, zoom by 1 delta = delta ? (delta > 0 ? 1 : -1) : 0; } From aca8e0880c0127369a4387bb31ca6958a0c59865 Mon Sep 17 00:00:00 2001 From: wussup Date: Mon, 20 Apr 2020 15:39:36 +0200 Subject: [PATCH 2/6] Update MouseWheelZoom.js --- src/ol/interaction/MouseWheelZoom.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index b9e89b35ae..a735b9dec8 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -223,7 +223,8 @@ class MouseWheelZoom extends Interaction { } const view = map.getView(); - if (this.mode_ === Mode.TRACKPAD && !(view.getConstrainResolution() || this.constrainResolution_)) { + if (this.mode_ === Mode.TRACKPAD && + !(view.getConstrainResolution() || this.constrainResolution_)) { if (this.trackpadTimeoutId_) { clearTimeout(this.trackpadTimeoutId_); } else { From ce7be5397027839734f318485ceb71ed26f45335 Mon Sep 17 00:00:00 2001 From: wussup Date: Mon, 20 Apr 2020 15:51:27 +0200 Subject: [PATCH 3/6] Update MouseWheelZoom.js --- src/ol/interaction/MouseWheelZoom.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index a735b9dec8..744eb9241c 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -91,7 +91,10 @@ class MouseWheelZoom extends Interaction { * @private * @type {boolean} */ - this.constrainResolution_ = options.constrainResolution !== undefined ? options.constrainResolution : false; + this.constrainResolution_ = + options.constrainResolution !== undefined + ? options.constrainResolution + : false; /** * @private @@ -224,7 +227,7 @@ class MouseWheelZoom extends Interaction { const view = map.getView(); if (this.mode_ === Mode.TRACKPAD && - !(view.getConstrainResolution() || this.constrainResolution_)) { + !(view.getConstrainResolution() || this.constrainResolution_)) { if (this.trackpadTimeoutId_) { clearTimeout(this.trackpadTimeoutId_); } else { From 020b387649987c8edd6b267f80deabd809b6d5f4 Mon Sep 17 00:00:00 2001 From: wussup Date: Mon, 20 Apr 2020 15:56:05 +0200 Subject: [PATCH 4/6] Update MouseWheelZoom.js --- src/ol/interaction/MouseWheelZoom.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index 744eb9241c..e7acb8a46f 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -95,7 +95,7 @@ class MouseWheelZoom extends Interaction { options.constrainResolution !== undefined ? options.constrainResolution : false; - + /** * @private * @type {import("../events/condition.js").Condition} @@ -227,7 +227,8 @@ class MouseWheelZoom extends Interaction { const view = map.getView(); if (this.mode_ === Mode.TRACKPAD && - !(view.getConstrainResolution() || this.constrainResolution_)) { + !(view.getConstrainResolution() || this.constrainResolution_)) + { if (this.trackpadTimeoutId_) { clearTimeout(this.trackpadTimeoutId_); } else { From b6fc2bf2fe02b42af3dbf0aede6173a6b372d12b Mon Sep 17 00:00:00 2001 From: wussup Date: Mon, 20 Apr 2020 15:58:42 +0200 Subject: [PATCH 5/6] Update MouseWheelZoom.js --- src/ol/interaction/MouseWheelZoom.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index e7acb8a46f..9702ec4ccc 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -226,8 +226,10 @@ class MouseWheelZoom extends Interaction { } const view = map.getView(); - if (this.mode_ === Mode.TRACKPAD && - !(view.getConstrainResolution() || this.constrainResolution_)) + if ( + this.mode_ === Mode.TRACKPAD && + !(view.getConstrainResolution() || this.constrainResolution_) + ) { if (this.trackpadTimeoutId_) { clearTimeout(this.trackpadTimeoutId_); From 7e1305eab2effc6155a8ec80fa8390126a3190e1 Mon Sep 17 00:00:00 2001 From: wussup Date: Mon, 20 Apr 2020 16:01:51 +0200 Subject: [PATCH 6/6] Update MouseWheelZoom.js --- src/ol/interaction/MouseWheelZoom.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index 9702ec4ccc..a34c6577bb 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -229,8 +229,7 @@ class MouseWheelZoom extends Interaction { if ( this.mode_ === Mode.TRACKPAD && !(view.getConstrainResolution() || this.constrainResolution_) - ) - { + ) { if (this.trackpadTimeoutId_) { clearTimeout(this.trackpadTimeoutId_); } else {