aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
Diffstat (limited to 'modern')
-rw-r--r--modern/src/map/Map.js22
1 files changed, 11 insertions, 11 deletions
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);