Merge pull request #3653 from Leaflet/wheel
Switch to wheel event where available
This commit is contained in:
commit
edacdf3bd5
@ -61,8 +61,7 @@ L.DomEvent = {
|
|||||||
} else if ('addEventListener' in obj) {
|
} else if ('addEventListener' in obj) {
|
||||||
|
|
||||||
if (type === 'mousewheel') {
|
if (type === 'mousewheel') {
|
||||||
obj.addEventListener('DOMMouseScroll', handler, false);
|
obj.addEventListener('onwheel' in obj ? 'wheel' : 'mousewheel', handler, false);
|
||||||
obj.addEventListener(type, handler, false);
|
|
||||||
|
|
||||||
} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
|
} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
|
||||||
handler = function (e) {
|
handler = function (e) {
|
||||||
@ -108,8 +107,7 @@ L.DomEvent = {
|
|||||||
} else if ('removeEventListener' in obj) {
|
} else if ('removeEventListener' in obj) {
|
||||||
|
|
||||||
if (type === 'mousewheel') {
|
if (type === 'mousewheel') {
|
||||||
obj.removeEventListener('DOMMouseScroll', handler, false);
|
obj.removeEventListener('onwheel' in obj ? 'wheel' : 'mousewheel', handler, false);
|
||||||
obj.removeEventListener(type, handler, false);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
obj.removeEventListener(
|
obj.removeEventListener(
|
||||||
@ -141,7 +139,7 @@ L.DomEvent = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
disableScrollPropagation: function (el) {
|
disableScrollPropagation: function (el) {
|
||||||
return L.DomEvent.on(el, 'mousewheel MozMousePixelScroll', L.DomEvent.stopPropagation);
|
return L.DomEvent.on(el, 'mousewheel', L.DomEvent.stopPropagation);
|
||||||
},
|
},
|
||||||
|
|
||||||
disableClickPropagation: function (el) {
|
disableClickPropagation: function (el) {
|
||||||
@ -184,16 +182,14 @@ L.DomEvent = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getWheelDelta: function (e) {
|
getWheelDelta: function (e) {
|
||||||
|
return (e.deltaY && e.deltaMode === 0) ? -e.deltaY : // Pixels
|
||||||
var delta = 0;
|
(e.deltaY && e.deltaMode === 1) ? -e.deltaY * 18 : // Lines
|
||||||
|
(e.deltaY && e.deltaMode === 2) ? -e.deltaY * 52 : // Pages
|
||||||
if (e.wheelDelta) {
|
(e.deltaX || e.deltaZ) ? 0 : // Skip horizontal/depth wheel events
|
||||||
delta = e.wheelDelta / 120;
|
e.wheelDelta ? (e.wheelDeltaY || e.wheelDelta) / 2 : // Legacy IE pixels
|
||||||
}
|
(e.detail && Math.abs(e.detail) < 32765) ? -e.detail * 18 : // Legacy Moz lines
|
||||||
if (e.detail) {
|
e.detail ? e.detail / -32765 * 52 : // Legacy Moz pages
|
||||||
delta = -e.detail / 3;
|
0;
|
||||||
}
|
|
||||||
return delta;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_skipEvents: {},
|
_skipEvents: {},
|
||||||
|
@ -9,23 +9,18 @@ L.Map.mergeOptions({
|
|||||||
|
|
||||||
L.Map.ScrollWheelZoom = L.Handler.extend({
|
L.Map.ScrollWheelZoom = L.Handler.extend({
|
||||||
addHooks: function () {
|
addHooks: function () {
|
||||||
L.DomEvent.on(this._map._container, {
|
L.DomEvent.on(this._map._container, 'mousewheel', this._onWheelScroll, this);
|
||||||
mousewheel: this._onWheelScroll,
|
|
||||||
MozMousePixelScroll: L.DomEvent.preventDefault
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this._delta = 0;
|
this._delta = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeHooks: function () {
|
removeHooks: function () {
|
||||||
L.DomEvent.off(this._map._container, {
|
L.DomEvent.off(this._map._container, 'mousewheel', this._onWheelScroll, this);
|
||||||
mousewheel: this._onWheelScroll,
|
|
||||||
MozMousePixelScroll: L.DomEvent.preventDefault
|
|
||||||
}, this);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_onWheelScroll: function (e) {
|
_onWheelScroll: function (e) {
|
||||||
var delta = L.DomEvent.getWheelDelta(e);
|
var delta = L.DomEvent.getWheelDelta(e);
|
||||||
|
|
||||||
var debounce = this._map.options.wheelDebounceTime;
|
var debounce = this._map.options.wheelDebounceTime;
|
||||||
|
|
||||||
this._delta += delta;
|
this._delta += delta;
|
||||||
@ -50,9 +45,9 @@ L.Map.ScrollWheelZoom = L.Handler.extend({
|
|||||||
|
|
||||||
map.stop(); // stop panning and fly animations if any
|
map.stop(); // stop panning and fly animations if any
|
||||||
|
|
||||||
delta = delta > 0 ? Math.ceil(delta) : Math.floor(delta);
|
// map the delta with a sigmoid function to -4..4 range leaning on -1..1
|
||||||
delta = Math.max(Math.min(delta, 4), -4);
|
var d2 = Math.ceil(4 * Math.log(2 / (1 + Math.exp(-Math.abs(delta / 200)))) / Math.LN2);
|
||||||
delta = map._limitZoom(zoom + delta) - zoom;
|
delta = map._limitZoom(zoom + (delta > 0 ? d2 : -d2)) - zoom;
|
||||||
|
|
||||||
this._delta = 0;
|
this._delta = 0;
|
||||||
this._startTime = null;
|
this._startTime = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user