From 56567e683734c1f990fb59f193c2d96df706b6b0 Mon Sep 17 00:00:00 2001 From: Mustafa Taha Şahin Date: Fri, 2 Apr 2021 02:40:07 +0300 Subject: another refactoring --- modern/src/map/Map.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'modern/src') diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js index 7f789734..d83c297d 100644 --- a/modern/src/map/Map.js +++ b/modern/src/map/Map.js @@ -35,13 +35,6 @@ const updateReadyValue = value => { readyListeners.forEach(listener => listener(value)); }; -const onIdle = function () { - const zoom = Math.round(map.getZoom()) - if (zoom !== map.getZoom()) { - map.zoomTo(zoom) - } -}; - const initMap = async () => { const background = await loadImage('images/background.svg'); await Promise.all(deviceCategories.map(async category => { @@ -102,12 +95,18 @@ const Map = ({ children }) => { useEffect(() => { if (mapReady && Object.values(map.getStyle().sources).some(e => e.type === 'raster')) { - map.scrollZoom.setWheelZoomRate(1); - map.on('idle', onIdle); + const onIdle = function () { + const zoom = Math.round(map.getZoom()); + if (zoom !== map.getZoom()) { + map.zoomTo(zoom); + } + }; + map.scrollZoom.setWheelZoomRate(1); + map.on('idle', onIdle); + return () => { + map.scrollZoom.setWheelZoomRate(1/450); + map.off('idle', onIdle); } - return () => { - map.scrollZoom.setWheelZoomRate(1/450); - map.off('idle', onIdle); } }, [mapReady]); -- cgit v1.2.3