diff options
author | Mustafa Taha Şahin <taha.sahin@metu.edu.tr> | 2021-04-02 01:14:03 +0300 |
---|---|---|
committer | Mustafa Taha Şahin <taha.sahin@metu.edu.tr> | 2021-04-02 01:14:03 +0300 |
commit | 203df66558a9d92dce11d6121e576886d29c2e77 (patch) | |
tree | c9c35400d2e9f909b4aab394da998be2e53e4c84 | |
parent | d4e94f135a4092186deda57bc53ad38154cdb401 (diff) | |
download | trackermap-web-203df66558a9d92dce11d6121e576886d29c2e77.tar.gz trackermap-web-203df66558a9d92dce11d6121e576886d29c2e77.tar.bz2 trackermap-web-203df66558a9d92dce11d6121e576886d29c2e77.zip |
more refactoring
-rw-r--r-- | modern/src/map/Map.js | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js index 4bdf2fd9..7f789734 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); |