@antv/l7-map 2.21.1 → 2.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/camera.js +595 -674
- package/es/earthmap.js +313 -276
- package/es/geo/edge_insets.js +57 -72
- package/es/geo/lng_lat.js +50 -64
- package/es/geo/lng_lat_bounds.js +101 -137
- package/es/geo/mercator.js +23 -35
- package/es/geo/point.js +150 -221
- package/es/geo/simple.js +22 -34
- package/es/geo/transform.js +839 -905
- package/es/handler/blockable_map_event.js +46 -66
- package/es/handler/box_zoom.js +125 -143
- package/es/handler/click_zoom.js +37 -51
- package/es/handler/events/event.js +11 -9
- package/es/handler/events/map_mouse_event.js +39 -54
- package/es/handler/events/map_touch_event.js +54 -73
- package/es/handler/events/map_wheel_event.js +22 -38
- package/es/handler/events/render_event.js +6 -23
- package/es/handler/handler_inertia.js +98 -113
- package/es/handler/handler_manager.js +349 -437
- package/es/handler/handler_util.js +2 -2
- package/es/handler/keyboard.js +98 -110
- package/es/handler/map_event.js +81 -117
- package/es/handler/mouse/mouse_handler.js +81 -100
- package/es/handler/mouse/mousepan_handler.js +16 -39
- package/es/handler/mouse/mousepitch_hander.js +18 -40
- package/es/handler/mouse/mouserotate_hander.js +18 -40
- package/es/handler/mouse/util.js +7 -5
- package/es/handler/scroll_zoom.js +221 -231
- package/es/handler/shim/dblclick_zoom.js +36 -47
- package/es/handler/shim/drag_pan.js +41 -50
- package/es/handler/shim/drag_rotate.js +38 -48
- package/es/handler/shim/touch_zoom_rotate.js +68 -79
- package/es/handler/tap/single_tap_recognizer.js +60 -80
- package/es/handler/tap/tap_drag_zoom.js +72 -89
- package/es/handler/tap/tap_recognizer.js +37 -45
- package/es/handler/tap/tap_zoom.js +67 -95
- package/es/handler/touch/touch_pan.js +77 -96
- package/es/handler/touch/touch_pitch.js +61 -79
- package/es/handler/touch/touch_rotate.js +47 -67
- package/es/handler/touch/touch_zoom.js +29 -46
- package/es/handler/touch/two_touch.js +79 -104
- package/es/hash.js +75 -88
- package/es/map.js +318 -284
- package/es/util.js +18 -37
- package/es/utils/Aabb.js +60 -100
- package/es/utils/dom.js +32 -55
- package/es/utils/performance.js +25 -29
- package/es/utils/primitives.js +33 -42
- package/es/utils/task_queue.js +47 -76
- package/lib/camera.d.ts +86 -0
- package/lib/camera.js +597 -672
- package/lib/earthmap.d.ts +69 -0
- package/lib/earthmap.js +314 -276
- package/lib/geo/edge_insets.d.ts +54 -0
- package/lib/geo/edge_insets.js +58 -70
- package/lib/geo/lng_lat.d.ts +18 -0
- package/lib/geo/lng_lat.js +50 -62
- package/lib/geo/lng_lat_bounds.d.ts +25 -0
- package/lib/geo/lng_lat_bounds.js +102 -136
- package/lib/geo/mercator.d.ts +30 -0
- package/lib/geo/mercator.js +26 -37
- package/lib/geo/point.d.ts +40 -0
- package/lib/geo/point.js +151 -220
- package/lib/geo/simple.d.ts +30 -0
- package/lib/geo/simple.js +25 -36
- package/lib/geo/transform.d.ts +198 -0
- package/lib/geo/transform.js +844 -907
- package/lib/handler/IHandler.d.ts +34 -0
- package/lib/handler/blockable_map_event.d.ts +17 -0
- package/lib/handler/blockable_map_event.js +48 -65
- package/lib/handler/box_zoom.d.ts +59 -0
- package/lib/handler/box_zoom.js +126 -143
- package/lib/handler/click_zoom.d.ts +16 -0
- package/lib/handler/click_zoom.js +38 -50
- package/lib/handler/events/event.d.ts +4 -0
- package/lib/handler/events/event.js +12 -9
- package/lib/handler/events/index.d.ts +4 -0
- package/lib/handler/events/index.js +3 -3
- package/lib/handler/events/map_mouse_event.d.ts +34 -0
- package/lib/handler/events/map_mouse_event.js +41 -52
- package/lib/handler/events/map_touch_event.d.ts +57 -0
- package/lib/handler/events/map_touch_event.js +56 -71
- package/lib/handler/events/map_wheel_event.d.ts +33 -0
- package/lib/handler/events/map_wheel_event.js +23 -37
- package/lib/handler/events/render_event.d.ts +5 -0
- package/lib/handler/events/render_event.js +7 -22
- package/lib/handler/handler_inertia.d.ts +23 -0
- package/lib/handler/handler_inertia.js +102 -112
- package/lib/handler/handler_manager.d.ts +61 -0
- package/lib/handler/handler_manager.js +351 -437
- package/lib/handler/handler_util.d.ts +4 -0
- package/lib/handler/handler_util.js +2 -2
- package/lib/handler/keyboard.d.ts +36 -0
- package/lib/handler/keyboard.js +98 -110
- package/lib/handler/map_event.d.ts +29 -0
- package/lib/handler/map_event.js +83 -116
- package/lib/handler/mouse/index.d.ts +4 -0
- package/lib/handler/mouse/index.js +3 -3
- package/lib/handler/mouse/mouse_handler.d.ts +22 -0
- package/lib/handler/mouse/mouse_handler.js +83 -99
- package/lib/handler/mouse/mousepan_handler.d.ts +10 -0
- package/lib/handler/mouse/mousepan_handler.js +19 -38
- package/lib/handler/mouse/mousepitch_hander.d.ts +9 -0
- package/lib/handler/mouse/mousepitch_hander.js +21 -39
- package/lib/handler/mouse/mouserotate_hander.d.ts +9 -0
- package/lib/handler/mouse/mouserotate_hander.js +21 -39
- package/lib/handler/mouse/util.d.ts +6 -0
- package/lib/handler/mouse/util.js +7 -6
- package/lib/handler/scroll_zoom.d.ts +93 -0
- package/lib/handler/scroll_zoom.js +221 -231
- package/lib/handler/shim/dblclick_zoom.d.ts +40 -0
- package/lib/handler/shim/dblclick_zoom.js +37 -46
- package/lib/handler/shim/drag_pan.d.ts +61 -0
- package/lib/handler/shim/drag_pan.js +42 -49
- package/lib/handler/shim/drag_rotate.d.ts +46 -0
- package/lib/handler/shim/drag_rotate.js +39 -47
- package/lib/handler/shim/touch_zoom_rotate.d.ts +70 -0
- package/lib/handler/shim/touch_zoom_rotate.js +69 -78
- package/lib/handler/tap/single_tap_recognizer.d.ts +20 -0
- package/lib/handler/tap/single_tap_recognizer.js +63 -79
- package/lib/handler/tap/tap_drag_zoom.d.ts +22 -0
- package/lib/handler/tap/tap_drag_zoom.js +74 -88
- package/lib/handler/tap/tap_recognizer.d.ts +17 -0
- package/lib/handler/tap/tap_recognizer.js +41 -47
- package/lib/handler/tap/tap_zoom.d.ts +22 -0
- package/lib/handler/tap/tap_zoom.js +69 -94
- package/lib/handler/touch/index.d.ts +5 -0
- package/lib/handler/touch/index.js +4 -4
- package/lib/handler/touch/touch_pan.d.ts +30 -0
- package/lib/handler/touch/touch_pan.js +79 -95
- package/lib/handler/touch/touch_pitch.d.ts +13 -0
- package/lib/handler/touch/touch_pitch.js +64 -78
- package/lib/handler/touch/touch_rotate.d.ts +12 -0
- package/lib/handler/touch/touch_rotate.js +50 -66
- package/lib/handler/touch/touch_zoom.d.ts +12 -0
- package/lib/handler/touch/touch_zoom.js +32 -45
- package/lib/handler/touch/two_touch.d.ts +23 -0
- package/lib/handler/touch/two_touch.js +81 -103
- package/lib/hash.d.ts +14 -0
- package/lib/hash.js +75 -88
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -4
- package/lib/interface.d.ts +34 -0
- package/lib/map.d.ts +70 -0
- package/lib/map.js +319 -284
- package/lib/util.d.ts +25 -0
- package/lib/util.js +20 -36
- package/lib/utils/Aabb.d.ts +12 -0
- package/lib/utils/Aabb.js +61 -99
- package/lib/utils/dom.d.ts +4 -0
- package/lib/utils/dom.js +34 -55
- package/lib/utils/performance.d.ts +17 -0
- package/lib/utils/performance.js +25 -29
- package/lib/utils/primitives.d.ts +6 -0
- package/lib/utils/primitives.js +34 -41
- package/lib/utils/task_queue.d.ts +13 -0
- package/lib/utils/task_queue.js +47 -76
- package/package.json +25 -32
package/es/handler/keyboard.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
var defaultOptions = {
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
const defaultOptions = {
|
|
4
3
|
panStep: 100,
|
|
5
4
|
bearingStep: 15,
|
|
6
5
|
pitchStep: 10
|
|
@@ -20,123 +19,112 @@ var defaultOptions = {
|
|
|
20
19
|
* - `Shift+⇡`: Increase the pitch by 10 degrees.
|
|
21
20
|
* - `Shift+⇣`: Decrease the pitch by 10 degrees.
|
|
22
21
|
*/
|
|
23
|
-
|
|
22
|
+
class KeyboardHandler {
|
|
24
23
|
/**
|
|
25
24
|
* @private
|
|
26
25
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
constructor() {
|
|
27
|
+
_defineProperty(this, "enabled", void 0);
|
|
28
|
+
_defineProperty(this, "active", void 0);
|
|
29
|
+
_defineProperty(this, "panStep", void 0);
|
|
30
|
+
_defineProperty(this, "bearingStep", void 0);
|
|
31
|
+
_defineProperty(this, "pitchStep", void 0);
|
|
32
|
+
const stepOptions = defaultOptions;
|
|
30
33
|
this.panStep = stepOptions.panStep;
|
|
31
34
|
this.bearingStep = stepOptions.bearingStep;
|
|
32
35
|
this.pitchStep = stepOptions.pitchStep;
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
reset() {
|
|
38
|
+
this.active = false;
|
|
39
|
+
}
|
|
40
|
+
keydown(e) {
|
|
41
|
+
if (e.altKey || e.ctrlKey || e.metaKey) {
|
|
42
|
+
return;
|
|
38
43
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
break;
|
|
63
|
-
case 37:
|
|
64
|
-
if (e.shiftKey) {
|
|
65
|
-
bearingDir = -1;
|
|
66
|
-
} else {
|
|
67
|
-
e.preventDefault();
|
|
68
|
-
xDir = -1;
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
case 39:
|
|
72
|
-
if (e.shiftKey) {
|
|
73
|
-
bearingDir = 1;
|
|
74
|
-
} else {
|
|
75
|
-
e.preventDefault();
|
|
76
|
-
xDir = 1;
|
|
77
|
-
}
|
|
78
|
-
break;
|
|
79
|
-
case 38:
|
|
80
|
-
if (e.shiftKey) {
|
|
81
|
-
pitchDir = 1;
|
|
82
|
-
} else {
|
|
83
|
-
e.preventDefault();
|
|
84
|
-
yDir = -1;
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
case 40:
|
|
88
|
-
if (e.shiftKey) {
|
|
89
|
-
pitchDir = -1;
|
|
90
|
-
} else {
|
|
91
|
-
e.preventDefault();
|
|
92
|
-
yDir = 1;
|
|
93
|
-
}
|
|
94
|
-
break;
|
|
95
|
-
default:
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
cameraAnimation: function cameraAnimation(map) {
|
|
100
|
-
var zoom = map.getZoom();
|
|
101
|
-
map.easeTo({
|
|
102
|
-
duration: 300,
|
|
103
|
-
easeId: 'keyboardHandler',
|
|
104
|
-
easing: easeOut,
|
|
105
|
-
zoom: zoomDir ? Math.round(zoom) + zoomDir * (e.shiftKey ? 2 : 1) : zoom,
|
|
106
|
-
bearing: map.getBearing() + bearingDir * _this.bearingStep,
|
|
107
|
-
pitch: map.getPitch() + pitchDir * _this.pitchStep,
|
|
108
|
-
offset: [-xDir * _this.panStep, -yDir * _this.panStep],
|
|
109
|
-
center: map.getCenter()
|
|
110
|
-
}, {
|
|
111
|
-
originalEvent: e
|
|
112
|
-
});
|
|
44
|
+
let zoomDir = 0;
|
|
45
|
+
let bearingDir = 0;
|
|
46
|
+
let pitchDir = 0;
|
|
47
|
+
let xDir = 0;
|
|
48
|
+
let yDir = 0;
|
|
49
|
+
switch (e.keyCode) {
|
|
50
|
+
case 61:
|
|
51
|
+
case 107:
|
|
52
|
+
case 171:
|
|
53
|
+
case 187:
|
|
54
|
+
zoomDir = 1;
|
|
55
|
+
break;
|
|
56
|
+
case 189:
|
|
57
|
+
case 109:
|
|
58
|
+
case 173:
|
|
59
|
+
zoomDir = -1;
|
|
60
|
+
break;
|
|
61
|
+
case 37:
|
|
62
|
+
if (e.shiftKey) {
|
|
63
|
+
bearingDir = -1;
|
|
64
|
+
} else {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
xDir = -1;
|
|
113
67
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
68
|
+
break;
|
|
69
|
+
case 39:
|
|
70
|
+
if (e.shiftKey) {
|
|
71
|
+
bearingDir = 1;
|
|
72
|
+
} else {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
xDir = 1;
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case 38:
|
|
78
|
+
if (e.shiftKey) {
|
|
79
|
+
pitchDir = 1;
|
|
80
|
+
} else {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
yDir = -1;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case 40:
|
|
86
|
+
if (e.shiftKey) {
|
|
87
|
+
pitchDir = -1;
|
|
88
|
+
} else {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
yDir = 1;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
return;
|
|
136
95
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
96
|
+
return {
|
|
97
|
+
cameraAnimation: map => {
|
|
98
|
+
const zoom = map.getZoom();
|
|
99
|
+
map.easeTo({
|
|
100
|
+
duration: 300,
|
|
101
|
+
easeId: 'keyboardHandler',
|
|
102
|
+
easing: easeOut,
|
|
103
|
+
zoom: zoomDir ? Math.round(zoom) + zoomDir * (e.shiftKey ? 2 : 1) : zoom,
|
|
104
|
+
bearing: map.getBearing() + bearingDir * this.bearingStep,
|
|
105
|
+
pitch: map.getPitch() + pitchDir * this.pitchStep,
|
|
106
|
+
offset: [-xDir * this.panStep, -yDir * this.panStep],
|
|
107
|
+
center: map.getCenter()
|
|
108
|
+
}, {
|
|
109
|
+
originalEvent: e
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
enable() {
|
|
115
|
+
this.enabled = true;
|
|
116
|
+
}
|
|
117
|
+
disable() {
|
|
118
|
+
this.enabled = false;
|
|
119
|
+
this.reset();
|
|
120
|
+
}
|
|
121
|
+
isEnabled() {
|
|
122
|
+
return this.enabled;
|
|
123
|
+
}
|
|
124
|
+
isActive() {
|
|
125
|
+
return this.active;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
140
128
|
function easeOut(t) {
|
|
141
129
|
return t * (2 - t);
|
|
142
130
|
}
|
package/es/handler/map_event.js
CHANGED
|
@@ -1,125 +1,89 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
2
|
// @ts-ignore
|
|
4
3
|
|
|
5
4
|
import { MapMouseEvent, MapTouchEvent, MapWheelEvent } from "./events";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export default class MapEventHandler {
|
|
6
|
+
constructor(map, options) {
|
|
7
|
+
_defineProperty(this, "mousedownPos", void 0);
|
|
8
|
+
_defineProperty(this, "clickTolerance", void 0);
|
|
9
|
+
_defineProperty(this, "map", void 0);
|
|
9
10
|
this.map = map;
|
|
10
11
|
this.clickTolerance = options.clickTolerance;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, {
|
|
37
|
-
key: "mouseup",
|
|
38
|
-
value: function mouseup(e) {
|
|
39
|
-
this.map.emit(e.type, new MapMouseEvent(e.type, this.map, e));
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
key: "click",
|
|
43
|
-
value: function click(e, point) {
|
|
44
|
-
if (this.mousedownPos && this.mousedownPos.dist(point) >= this.clickTolerance) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this.map.emit(e.type, new MapMouseEvent(e.type, this.map, e));
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
50
|
-
key: "dblclick",
|
|
51
|
-
value: function dblclick(e) {
|
|
52
|
-
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
|
|
53
|
-
// - DblClickZoom
|
|
54
|
-
return this.firePreventable(new MapMouseEvent(e.type, this.map, e));
|
|
55
|
-
}
|
|
56
|
-
}, {
|
|
57
|
-
key: "mouseover",
|
|
58
|
-
value: function mouseover(e) {
|
|
59
|
-
this.map.emit(e.type, new MapMouseEvent(e.type, this.map, e));
|
|
60
|
-
}
|
|
61
|
-
}, {
|
|
62
|
-
key: "mouseout",
|
|
63
|
-
value: function mouseout(e) {
|
|
64
|
-
this.map.emit(e.type, new MapMouseEvent(e.type, this.map, e));
|
|
65
|
-
}
|
|
66
|
-
}, {
|
|
67
|
-
key: "touchstart",
|
|
68
|
-
value: function touchstart(e) {
|
|
69
|
-
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
|
|
70
|
-
// - TouchPan
|
|
71
|
-
// - TouchZoom
|
|
72
|
-
// - TouchRotate
|
|
73
|
-
// - TouchPitch
|
|
74
|
-
// - TapZoom
|
|
75
|
-
// - SwipeZoom
|
|
76
|
-
return this.firePreventable(new MapTouchEvent(e.type, this.map, e));
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
key: "touchmove",
|
|
80
|
-
value: function touchmove(e) {
|
|
81
|
-
this.map.emit(e.type, new MapTouchEvent(e.type, this.map, e));
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
key: "touchend",
|
|
85
|
-
value: function touchend(e) {
|
|
86
|
-
this.map.emit(e.type, new MapTouchEvent(e.type, this.map, e));
|
|
87
|
-
}
|
|
88
|
-
}, {
|
|
89
|
-
key: "touchcancel",
|
|
90
|
-
value: function touchcancel(e) {
|
|
91
|
-
this.map.emit(e.type, new MapTouchEvent(e.type, this.map, e));
|
|
92
|
-
}
|
|
93
|
-
}, {
|
|
94
|
-
key: "firePreventable",
|
|
95
|
-
value: function firePreventable(mapEvent) {
|
|
96
|
-
this.map.emit(mapEvent.type, mapEvent);
|
|
97
|
-
if (mapEvent.defaultPrevented) {
|
|
98
|
-
// returning an object marks the handler as active and resets other handlers
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}, {
|
|
103
|
-
key: "isEnabled",
|
|
104
|
-
value: function isEnabled() {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}, {
|
|
108
|
-
key: "isActive",
|
|
109
|
-
value: function isActive() {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "enable",
|
|
114
|
-
value: function enable() {
|
|
115
|
-
return false;
|
|
13
|
+
reset() {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
delete this.mousedownPos;
|
|
16
|
+
}
|
|
17
|
+
wheel(e) {
|
|
18
|
+
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
|
|
19
|
+
// - ScrollZoom
|
|
20
|
+
return this.firePreventable(new MapWheelEvent(e.type, this.map, e));
|
|
21
|
+
}
|
|
22
|
+
mousedown(e, point) {
|
|
23
|
+
this.mousedownPos = point;
|
|
24
|
+
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
|
|
25
|
+
// - MousePan
|
|
26
|
+
// - MouseRotate
|
|
27
|
+
// - MousePitch
|
|
28
|
+
// - DblclickHandler
|
|
29
|
+
return this.firePreventable(new MapMouseEvent(e.type, this.map, e));
|
|
30
|
+
}
|
|
31
|
+
mouseup(e) {
|
|
32
|
+
this.map.emit(e.type, new MapMouseEvent(e.type, this.map, e));
|
|
33
|
+
}
|
|
34
|
+
click(e, point) {
|
|
35
|
+
if (this.mousedownPos && this.mousedownPos.dist(point) >= this.clickTolerance) {
|
|
36
|
+
return;
|
|
116
37
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
38
|
+
this.map.emit(e.type, new MapMouseEvent(e.type, this.map, e));
|
|
39
|
+
}
|
|
40
|
+
dblclick(e) {
|
|
41
|
+
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
|
|
42
|
+
// - DblClickZoom
|
|
43
|
+
return this.firePreventable(new MapMouseEvent(e.type, this.map, e));
|
|
44
|
+
}
|
|
45
|
+
mouseover(e) {
|
|
46
|
+
this.map.emit(e.type, new MapMouseEvent(e.type, this.map, e));
|
|
47
|
+
}
|
|
48
|
+
mouseout(e) {
|
|
49
|
+
this.map.emit(e.type, new MapMouseEvent(e.type, this.map, e));
|
|
50
|
+
}
|
|
51
|
+
touchstart(e) {
|
|
52
|
+
// If mapEvent.preventDefault() is called by the user, prevent handlers such as:
|
|
53
|
+
// - TouchPan
|
|
54
|
+
// - TouchZoom
|
|
55
|
+
// - TouchRotate
|
|
56
|
+
// - TouchPitch
|
|
57
|
+
// - TapZoom
|
|
58
|
+
// - SwipeZoom
|
|
59
|
+
return this.firePreventable(new MapTouchEvent(e.type, this.map, e));
|
|
60
|
+
}
|
|
61
|
+
touchmove(e) {
|
|
62
|
+
this.map.emit(e.type, new MapTouchEvent(e.type, this.map, e));
|
|
63
|
+
}
|
|
64
|
+
touchend(e) {
|
|
65
|
+
this.map.emit(e.type, new MapTouchEvent(e.type, this.map, e));
|
|
66
|
+
}
|
|
67
|
+
touchcancel(e) {
|
|
68
|
+
this.map.emit(e.type, new MapTouchEvent(e.type, this.map, e));
|
|
69
|
+
}
|
|
70
|
+
firePreventable(mapEvent) {
|
|
71
|
+
this.map.emit(mapEvent.type, mapEvent);
|
|
72
|
+
if (mapEvent.defaultPrevented) {
|
|
73
|
+
// returning an object marks the handler as active and resets other handlers
|
|
74
|
+
return {};
|
|
121
75
|
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
76
|
+
}
|
|
77
|
+
isEnabled() {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
isActive() {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
enable() {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
disable() {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,118 +1,99 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
2
|
// @ts-ignore
|
|
4
3
|
|
|
5
4
|
import DOM from "../../utils/dom";
|
|
6
5
|
import { buttonStillPressed } from "./util";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export default class MouseHandler {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
_defineProperty(this, "enabled", void 0);
|
|
9
|
+
_defineProperty(this, "active", void 0);
|
|
10
|
+
_defineProperty(this, "lastPoint", void 0);
|
|
11
|
+
_defineProperty(this, "eventButton", void 0);
|
|
12
|
+
_defineProperty(this, "moved", void 0);
|
|
13
|
+
_defineProperty(this, "clickTolerance", void 0);
|
|
10
14
|
this.reset();
|
|
11
15
|
this.clickTolerance = options.clickTolerance || 1;
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
reset() {
|
|
18
|
+
this.active = false;
|
|
19
|
+
this.moved = false;
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
delete this.lastPoint;
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
delete this.eventButton;
|
|
24
|
+
}
|
|
25
|
+
mousedown(e, point) {
|
|
26
|
+
if (this.lastPoint) {
|
|
27
|
+
return;
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (this.lastPoint) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
var eventButton = DOM.mouseButton(e);
|
|
30
|
-
if (!this.correctButton(e, eventButton)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this.lastPoint = point;
|
|
34
|
-
this.eventButton = eventButton;
|
|
29
|
+
const eventButton = DOM.mouseButton(e);
|
|
30
|
+
if (!this.correctButton(e, eventButton)) {
|
|
31
|
+
return;
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
e.preventDefault();
|
|
44
|
-
if (buttonStillPressed(e, this.eventButton)) {
|
|
45
|
-
// Some browsers don't fire a `mouseup` when the mouseup occurs outside
|
|
46
|
-
// the window or iframe:
|
|
47
|
-
// https://github.com/mapbox/mapbox-gl-js/issues/4622
|
|
48
|
-
//
|
|
49
|
-
// If the button is no longer pressed during this `mousemove` it may have
|
|
50
|
-
// been released outside of the window or iframe.
|
|
51
|
-
this.reset();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (!this.moved && point.dist(lastPoint) < this.clickTolerance) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
this.moved = true;
|
|
58
|
-
this.lastPoint = point;
|
|
59
|
-
|
|
60
|
-
// implemented by child class
|
|
61
|
-
return this.move(lastPoint, point);
|
|
33
|
+
this.lastPoint = point;
|
|
34
|
+
this.eventButton = eventButton;
|
|
35
|
+
}
|
|
36
|
+
mousemoveWindow(e, point) {
|
|
37
|
+
const lastPoint = this.lastPoint;
|
|
38
|
+
if (!lastPoint) {
|
|
39
|
+
return;
|
|
62
40
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (this.moved) {
|
|
74
|
-
DOM.suppressClick();
|
|
75
|
-
}
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
if (buttonStillPressed(e, this.eventButton)) {
|
|
43
|
+
// Some browsers don't fire a `mouseup` when the mouseup occurs outside
|
|
44
|
+
// the window or iframe:
|
|
45
|
+
// https://github.com/mapbox/mapbox-gl-js/issues/4622
|
|
46
|
+
//
|
|
47
|
+
// If the button is no longer pressed during this `mousemove` it may have
|
|
48
|
+
// been released outside of the window or iframe.
|
|
76
49
|
this.reset();
|
|
50
|
+
return;
|
|
77
51
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
value: function enable() {
|
|
81
|
-
this.enabled = true;
|
|
52
|
+
if (!this.moved && point.dist(lastPoint) < this.clickTolerance) {
|
|
53
|
+
return;
|
|
82
54
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
55
|
+
this.moved = true;
|
|
56
|
+
this.lastPoint = point;
|
|
57
|
+
|
|
58
|
+
// implemented by child class
|
|
59
|
+
return this.move(lastPoint, point);
|
|
60
|
+
}
|
|
61
|
+
mouseupWindow(e) {
|
|
62
|
+
if (!this.lastPoint) {
|
|
63
|
+
return;
|
|
88
64
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return this.enabled;
|
|
65
|
+
const eventButton = DOM.mouseButton(e);
|
|
66
|
+
if (eventButton !== this.eventButton) {
|
|
67
|
+
return;
|
|
93
68
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
value: function isActive() {
|
|
97
|
-
return this.active;
|
|
69
|
+
if (this.moved) {
|
|
70
|
+
DOM.suppressClick();
|
|
98
71
|
}
|
|
72
|
+
this.reset();
|
|
73
|
+
}
|
|
74
|
+
enable() {
|
|
75
|
+
this.enabled = true;
|
|
76
|
+
}
|
|
77
|
+
disable() {
|
|
78
|
+
this.enabled = false;
|
|
79
|
+
this.reset();
|
|
80
|
+
}
|
|
81
|
+
isEnabled() {
|
|
82
|
+
return this.enabled;
|
|
83
|
+
}
|
|
84
|
+
isActive() {
|
|
85
|
+
return this.active;
|
|
86
|
+
}
|
|
99
87
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return false; // implemented by child
|
|
106
|
-
}
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
89
|
+
correctButton(e, button) {
|
|
90
|
+
// eslint-disable-line
|
|
91
|
+
return false; // implemented by child
|
|
92
|
+
}
|
|
107
93
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
}]);
|
|
116
|
-
return MouseHandler;
|
|
117
|
-
}();
|
|
118
|
-
export { MouseHandler as default };
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
95
|
+
move(lastPoint, point) {
|
|
96
|
+
// eslint-disable-line
|
|
97
|
+
return; // implemented by child
|
|
98
|
+
}
|
|
99
|
+
}
|