diff options
author | Mustafa Taha Şahin <taha.sahin@metu.edu.tr> | 2021-04-01 00:29:15 +0300 |
---|---|---|
committer | Mustafa Taha Şahin <taha.sahin@metu.edu.tr> | 2021-04-01 00:29:15 +0300 |
commit | dfc2c4d23684b4dcce3e4d8a366e58040163ed51 (patch) | |
tree | a0f96abea4f540d8fc178049d921ced7c1157c88 /modern/src/map/Map.js | |
parent | 9ccde8f4495d1a58e644ad36c1866cb91168d173 (diff) | |
download | trackermap-web-dfc2c4d23684b4dcce3e4d8a366e58040163ed51.tar.gz trackermap-web-dfc2c4d23684b4dcce3e4d8a366e58040163ed51.tar.bz2 trackermap-web-dfc2c4d23684b4dcce3e4d8a366e58040163ed51.zip |
Limit zoom levels to integers for raster maps
Diffstat (limited to 'modern/src/map/Map.js')
-rw-r--r-- | modern/src/map/Map.js | 20 |
1 files changed, 20 insertions, 0 deletions
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)) { |