From c666e297b32da2c677e3b8203fc20dae678e2407 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Wed, 7 Nov 2018 10:54:11 -0800 Subject: [PATCH] fix shaky sprites on scrollZoom (#7558) (#7564) --- src/ui/handler/scroll_zoom.js | 12 ++++++++++++ src/ui/map.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ui/handler/scroll_zoom.js b/src/ui/handler/scroll_zoom.js index fb06392245c..143eab2592d 100644 --- a/src/ui/handler/scroll_zoom.js +++ b/src/ui/handler/scroll_zoom.js @@ -33,6 +33,7 @@ class ScrollZoomHandler { _el: HTMLElement; _enabled: boolean; _active: boolean; + _zooming: boolean; _aroundCenter: boolean; _around: Point; _aroundPoint: Point; @@ -78,10 +79,19 @@ class ScrollZoomHandler { return !!this._enabled; } + /* + * Active state is turned on and off with every scroll wheel event and is set back to false before the map + * render is called, so _active is not a good candidate for determining if a scroll zoom animation is in + * progress. + */ isActive() { return !!this._active; } + + isZooming() { + return !!this._zooming; + } /** * Enables the "scroll to zoom" interaction. * @@ -182,6 +192,7 @@ class ScrollZoomHandler { } this._active = true; + this._zooming = true; this._map.fire(new Event('movestart', {originalEvent: e})); this._map.fire(new Event('zoomstart', {originalEvent: e})); if (this._finishTimeout) { @@ -261,6 +272,7 @@ class ScrollZoomHandler { if (finished) { this._active = false; this._finishTimeout = setTimeout(() => { + this._zooming = false; this._map.fire(new Event('zoomend', {originalEvent: this._lastWheelEvent})); this._map.fire(new Event('moveend', {originalEvent: this._lastWheelEvent})); delete this._targetZoom; diff --git a/src/ui/map.js b/src/ui/map.js index ce2fe9e8984..5d7be0168db 100755 --- a/src/ui/map.js +++ b/src/ui/map.js @@ -644,7 +644,7 @@ class Map extends Camera { */ isZooming(): boolean { return this._zooming || - this.scrollZoom.isActive(); + this.scrollZoom.isZooming(); } /**