From dfc2c4d23684b4dcce3e4d8a366e58040163ed51 Mon Sep 17 00:00:00 2001 From: Mustafa Taha Şahin Date: Thu, 1 Apr 2021 00:29:15 +0300 Subject: Limit zoom levels to integers for raster maps --- modern/src/map/Map.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'modern') diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js index 8a43e97b..bbb1f5ce 100644 --- a/modern/src/map/Map.js +++ b/modern/src/map/Map.js @@ -35,7 +35,27 @@ 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 isRasterMap = map => Object.values(map.getStyle().sources).some(e => e.type === 'raster'); + +const setAllowedZoomLevels = map => { + if(isRasterMap(map)) { + 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)) { -- cgit v1.2.3