Make wheel-zoom speed depend on a new wheelPxPerZoomLevel option
This commit is contained in:
parent
f43950e3fa
commit
a1ff60bf9b
@ -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(){
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user