2 * L.Handler.ShiftDragZoom is used internally by L.Map to add shift-drag zoom (zoom to a selected bounding box).
5 L
.Handler
.ShiftDragZoom
= L
.Handler
.extend({
6 initialize: function(map
) {
8 this._container
= map
._container
;
9 this._pane
= map
._panes
.overlayPane
;
13 if (this._enabled
) { return; }
15 L
.DomEvent
.addListener(this._container
, 'mousedown', this._onMouseDown
, this);
21 if (!this._enabled
) { return; }
23 L
.DomEvent
.removeListener(this._container
, 'mousedown', this._onMouseDown
);
25 this._enabled
= false;
28 _onMouseDown: function(e
) {
29 if (!e
.shiftKey
|| ((e
.which
!= 1) && (e
.button
!= 1))) { return false; }
31 L
.DomUtil
.disableTextSelection();
33 this._startLayerPoint
= this._map
.mouseEventToLayerPoint(e
);
35 this._box
= L
.DomUtil
.create('div', 'leaflet-zoom-box', this._pane
);
36 L
.DomUtil
.setPosition(this._box
, this._startLayerPoint
);
38 //TODO move cursor to styles
39 this._container
.style
.cursor
= 'crosshair';
41 L
.DomEvent
.addListener(document
, 'mousemove', this._onMouseMove
, this);
42 L
.DomEvent
.addListener(document
, 'mouseup', this._onMouseUp
, this);
44 L
.DomEvent
.preventDefault(e
);
47 _onMouseMove: function(e
) {
48 var layerPoint
= this._map
.mouseEventToLayerPoint(e
),
49 dx
= layerPoint
.x
- this._startLayerPoint
.x
,
50 dy
= layerPoint
.y
- this._startLayerPoint
.y
;
52 var newX
= Math
.min(layerPoint
.x
, this._startLayerPoint
.x
),
53 newY
= Math
.min(layerPoint
.y
, this._startLayerPoint
.y
),
54 newPos
= new L
.Point(newX
, newY
);
56 L
.DomUtil
.setPosition(this._box
, newPos
);
58 this._box
.style
.width
= (Math
.abs(dx
) - 4) + 'px';
59 this._box
.style
.height
= (Math
.abs(dy
) - 4) + 'px';
62 _onMouseUp: function(e
) {
63 this._pane
.removeChild(this._box
);
64 this._container
.style
.cursor
= '';
66 L
.DomUtil
.enableTextSelection();
68 L
.DomEvent
.removeListener(document
, 'mousemove', this._onMouseMove
);
69 L
.DomEvent
.removeListener(document
, 'mouseup', this._onMouseUp
);
71 var layerPoint
= this._map
.mouseEventToLayerPoint(e
);
73 var bounds
= new L
.LatLngBounds(
74 this._map
.layerPointToLatLng(this._startLayerPoint
),
75 this._map
.layerPointToLatLng(layerPoint
));
77 this._map
.fitBounds(bounds
);