Merge pull request #1438 from yohanboniface/echap-boxzoom
Allow for cancelling a boxzoom being drawn pressing Escape key
This commit is contained in:
commit
5a22c25ab3
@ -38,6 +38,7 @@ L.Map.BoxZoom = L.Handler.extend({
|
|||||||
L.DomEvent
|
L.DomEvent
|
||||||
.on(document, 'mousemove', this._onMouseMove, this)
|
.on(document, 'mousemove', this._onMouseMove, this)
|
||||||
.on(document, 'mouseup', this._onMouseUp, this)
|
.on(document, 'mouseup', this._onMouseUp, this)
|
||||||
|
.on(document, 'keydown', this._onKeyDown, this)
|
||||||
.preventDefault(e);
|
.preventDefault(e);
|
||||||
|
|
||||||
this._map.fire("boxzoomstart");
|
this._map.fire("boxzoomstart");
|
||||||
@ -61,7 +62,7 @@ L.Map.BoxZoom = L.Handler.extend({
|
|||||||
box.style.height = (Math.max(0, Math.abs(offset.y) - 4)) + 'px';
|
box.style.height = (Math.max(0, Math.abs(offset.y) - 4)) + 'px';
|
||||||
},
|
},
|
||||||
|
|
||||||
_onMouseUp: function (e) {
|
_finish: function () {
|
||||||
this._pane.removeChild(this._box);
|
this._pane.removeChild(this._box);
|
||||||
this._container.style.cursor = '';
|
this._container.style.cursor = '';
|
||||||
|
|
||||||
@ -69,7 +70,13 @@ L.Map.BoxZoom = L.Handler.extend({
|
|||||||
|
|
||||||
L.DomEvent
|
L.DomEvent
|
||||||
.off(document, 'mousemove', this._onMouseMove)
|
.off(document, 'mousemove', this._onMouseMove)
|
||||||
.off(document, 'mouseup', this._onMouseUp);
|
.off(document, 'mouseup', this._onMouseUp)
|
||||||
|
.off(document, 'keydown', this._onKeyDown);
|
||||||
|
},
|
||||||
|
|
||||||
|
_onMouseUp: function (e) {
|
||||||
|
|
||||||
|
this._finish();
|
||||||
|
|
||||||
var map = this._map,
|
var map = this._map,
|
||||||
layerPoint = map.mouseEventToLayerPoint(e);
|
layerPoint = map.mouseEventToLayerPoint(e);
|
||||||
@ -85,6 +92,12 @@ L.Map.BoxZoom = L.Handler.extend({
|
|||||||
map.fire("boxzoomend", {
|
map.fire("boxzoomend", {
|
||||||
boxZoomBounds: bounds
|
boxZoomBounds: bounds
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
_onKeyDown: function (e) {
|
||||||
|
if (e.keyCode === 27) {
|
||||||
|
this._finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user