diff --git a/src/components/Map/BrowserMap.tsx b/src/components/Map/BrowserMap.tsx index 10403ac83..016806f43 100644 --- a/src/components/Map/BrowserMap.tsx +++ b/src/components/Map/BrowserMap.tsx @@ -11,6 +11,7 @@ import { useInitMap } from './behaviour/useInitMap'; import { Translation } from '../../services/intl'; import { useToggleTerrainControl } from './behaviour/useToggleTerrainControl'; import { isWebglSupported } from './helpers'; +import { useIntegerZoomInRaster } from './behaviour/useIntegerZoomInRaster'; const useOnMapLoaded = useAddMapEvent((map, onMapLoaded) => ({ eventType: 'load', @@ -47,6 +48,7 @@ const BrowserMap = ({ onMapLoaded }) => { const { viewForMap, setViewFromMap, setBbox, activeLayers } = useMapStateContext(); useUpdateViewOnMove(map, setViewFromMap, setBbox); + useIntegerZoomInRaster(map, activeLayers); useToggleTerrainControl(map); useUpdateMap(map, viewForMap); useUpdateStyle(map, activeLayers); diff --git a/src/components/Map/behaviour/useIntegerZoomInRaster.tsx b/src/components/Map/behaviour/useIntegerZoomInRaster.tsx new file mode 100644 index 000000000..c1a5fa00c --- /dev/null +++ b/src/components/Map/behaviour/useIntegerZoomInRaster.tsx @@ -0,0 +1,17 @@ +import { useAddMapEvent } from '../../helpers'; + +export const useIntegerZoomInRaster = useAddMapEvent((map, activeLayers) => ({ + eventType: 'moveend', + eventHandler: () => { + const isRaster = + activeLayers[0] !== 'basic' && activeLayers[0] !== 'outdoor'; + + const delta = parseFloat(window.location.search?.substring(1)) || 0.1; + const zoomIsInVicinity = + Math.abs(map.getZoom() % 1) < delta || + Math.abs(map.getZoom() % 1) > 1 - delta; + if (isRaster && map.getZoom() % 1 !== 0 && zoomIsInVicinity) { + map.setZoom(Math.round(map.getZoom())); + } + }, +}));