Skip to content

Commit

Permalink
Use Pointer Events for Map.BoxZoom (Leaflet#8757)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops authored Jul 14, 2023
1 parent b0109c9 commit 084f5d9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/map/handler/Map.BoxZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Bounds} from '../../geometry/Bounds.js';
Map.mergeOptions({
// @option boxZoom: Boolean = true
// Whether the map can be zoomed to a rectangular area specified by
// dragging the mouse while pressing the shift key.
// dragging the pointer while pressing the shift key.
boxZoom: true
});

Expand All @@ -29,11 +29,11 @@ export const BoxZoom = Handler.extend({
},

addHooks() {
DomEvent.on(this._container, 'mousedown', this._onMouseDown, this);
DomEvent.on(this._container, 'pointerdown', this._onPointerDown, this);
},

removeHooks() {
DomEvent.off(this._container, 'mousedown', this._onMouseDown, this);
DomEvent.off(this._container, 'pointerdown', this._onPointerDown, this);
},

moved() {
Expand All @@ -57,7 +57,7 @@ export const BoxZoom = Handler.extend({
}
},

_onMouseDown(e) {
_onPointerDown(e) {
if (!e.shiftKey || (e.button !== 0)) { return false; }

// Clear the deferred resetState if it hasn't executed yet, otherwise it
Expand All @@ -72,13 +72,13 @@ export const BoxZoom = Handler.extend({

DomEvent.on(document, {
contextmenu: DomEvent.stop,
mousemove: this._onMouseMove,
mouseup: this._onMouseUp,
pointermove: this._onPointerMove,
pointerup: this._onPointerUp,
keydown: this._onKeyDown
}, this);
},

_onMouseMove(e) {
_onPointerMove(e) {
if (!this._moved) {
this._moved = true;

Expand Down Expand Up @@ -110,13 +110,13 @@ export const BoxZoom = Handler.extend({

DomEvent.off(document, {
contextmenu: DomEvent.stop,
mousemove: this._onMouseMove,
mouseup: this._onMouseUp,
pointermove: this._onPointerMove,
pointerup: this._onPointerUp,
keydown: this._onKeyDown
}, this);
},

_onMouseUp(e) {
_onPointerUp(e) {
if (e.button !== 0) { return; }

this._finish();
Expand Down Expand Up @@ -147,5 +147,5 @@ export const BoxZoom = Handler.extend({

// @section Handlers
// @property boxZoom: Handler
// Box (shift-drag with mouse) zoom handler.
// Box (shift-drag with pointer) zoom handler.
Map.addInitHook('addHandler', 'boxZoom', BoxZoom);

0 comments on commit 084f5d9

Please sign in to comment.