Script and makefile adjustments for updating extlib
[larjonas-mediagoblin.git] / extlib / leaflet / src / handler / ScrollWheelZoom.js
blobdc877e17a6e0e0252d2c94c2f75a15db845f3b32
1 /*
2 * L.Handler.ScrollWheelZoom is used internally by L.Map to enable mouse scroll wheel zooming on the map.
3 */
5 L.Handler.ScrollWheelZoom = L.Handler.extend({
6 enable: function() {
7 if (this._enabled) { return; }
8 L.DomEvent.addListener(this._map._container, 'mousewheel', this._onWheelScroll, this);
9 this._delta = 0;
10 this._enabled = true;
13 disable: function() {
14 if (!this._enabled) { return; }
15 L.DomEvent.removeListener(this._map._container, 'mousewheel', this._onWheelScroll);
16 this._enabled = false;
19 _onWheelScroll: function(e) {
20 this._delta += L.DomEvent.getWheelDelta(e);
21 this._lastMousePos = this._map.mouseEventToContainerPoint(e);
23 clearTimeout(this._timer);
24 this._timer = setTimeout(L.Util.bind(this._performZoom, this), 50);
26 L.DomEvent.preventDefault(e);
29 _performZoom: function() {
30 var delta = Math.round(this._delta);
31 this._delta = 0;
33 if (!delta) { return; }
35 var center = this._getCenterForScrollWheelZoom(this._lastMousePos, delta),
36 zoom = this._map.getZoom() + delta;
38 if (this._map._limitZoom(zoom) == this._map._zoom) { return; }
40 this._map.setView(center, zoom);
43 _getCenterForScrollWheelZoom: function(mousePos, delta) {
44 var centerPoint = this._map.getPixelBounds().getCenter(),
45 viewHalf = this._map.getSize().divideBy(2),
46 centerOffset = mousePos.subtract(viewHalf).multiplyBy(1 - Math.pow(2, -delta)),
47 newCenterPoint = centerPoint.add(centerOffset);
48 return this._map.unproject(newCenterPoint, this._map._zoom, true);
50 });