From 19b164205208e99bbbd62750cfb7e845819ab8e4 Mon Sep 17 00:00:00 2001 From: Federico Saglia Date: Thu, 31 Jan 2019 18:08:49 +0100 Subject: [PATCH 1/5] added scrollZoom.setZoomRate() and scrollZoom.setWheelZoomRate() to set defaultZoomRate/wheelZoomRate --- src/ui/handler/scroll_zoom.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/ui/handler/scroll_zoom.js b/src/ui/handler/scroll_zoom.js index 0082c270cba..456d2d54b4d 100644 --- a/src/ui/handler/scroll_zoom.js +++ b/src/ui/handler/scroll_zoom.js @@ -18,8 +18,8 @@ import type {TaskID} from '../../util/task_queue'; const wheelZoomDelta = 4.000244140625; // These magic numbers control the rate of zoom. Trackpad events fire at a greater // frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick -const defaultZoomRate = 1 / 100; -const wheelZoomRate = 1 / 450; +const defaultZoomRate = 0.3; // 1 / 100; +const wheelZoomRate = 0.1; // 1 / 450; // upper bound on how much we scale the map in any single render frame; this // is used to limit zoom rate in the case of very fast scrolling @@ -53,15 +53,26 @@ class ScrollZoomHandler { _frameId: ?TaskID; + _defaultZoomRate: number; + _wheelZoomRate: number; + /** * @private */ - constructor(map: Map) { + constructor(map: Map, options?: { + defaultZoomRate: number, + wheelZoomRate: number + }) { this._map = map; this._el = map.getCanvasContainer(); this._delta = 0; + // These magic numbers control the rate of zoom. Trackpad events fire at a greater + // frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick + this._defaultZoomRate = options.defaultZoomRate || defaultZoomRate; // 1 / 450; + this._wheelZoomRate = options.wheelZoomRate || wheelZoomRate; // 1 / 100; + bindAll([ '_onWheel', '_onTimeout', @@ -70,6 +81,22 @@ class ScrollZoomHandler { ], this); } + /** + * Override default zoomRate value + * @param {number} zoomRate + */ + setZoomRate(zoomRate) { + this._defaultZoomRate = zoomRate; + } + + /** + * Override default wheelZoomRate value + * @param {number} wheelZoomRate + */ + setWheelZoomRate(wheelZoomRate) { + this._wheelZoomRate = wheelZoomRate; + } + /** * Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled. * @@ -218,7 +245,7 @@ class ScrollZoomHandler { // accumulated delta, and update the target zoom level accordingly if (this._delta !== 0) { // For trackpad events and single mouse wheel ticks, use the default zoom rate - const zoomRate = (this._type === 'wheel' && Math.abs(this._delta) > wheelZoomDelta) ? wheelZoomRate : defaultZoomRate; + const zoomRate = (this._type === 'wheel' && Math.abs(this._delta) > wheelZoomDelta) ? this._wheelZoomRate : this._defaultZoomRate; // Scale by sigmoid of scroll wheel delta. let scale = maxScalePerFrame / (1 + Math.exp(-Math.abs(this._delta * zoomRate))); From 4ced9ad65adcf7c637d92fa716d3b3e120781f1c Mon Sep 17 00:00:00 2001 From: Federico Saglia Date: Thu, 31 Jan 2019 18:25:41 +0100 Subject: [PATCH 2/5] restored default values for `defaultZoomRate` and `wheelZoomRate` --- src/ui/handler/scroll_zoom.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/handler/scroll_zoom.js b/src/ui/handler/scroll_zoom.js index 456d2d54b4d..3ba359308a7 100644 --- a/src/ui/handler/scroll_zoom.js +++ b/src/ui/handler/scroll_zoom.js @@ -18,8 +18,8 @@ import type {TaskID} from '../../util/task_queue'; const wheelZoomDelta = 4.000244140625; // These magic numbers control the rate of zoom. Trackpad events fire at a greater // frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick -const defaultZoomRate = 0.3; // 1 / 100; -const wheelZoomRate = 0.1; // 1 / 450; +const defaultZoomRate = 1 / 100; +const wheelZoomRate = 1 / 450; // upper bound on how much we scale the map in any single render frame; this // is used to limit zoom rate in the case of very fast scrolling @@ -70,8 +70,8 @@ class ScrollZoomHandler { // These magic numbers control the rate of zoom. Trackpad events fire at a greater // frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick - this._defaultZoomRate = options.defaultZoomRate || defaultZoomRate; // 1 / 450; - this._wheelZoomRate = options.wheelZoomRate || wheelZoomRate; // 1 / 100; + this._defaultZoomRate = options.defaultZoomRate || defaultZoomRate; + this._wheelZoomRate = options.wheelZoomRate || wheelZoomRate; bindAll([ '_onWheel', From 8eefbf2490fffccc91d087b12da0e36030e03795 Mon Sep 17 00:00:00 2001 From: Federico Saglia Date: Thu, 31 Jan 2019 18:40:40 +0100 Subject: [PATCH 3/5] removed options from constructor --- src/ui/handler/scroll_zoom.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/ui/handler/scroll_zoom.js b/src/ui/handler/scroll_zoom.js index 3ba359308a7..a33c0bd9ce5 100644 --- a/src/ui/handler/scroll_zoom.js +++ b/src/ui/handler/scroll_zoom.js @@ -59,10 +59,7 @@ class ScrollZoomHandler { /** * @private */ - constructor(map: Map, options?: { - defaultZoomRate: number, - wheelZoomRate: number - }) { + constructor(map: Map) { this._map = map; this._el = map.getCanvasContainer(); @@ -70,8 +67,8 @@ class ScrollZoomHandler { // These magic numbers control the rate of zoom. Trackpad events fire at a greater // frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick - this._defaultZoomRate = options.defaultZoomRate || defaultZoomRate; - this._wheelZoomRate = options.wheelZoomRate || wheelZoomRate; + this._defaultZoomRate = defaultZoomRate; + this._wheelZoomRate = wheelZoomRate; bindAll([ '_onWheel', @@ -85,7 +82,7 @@ class ScrollZoomHandler { * Override default zoomRate value * @param {number} zoomRate */ - setZoomRate(zoomRate) { + setZoomRate(zoomRate: number) { this._defaultZoomRate = zoomRate; } @@ -93,7 +90,7 @@ class ScrollZoomHandler { * Override default wheelZoomRate value * @param {number} wheelZoomRate */ - setWheelZoomRate(wheelZoomRate) { + setWheelZoomRate(wheelZoomRate: number) { this._wheelZoomRate = wheelZoomRate; } From 4a56137d28069ad7395695146b2e292104841682 Mon Sep 17 00:00:00 2001 From: Federico Saglia Date: Mon, 29 Apr 2019 10:19:02 +0200 Subject: [PATCH 4/5] fixed docs zoomRate/wheelZoomRate --- src/ui/handler/scroll_zoom.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ui/handler/scroll_zoom.js b/src/ui/handler/scroll_zoom.js index a33c0bd9ce5..8414d2d0409 100644 --- a/src/ui/handler/scroll_zoom.js +++ b/src/ui/handler/scroll_zoom.js @@ -16,6 +16,7 @@ import type {TaskID} from '../../util/task_queue'; // deltaY value for mouse scroll wheel identification const wheelZoomDelta = 4.000244140625; + // These magic numbers control the rate of zoom. Trackpad events fire at a greater // frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick const defaultZoomRate = 1 / 100; @@ -65,8 +66,6 @@ class ScrollZoomHandler { this._delta = 0; - // These magic numbers control the rate of zoom. Trackpad events fire at a greater - // frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick this._defaultZoomRate = defaultZoomRate; this._wheelZoomRate = wheelZoomRate; @@ -79,16 +78,16 @@ class ScrollZoomHandler { } /** - * Override default zoomRate value - * @param {number} zoomRate + * Set the zoom rate of a trackpad + * @param {number} [zoomRate = 1/100] */ setZoomRate(zoomRate: number) { this._defaultZoomRate = zoomRate; } /** - * Override default wheelZoomRate value - * @param {number} wheelZoomRate + * Set the zoom rate of a mouse wheel + * @param {number} [zoomRate = 1/450] */ setWheelZoomRate(wheelZoomRate: number) { this._wheelZoomRate = wheelZoomRate; From f74a888717da6a959631473ba93bd8713fc9fff8 Mon Sep 17 00:00:00 2001 From: Federico Saglia Date: Mon, 29 Apr 2019 10:26:30 +0200 Subject: [PATCH 5/5] fixed param name --- src/ui/handler/scroll_zoom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/handler/scroll_zoom.js b/src/ui/handler/scroll_zoom.js index 8414d2d0409..3f018c748eb 100644 --- a/src/ui/handler/scroll_zoom.js +++ b/src/ui/handler/scroll_zoom.js @@ -87,7 +87,7 @@ class ScrollZoomHandler { /** * Set the zoom rate of a mouse wheel - * @param {number} [zoomRate = 1/450] + * @param {number} [wheelZoomRate = 1/450] */ setWheelZoomRate(wheelZoomRate: number) { this._wheelZoomRate = wheelZoomRate;