From a1ff60bf9be4fd0eb569ac2b13cf189d700a048b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20S=C3=A1nchez=20Ortega?= Date: Thu, 4 Feb 2016 12:27:23 +0100 Subject: [PATCH] Make wheel-zoom speed depend on a new wheelPxPerZoomLevel option --- debug/map/zoom-delta.html | 6 ++++-- src/map/handler/Map.ScrollWheelZoom.js | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/debug/map/zoom-delta.html b/debug/map/zoom-delta.html index ee449a6c..5c86dd82 100644 --- a/debug/map/zoom-delta.html +++ b/debug/map/zoom-delta.html @@ -71,7 +71,8 @@ layers: [osm1], zoom: 5, zoomSnap: 0.25, - zoomDelta: 0.5 + zoomDelta: 0.5, + wheelPxPerZoomLevel: 50 }); var map2 = new L.Map('map2', { @@ -79,7 +80,8 @@ layers: [osm2], zoom: 5, zoomSnap: 0, - zoomDelta: 0.25 + zoomDelta: 0.25, + wheelPxPerZoomLevel: 50 }); map1.on('zoomend',function(){ diff --git a/src/map/handler/Map.ScrollWheelZoom.js b/src/map/handler/Map.ScrollWheelZoom.js index d6f17406..55a3afbc 100644 --- a/src/map/handler/Map.ScrollWheelZoom.js +++ b/src/map/handler/Map.ScrollWheelZoom.js @@ -4,7 +4,8 @@ L.Map.mergeOptions({ scrollWheelZoom: true, - wheelDebounceTime: 40 + wheelDebounceTime: 40, + wheelPxPerZoomLevel: 50 }); L.Map.ScrollWheelZoom = L.Handler.extend({ @@ -45,9 +46,10 @@ L.Map.ScrollWheelZoom = L.Handler.extend({ map._stop(); // stop panning and fly animations if any // map the delta with a sigmoid function to -4..4 range leaning on -1..1 - var d2 = Math.ceil(4 * Math.log(2 / (1 + Math.exp(-Math.abs(this._delta / 200)))) / Math.LN2), - d3 = d2 * this._map.options.zoomDelta, - delta = map._limitZoom(zoom + (this._delta > 0 ? d3 : -d3)) - zoom; + var d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4), + d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2, + d4 = Math.max(d3, this._map.options.zoomSnap || 0), + delta = map._limitZoom(zoom + (this._delta > 0 ? d4 : -d4)) - zoom; this._delta = 0; this._startTime = null;