From 203df66558a9d92dce11d6121e576886d29c2e77 Mon Sep 17 00:00:00 2001 From: Mustafa Taha Şahin Date: Fri, 2 Apr 2021 01:14:03 +0300 Subject: more refactoring --- modern/src/map/Map.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'modern') diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js index 4bdf2fd..7f78973 100644 --- a/modern/src/map/Map.js +++ b/modern/src/map/Map.js @@ -42,18 +42,7 @@ const onIdle = function () { } }; -const setAllowedZoomLevels = map => { - if (Object.values(map.getStyle().sources).some(e => e.type === 'raster')) { - map.scrollZoom.setWheelZoomRate(1); - map.on('idle', onIdle); - } else { - map.scrollZoom.setWheelZoomRate(1/450); - map.off('idle', onIdle); - } -}; - const initMap = async () => { - setAllowedZoomLevels(map); const background = await loadImage('images/background.svg'); await Promise.all(deviceCategories.map(async category => { if (!map.hasImage(category)) { @@ -111,6 +100,17 @@ const Map = ({ children }) => { }; }, []); + useEffect(() => { + if (mapReady && Object.values(map.getStyle().sources).some(e => e.type === 'raster')) { + map.scrollZoom.setWheelZoomRate(1); + map.on('idle', onIdle); + } + return () => { + map.scrollZoom.setWheelZoomRate(1/450); + map.off('idle', onIdle); + } + }, [mapReady]); + useLayoutEffect(() => { const currentEl = containerEl.current; currentEl.appendChild(element); -- cgit v1.2.3