@antv/l7-map 2.25.7 → 2.25.9

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.
Files changed (159) hide show
  1. package/es/index.d.ts +5 -0
  2. package/es/index.js +4 -0
  3. package/es/map/camera.d.ts +690 -0
  4. package/es/map/camera.js +1138 -0
  5. package/es/map/css/l7.css +171 -0
  6. package/es/map/events.d.ts +384 -0
  7. package/es/map/events.js +231 -0
  8. package/es/map/geo/edge_insets.d.ts +97 -0
  9. package/es/map/geo/edge_insets.js +115 -0
  10. package/es/map/geo/lng_lat.d.ts +116 -0
  11. package/es/map/geo/lng_lat.js +159 -0
  12. package/es/map/geo/lng_lat_bounds.d.ts +217 -0
  13. package/es/map/geo/lng_lat_bounds.js +334 -0
  14. package/es/map/geo/mercator_coordinate.d.ts +113 -0
  15. package/es/map/geo/mercator_coordinate.js +142 -0
  16. package/es/map/geo/transform.d.ts +262 -0
  17. package/es/map/geo/transform.js +736 -0
  18. package/es/map/handler/box_zoom.d.ts +65 -0
  19. package/es/map/handler/box_zoom.js +145 -0
  20. package/es/map/handler/click_zoom.d.ts +24 -0
  21. package/es/map/handler/click_zoom.js +47 -0
  22. package/es/map/handler/cooperative_gestures.d.ts +40 -0
  23. package/es/map/handler/cooperative_gestures.js +94 -0
  24. package/es/map/handler/drag_handler.d.ts +88 -0
  25. package/es/map/handler/drag_handler.js +89 -0
  26. package/es/map/handler/drag_move_state_manager.d.ts +30 -0
  27. package/es/map/handler/drag_move_state_manager.js +94 -0
  28. package/es/map/handler/handler_util.d.ts +3 -0
  29. package/es/map/handler/handler_util.js +8 -0
  30. package/es/map/handler/keyboard.d.ts +88 -0
  31. package/es/map/handler/keyboard.js +197 -0
  32. package/es/map/handler/map_event.d.ts +46 -0
  33. package/es/map/handler/map_event.js +131 -0
  34. package/es/map/handler/mouse.d.ts +30 -0
  35. package/es/map/handler/mouse.js +85 -0
  36. package/es/map/handler/one_finger_touch_drag.d.ts +15 -0
  37. package/es/map/handler/one_finger_touch_drag.js +39 -0
  38. package/es/map/handler/scroll_zoom.d.ts +102 -0
  39. package/es/map/handler/scroll_zoom.js +312 -0
  40. package/es/map/handler/shim/dblclick_zoom.d.ts +44 -0
  41. package/es/map/handler/shim/dblclick_zoom.js +60 -0
  42. package/es/map/handler/shim/drag_pan.d.ts +79 -0
  43. package/es/map/handler/shim/drag_pan.js +77 -0
  44. package/es/map/handler/shim/drag_rotate.d.ts +54 -0
  45. package/es/map/handler/shim/drag_rotate.js +66 -0
  46. package/es/map/handler/shim/two_fingers_touch.d.ts +74 -0
  47. package/es/map/handler/shim/two_fingers_touch.js +106 -0
  48. package/es/map/handler/tap_drag_zoom.d.ts +28 -0
  49. package/es/map/handler/tap_drag_zoom.js +92 -0
  50. package/es/map/handler/tap_recognizer.d.ts +35 -0
  51. package/es/map/handler/tap_recognizer.js +107 -0
  52. package/es/map/handler/tap_zoom.d.ts +28 -0
  53. package/es/map/handler/tap_zoom.js +87 -0
  54. package/es/map/handler/touch_pan.d.ts +40 -0
  55. package/es/map/handler/touch_pan.js +85 -0
  56. package/es/map/handler/transform-provider.d.ts +23 -0
  57. package/es/map/handler/transform-provider.js +35 -0
  58. package/es/map/handler/two_fingers_touch.d.ts +107 -0
  59. package/es/map/handler/two_fingers_touch.js +289 -0
  60. package/es/map/handler_inertia.d.ts +20 -0
  61. package/es/map/handler_inertia.js +128 -0
  62. package/es/map/handler_manager.d.ts +154 -0
  63. package/es/map/handler_manager.js +466 -0
  64. package/es/map/map.d.ts +637 -0
  65. package/es/map/map.js +984 -0
  66. package/es/map/util/abort_error.d.ts +15 -0
  67. package/es/map/util/abort_error.js +21 -0
  68. package/es/map/util/browser.d.ts +10 -0
  69. package/es/map/util/browser.js +30 -0
  70. package/es/map/util/dom.d.ts +30 -0
  71. package/es/map/util/dom.js +105 -0
  72. package/es/map/util/evented.d.ts +75 -0
  73. package/es/map/util/evented.js +158 -0
  74. package/es/map/util/simpleMapCoord.d.ts +31 -0
  75. package/es/map/util/simpleMapCoord.js +54 -0
  76. package/es/map/util/task_queue.d.ts +18 -0
  77. package/es/map/util/task_queue.js +54 -0
  78. package/es/map/util/util.d.ts +104 -0
  79. package/es/map/util/util.js +155 -0
  80. package/lib/index.d.ts +5 -0
  81. package/lib/index.js +33 -0
  82. package/lib/map/camera.d.ts +690 -0
  83. package/lib/map/camera.js +1145 -0
  84. package/lib/map/css/l7.css +171 -0
  85. package/lib/map/events.d.ts +384 -0
  86. package/lib/map/events.js +240 -0
  87. package/lib/map/geo/edge_insets.d.ts +97 -0
  88. package/lib/map/geo/edge_insets.js +122 -0
  89. package/lib/map/geo/lng_lat.d.ts +116 -0
  90. package/lib/map/geo/lng_lat.js +166 -0
  91. package/lib/map/geo/lng_lat_bounds.d.ts +217 -0
  92. package/lib/map/geo/lng_lat_bounds.js +341 -0
  93. package/lib/map/geo/mercator_coordinate.d.ts +113 -0
  94. package/lib/map/geo/mercator_coordinate.js +157 -0
  95. package/lib/map/geo/transform.d.ts +262 -0
  96. package/lib/map/geo/transform.js +744 -0
  97. package/lib/map/handler/box_zoom.d.ts +65 -0
  98. package/lib/map/handler/box_zoom.js +153 -0
  99. package/lib/map/handler/click_zoom.d.ts +24 -0
  100. package/lib/map/handler/click_zoom.js +54 -0
  101. package/lib/map/handler/cooperative_gestures.d.ts +40 -0
  102. package/lib/map/handler/cooperative_gestures.js +101 -0
  103. package/lib/map/handler/drag_handler.d.ts +88 -0
  104. package/lib/map/handler/drag_handler.js +97 -0
  105. package/lib/map/handler/drag_move_state_manager.d.ts +30 -0
  106. package/lib/map/handler/drag_move_state_manager.js +103 -0
  107. package/lib/map/handler/handler_util.d.ts +3 -0
  108. package/lib/map/handler/handler_util.js +14 -0
  109. package/lib/map/handler/keyboard.d.ts +88 -0
  110. package/lib/map/handler/keyboard.js +205 -0
  111. package/lib/map/handler/map_event.d.ts +46 -0
  112. package/lib/map/handler/map_event.js +140 -0
  113. package/lib/map/handler/mouse.d.ts +30 -0
  114. package/lib/map/handler/mouse.js +93 -0
  115. package/lib/map/handler/one_finger_touch_drag.d.ts +15 -0
  116. package/lib/map/handler/one_finger_touch_drag.js +47 -0
  117. package/lib/map/handler/scroll_zoom.d.ts +102 -0
  118. package/lib/map/handler/scroll_zoom.js +320 -0
  119. package/lib/map/handler/shim/dblclick_zoom.d.ts +44 -0
  120. package/lib/map/handler/shim/dblclick_zoom.js +68 -0
  121. package/lib/map/handler/shim/drag_pan.d.ts +79 -0
  122. package/lib/map/handler/shim/drag_pan.js +85 -0
  123. package/lib/map/handler/shim/drag_rotate.d.ts +54 -0
  124. package/lib/map/handler/shim/drag_rotate.js +74 -0
  125. package/lib/map/handler/shim/two_fingers_touch.d.ts +74 -0
  126. package/lib/map/handler/shim/two_fingers_touch.js +114 -0
  127. package/lib/map/handler/tap_drag_zoom.d.ts +28 -0
  128. package/lib/map/handler/tap_drag_zoom.js +99 -0
  129. package/lib/map/handler/tap_recognizer.d.ts +35 -0
  130. package/lib/map/handler/tap_recognizer.js +116 -0
  131. package/lib/map/handler/tap_zoom.d.ts +28 -0
  132. package/lib/map/handler/tap_zoom.js +94 -0
  133. package/lib/map/handler/touch_pan.d.ts +40 -0
  134. package/lib/map/handler/touch_pan.js +92 -0
  135. package/lib/map/handler/transform-provider.d.ts +23 -0
  136. package/lib/map/handler/transform-provider.js +43 -0
  137. package/lib/map/handler/two_fingers_touch.d.ts +107 -0
  138. package/lib/map/handler/two_fingers_touch.js +296 -0
  139. package/lib/map/handler_inertia.d.ts +20 -0
  140. package/lib/map/handler_inertia.js +136 -0
  141. package/lib/map/handler_manager.d.ts +154 -0
  142. package/lib/map/handler_manager.js +474 -0
  143. package/lib/map/map.d.ts +637 -0
  144. package/lib/map/map.js +991 -0
  145. package/lib/map/util/abort_error.d.ts +15 -0
  146. package/lib/map/util/abort_error.js +29 -0
  147. package/lib/map/util/browser.d.ts +10 -0
  148. package/lib/map/util/browser.js +36 -0
  149. package/lib/map/util/dom.d.ts +30 -0
  150. package/lib/map/util/dom.js +113 -0
  151. package/lib/map/util/evented.d.ts +75 -0
  152. package/lib/map/util/evented.js +167 -0
  153. package/lib/map/util/simpleMapCoord.d.ts +31 -0
  154. package/lib/map/util/simpleMapCoord.js +62 -0
  155. package/lib/map/util/task_queue.d.ts +18 -0
  156. package/lib/map/util/task_queue.js +62 -0
  157. package/lib/map/util/util.d.ts +104 -0
  158. package/lib/map/util/util.js +171 -0
  159. package/package.json +2 -2
@@ -0,0 +1,466 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import Point from '@mapbox/point-geometry';
3
+ import { BoxZoomHandler } from "./handler/box_zoom";
4
+ import { ClickZoomHandler } from "./handler/click_zoom";
5
+ import { CooperativeGesturesHandler } from "./handler/cooperative_gestures";
6
+ import { KeyboardHandler } from "./handler/keyboard";
7
+ import { BlockableMapEventHandler, MapEventHandler } from "./handler/map_event";
8
+ import { generateMousePanHandler, generateMousePitchHandler, generateMouseRotationHandler } from "./handler/mouse";
9
+ import { ScrollZoomHandler } from "./handler/scroll_zoom";
10
+ import { DoubleClickZoomHandler } from "./handler/shim/dblclick_zoom";
11
+ import { DragPanHandler } from "./handler/shim/drag_pan";
12
+ import { DragRotateHandler } from "./handler/shim/drag_rotate";
13
+ import { TwoFingersTouchZoomRotateHandler } from "./handler/shim/two_fingers_touch";
14
+ import { TapDragZoomHandler } from "./handler/tap_drag_zoom";
15
+ import { TapZoomHandler } from "./handler/tap_zoom";
16
+ import { TouchPanHandler } from "./handler/touch_pan";
17
+ import { TwoFingersTouchPitchHandler, TwoFingersTouchRotateHandler, TwoFingersTouchZoomHandler } from "./handler/two_fingers_touch";
18
+ import { HandlerInertia } from "./handler_inertia";
19
+ import { browser } from "./util/browser";
20
+ import { DOM } from "./util/dom";
21
+ import { Event } from "./util/evented";
22
+ import { extend } from "./util/util";
23
+ const isMoving = p => p.zoom || p.drag || p.pitch || p.rotate;
24
+ class RenderFrameEvent extends Event {
25
+ constructor(type, timeStamp) {
26
+ super(type);
27
+ _defineProperty(this, "type", 'renderFrame');
28
+ _defineProperty(this, "timeStamp", void 0);
29
+ this.timeStamp = timeStamp;
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Handlers interpret dom events and return camera changes that should be
35
+ * applied to the map (`HandlerResult`s). The camera changes are all deltas.
36
+ * The handler itself should have no knowledge of the map's current state.
37
+ * This makes it easier to merge multiple results and keeps handlers simpler.
38
+ * For example, if there is a mousedown and mousemove, the mousePan handler
39
+ * would return a `panDelta` on the mousemove.
40
+ */
41
+
42
+ /**
43
+ * All handler methods that are called with events can optionally return a `HandlerResult`.
44
+ */
45
+
46
+ function hasChange(result) {
47
+ return result.panDelta && result.panDelta.mag() || result.zoomDelta || result.bearingDelta || result.pitchDelta;
48
+ }
49
+ export class HandlerManager {
50
+ constructor(map, options) {
51
+ _defineProperty(this, "_map", void 0);
52
+ _defineProperty(this, "_el", void 0);
53
+ _defineProperty(this, "_handlers", void 0);
54
+ _defineProperty(this, "_eventsInProgress", void 0);
55
+ _defineProperty(this, "_frameId", void 0);
56
+ _defineProperty(this, "_inertia", void 0);
57
+ _defineProperty(this, "_bearingSnap", void 0);
58
+ _defineProperty(this, "_handlersById", void 0);
59
+ _defineProperty(this, "_updatingCamera", void 0);
60
+ _defineProperty(this, "_changes", void 0);
61
+ _defineProperty(this, "_zoom", void 0);
62
+ _defineProperty(this, "_previousActiveHandlers", void 0);
63
+ _defineProperty(this, "_listeners", void 0);
64
+ _defineProperty(this, "handleWindowEvent", e => {
65
+ this.handleEvent(e, `${e.type}Window`);
66
+ });
67
+ _defineProperty(this, "handleEvent", (e, eventName) => {
68
+ if (e.type === 'blur') {
69
+ this.stop(true);
70
+ return;
71
+ }
72
+ this._updatingCamera = true;
73
+ const inputEvent = e.type === 'renderFrame' ? undefined : e;
74
+
75
+ /*
76
+ * We don't call e.preventDefault() for any events by default.
77
+ * Handlers are responsible for calling it where necessary.
78
+ */
79
+
80
+ const mergedHandlerResult = {
81
+ needsRenderFrame: false
82
+ };
83
+ const eventsInProgress = {};
84
+ const activeHandlers = {};
85
+ const eventTouches = e.touches;
86
+ const mapTouches = eventTouches ? this._getMapTouches(eventTouches) : undefined;
87
+ const points = mapTouches ? DOM.touchPos(this._map.getCanvasContainer(), mapTouches) : DOM.mousePos(this._map.getCanvasContainer(), e);
88
+ for (const {
89
+ handlerName,
90
+ handler,
91
+ allowed
92
+ } of this._handlers) {
93
+ if (!handler.isEnabled()) continue;
94
+ let data;
95
+ if (this._blockedByActive(activeHandlers, allowed, handlerName)) {
96
+ handler.reset();
97
+ } else {
98
+ if (handler[eventName || e.type]) {
99
+ data = handler[eventName || e.type](e, points, mapTouches);
100
+ this.mergeHandlerResult(mergedHandlerResult, eventsInProgress, data, handlerName, inputEvent);
101
+ if (data && data.needsRenderFrame) {
102
+ this._triggerRenderFrame();
103
+ }
104
+ }
105
+ }
106
+ if (data || handler.isActive()) {
107
+ activeHandlers[handlerName] = handler;
108
+ }
109
+ }
110
+ const deactivatedHandlers = {};
111
+ for (const name in this._previousActiveHandlers) {
112
+ if (!activeHandlers[name]) {
113
+ deactivatedHandlers[name] = inputEvent;
114
+ }
115
+ }
116
+ this._previousActiveHandlers = activeHandlers;
117
+ if (Object.keys(deactivatedHandlers).length || hasChange(mergedHandlerResult)) {
118
+ this._changes.push([mergedHandlerResult, eventsInProgress, deactivatedHandlers]);
119
+ this._triggerRenderFrame();
120
+ }
121
+ if (Object.keys(activeHandlers).length || hasChange(mergedHandlerResult)) {
122
+ this._map._stop(true);
123
+ }
124
+ this._updatingCamera = false;
125
+ const {
126
+ cameraAnimation
127
+ } = mergedHandlerResult;
128
+ if (cameraAnimation) {
129
+ this._inertia.clear();
130
+ this._fireEvents({}, {}, true);
131
+ this._changes = [];
132
+ cameraAnimation(this._map);
133
+ }
134
+ });
135
+ this._map = map;
136
+ this._el = this._map.getCanvasContainer();
137
+ this._handlers = [];
138
+ this._handlersById = {};
139
+ this._changes = [];
140
+ this._inertia = new HandlerInertia(map);
141
+ this._bearingSnap = options.bearingSnap || 7;
142
+ this._previousActiveHandlers = {};
143
+
144
+ // Track whether map is currently moving, to compute start/move/end events
145
+ this._eventsInProgress = {};
146
+ this._addDefaultHandlers(options);
147
+ const el = this._el;
148
+ this._listeners = [
149
+ // This needs to be `passive: true` so that a double tap fires two
150
+ // pairs of touchstart/end events in iOS Safari 13. If this is set to
151
+ // `passive: false` then the second pair of events is only fired if
152
+ // preventDefault() is called on the first touchstart. Calling preventDefault()
153
+ // undesirably prevents click events.
154
+ [el, 'touchstart', {
155
+ passive: true
156
+ }],
157
+ // This needs to be `passive: false` so that scrolls and pinches can be
158
+ // prevented in browsers that don't support `touch-actions: none`, for example iOS Safari 12.
159
+ [el, 'touchmove', {
160
+ passive: false
161
+ }], [el, 'touchend', undefined], [el, 'touchcancel', undefined], [el, 'mousedown', undefined], [el, 'mousemove', undefined], [el, 'mouseup', undefined],
162
+ // Bind window-level event listeners for move and up/end events. In the absence of
163
+ // the pointer capture API, which is not supported by all necessary platforms,
164
+ // window-level event listeners give us the best shot at capturing events that
165
+ // fall outside the map canvas element. Use `{capture: true}` for the move event
166
+ // to prevent map move events from being fired during a drag.
167
+ [document, 'mousemove', {
168
+ capture: true
169
+ }], [document, 'mouseup', undefined], [el, 'mouseover', undefined], [el, 'mouseout', undefined], [el, 'dblclick', undefined], [el, 'click', undefined], [el, 'keydown', {
170
+ capture: false
171
+ }], [el, 'keyup', undefined], [el, 'wheel', {
172
+ passive: false
173
+ }], [el, 'contextmenu', undefined], [window, 'blur', undefined]];
174
+ for (const [target, type, listenerOptions] of this._listeners) {
175
+ DOM.addEventListener(target, type, target === document ? this.handleWindowEvent : this.handleEvent, listenerOptions);
176
+ }
177
+ }
178
+ destroy() {
179
+ for (const [target, type, listenerOptions] of this._listeners) {
180
+ DOM.removeEventListener(target, type, target === document ? this.handleWindowEvent : this.handleEvent, listenerOptions);
181
+ }
182
+ }
183
+ _addDefaultHandlers(options) {
184
+ const map = this._map;
185
+ const el = map.getCanvasContainer();
186
+ this._add('mapEvent', new MapEventHandler(map, options));
187
+ const boxZoom = map.boxZoom = new BoxZoomHandler(map, options);
188
+ this._add('boxZoom', boxZoom);
189
+ if (options.interactive && options.boxZoom) {
190
+ boxZoom.enable();
191
+ }
192
+ const cooperativeGestures = map.cooperativeGestures = new CooperativeGesturesHandler(map, options.cooperativeGestures);
193
+ this._add('cooperativeGestures', cooperativeGestures);
194
+ if (options.cooperativeGestures) {
195
+ cooperativeGestures.enable();
196
+ }
197
+ const tapZoom = new TapZoomHandler(map);
198
+ const clickZoom = new ClickZoomHandler(map);
199
+ map.doubleClickZoom = new DoubleClickZoomHandler(clickZoom, tapZoom);
200
+ this._add('tapZoom', tapZoom);
201
+ this._add('clickZoom', clickZoom);
202
+ if (options.interactive && options.doubleClickZoom) {
203
+ map.doubleClickZoom.enable();
204
+ }
205
+ const tapDragZoom = new TapDragZoomHandler();
206
+ this._add('tapDragZoom', tapDragZoom);
207
+ const touchPitch = map.touchPitch = new TwoFingersTouchPitchHandler(map);
208
+ this._add('touchPitch', touchPitch);
209
+ if (options.interactive && options.touchPitch) {
210
+ map.touchPitch.enable(options.touchPitch);
211
+ }
212
+ const mouseRotate = generateMouseRotationHandler(options);
213
+ const mousePitch = generateMousePitchHandler(options);
214
+ map.dragRotate = new DragRotateHandler(options, mouseRotate, mousePitch);
215
+ this._add('mouseRotate', mouseRotate, ['mousePitch']);
216
+ this._add('mousePitch', mousePitch, ['mouseRotate']);
217
+ if (options.interactive && options.dragRotate) {
218
+ map.dragRotate.enable();
219
+ }
220
+ const mousePan = generateMousePanHandler(options);
221
+ const touchPan = new TouchPanHandler(options, map);
222
+ map.dragPan = new DragPanHandler(el, mousePan, touchPan);
223
+ this._add('mousePan', mousePan);
224
+ this._add('touchPan', touchPan, ['touchZoom', 'touchRotate']);
225
+ if (options.interactive && options.dragPan) {
226
+ map.dragPan.enable(options.dragPan);
227
+ }
228
+ const touchRotate = new TwoFingersTouchRotateHandler();
229
+ const touchZoom = new TwoFingersTouchZoomHandler();
230
+ map.touchZoomRotate = new TwoFingersTouchZoomRotateHandler(el, touchZoom, touchRotate, tapDragZoom);
231
+ this._add('touchRotate', touchRotate, ['touchPan', 'touchZoom']);
232
+ this._add('touchZoom', touchZoom, ['touchPan', 'touchRotate']);
233
+ if (options.interactive && options.touchZoomRotate) {
234
+ map.touchZoomRotate.enable(options.touchZoomRotate);
235
+ }
236
+ const scrollZoom = map.scrollZoom = new ScrollZoomHandler(map, () => this._triggerRenderFrame());
237
+ this._add('scrollZoom', scrollZoom, ['mousePan']);
238
+ if (options.interactive && options.scrollZoom) {
239
+ map.scrollZoom.enable(options.scrollZoom);
240
+ }
241
+ const keyboard = map.keyboard = new KeyboardHandler(map);
242
+ this._add('keyboard', keyboard);
243
+ if (options.interactive && options.keyboard) {
244
+ map.keyboard.enable();
245
+ }
246
+ this._add('blockableMapEvent', new BlockableMapEventHandler(map));
247
+ }
248
+ _add(handlerName, handler, allowed) {
249
+ this._handlers.push({
250
+ handlerName,
251
+ handler,
252
+ allowed
253
+ });
254
+ this._handlersById[handlerName] = handler;
255
+ }
256
+ stop(allowEndAnimation) {
257
+ // do nothing if this method was triggered by a gesture update
258
+ if (this._updatingCamera) return;
259
+ for (const {
260
+ handler
261
+ } of this._handlers) {
262
+ handler.reset();
263
+ }
264
+ this._inertia.clear();
265
+ this._fireEvents({}, {}, allowEndAnimation);
266
+ this._changes = [];
267
+ }
268
+ isActive() {
269
+ for (const {
270
+ handler
271
+ } of this._handlers) {
272
+ if (handler.isActive()) return true;
273
+ }
274
+ return false;
275
+ }
276
+ isZooming() {
277
+ return !!this._eventsInProgress.zoom || this._map.scrollZoom.isZooming();
278
+ }
279
+ isRotating() {
280
+ return !!this._eventsInProgress.rotate;
281
+ }
282
+ isMoving() {
283
+ return Boolean(isMoving(this._eventsInProgress)) || this.isZooming();
284
+ }
285
+ _blockedByActive(activeHandlers, allowed, myName) {
286
+ for (const name in activeHandlers) {
287
+ if (name === myName) continue;
288
+ if (!allowed || allowed.indexOf(name) < 0) {
289
+ return true;
290
+ }
291
+ }
292
+ return false;
293
+ }
294
+ _getMapTouches(touches) {
295
+ const mapTouches = [];
296
+ for (const t of touches) {
297
+ const target = t.target;
298
+ if (this._el.contains(target)) {
299
+ mapTouches.push(t);
300
+ }
301
+ }
302
+ return mapTouches;
303
+ }
304
+ mergeHandlerResult(mergedHandlerResult, eventsInProgress, handlerResult, name, e) {
305
+ if (!handlerResult) return;
306
+ extend(mergedHandlerResult, handlerResult);
307
+ const eventData = {
308
+ handlerName: name,
309
+ originalEvent: handlerResult.originalEvent || e
310
+ };
311
+
312
+ // track which handler changed which camera property
313
+ if (handlerResult.zoomDelta !== undefined) {
314
+ eventsInProgress.zoom = eventData;
315
+ }
316
+ if (handlerResult.panDelta !== undefined) {
317
+ eventsInProgress.drag = eventData;
318
+ }
319
+ if (handlerResult.pitchDelta !== undefined) {
320
+ eventsInProgress.pitch = eventData;
321
+ }
322
+ if (handlerResult.bearingDelta !== undefined) {
323
+ eventsInProgress.rotate = eventData;
324
+ }
325
+ }
326
+ _applyChanges() {
327
+ const combined = {};
328
+ const combinedEventsInProgress = {};
329
+ const combinedDeactivatedHandlers = {};
330
+ for (const [change, eventsInProgress, deactivatedHandlers] of this._changes) {
331
+ if (change.panDelta) combined.panDelta = (combined.panDelta || new Point(0, 0))._add(change.panDelta);
332
+ if (change.zoomDelta) combined.zoomDelta = (combined.zoomDelta || 0) + change.zoomDelta;
333
+ if (change.bearingDelta) combined.bearingDelta = (combined.bearingDelta || 0) + change.bearingDelta;
334
+ if (change.pitchDelta) combined.pitchDelta = (combined.pitchDelta || 0) + change.pitchDelta;
335
+ if (change.around !== undefined) combined.around = change.around;
336
+ if (change.pinchAround !== undefined) combined.pinchAround = change.pinchAround;
337
+ if (change.noInertia) combined.noInertia = change.noInertia;
338
+ extend(combinedEventsInProgress, eventsInProgress);
339
+ extend(combinedDeactivatedHandlers, deactivatedHandlers);
340
+ }
341
+ this._updateMapTransform(combined, combinedEventsInProgress, combinedDeactivatedHandlers);
342
+ this._changes = [];
343
+ }
344
+ _updateMapTransform(combinedResult, combinedEventsInProgress, deactivatedHandlers) {
345
+ const map = this._map;
346
+ const tr = map._getTransformForUpdate();
347
+ if (!hasChange(combinedResult)) {
348
+ return this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);
349
+ }
350
+ const {
351
+ panDelta,
352
+ zoomDelta,
353
+ bearingDelta,
354
+ pitchDelta,
355
+ pinchAround
356
+ } = combinedResult;
357
+ let {
358
+ around
359
+ } = combinedResult;
360
+ if (pinchAround !== undefined) {
361
+ around = pinchAround;
362
+ }
363
+
364
+ // stop any ongoing camera animations (easeTo, flyTo)
365
+ map._stop(true);
366
+ around = around || map.transform.centerPoint;
367
+ const loc = tr.pointLocation(panDelta ? around.sub(panDelta) : around);
368
+ if (bearingDelta) tr.bearing += bearingDelta;
369
+ if (pitchDelta) tr.pitch += pitchDelta;
370
+ if (zoomDelta) tr.zoom += zoomDelta;
371
+ tr.setLocationAtPoint(loc, around);
372
+ map._applyUpdatedTransform(tr);
373
+ this._map._update();
374
+ if (!combinedResult.noInertia) this._inertia.record(combinedResult);
375
+ this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);
376
+ }
377
+ _fireEvents(newEventsInProgress, deactivatedHandlers, allowEndAnimation) {
378
+ const wasMoving = isMoving(this._eventsInProgress);
379
+ const nowMoving = isMoving(newEventsInProgress);
380
+ const startEvents = {};
381
+ for (const eventName in newEventsInProgress) {
382
+ const {
383
+ originalEvent
384
+ } = newEventsInProgress[eventName];
385
+ if (!this._eventsInProgress[eventName]) {
386
+ startEvents[`${eventName}start`] = originalEvent;
387
+ }
388
+ this._eventsInProgress[eventName] = newEventsInProgress[eventName];
389
+ }
390
+
391
+ // fire start events only after this._eventsInProgress has been updated
392
+ if (!wasMoving && nowMoving) {
393
+ this._fireEvent('movestart', nowMoving.originalEvent);
394
+ }
395
+ for (const name in startEvents) {
396
+ this._fireEvent(name, startEvents[name]);
397
+ }
398
+ if (nowMoving) {
399
+ this._fireEvent('move', nowMoving.originalEvent);
400
+ }
401
+ for (const eventName in newEventsInProgress) {
402
+ const {
403
+ originalEvent
404
+ } = newEventsInProgress[eventName];
405
+ this._fireEvent(eventName, originalEvent);
406
+ }
407
+ const endEvents = {};
408
+ let originalEndEvent;
409
+ for (const eventName in this._eventsInProgress) {
410
+ const {
411
+ handlerName,
412
+ originalEvent
413
+ } = this._eventsInProgress[eventName];
414
+ if (!this._handlersById[handlerName].isActive()) {
415
+ delete this._eventsInProgress[eventName];
416
+ originalEndEvent = deactivatedHandlers[handlerName] || originalEvent;
417
+ endEvents[`${eventName}end`] = originalEndEvent;
418
+ }
419
+ }
420
+ for (const name in endEvents) {
421
+ this._fireEvent(name, endEvents[name]);
422
+ }
423
+ const stillMoving = isMoving(this._eventsInProgress);
424
+ const finishedMoving = (wasMoving || nowMoving) && !stillMoving;
425
+ if (allowEndAnimation && finishedMoving) {
426
+ this._updatingCamera = true;
427
+ const inertialEase = this._inertia._onMoveEnd(this._map.dragPan._inertiaOptions);
428
+ const shouldSnapToNorth = bearing => bearing !== 0 && -this._bearingSnap < bearing && bearing < this._bearingSnap;
429
+ if (inertialEase && (inertialEase.essential || !browser.prefersReducedMotion)) {
430
+ if (shouldSnapToNorth(inertialEase.bearing || this._map.getBearing())) {
431
+ inertialEase.bearing = 0;
432
+ }
433
+ inertialEase.freezeElevation = true;
434
+ this._map.easeTo(inertialEase, {
435
+ originalEvent: originalEndEvent
436
+ });
437
+ } else {
438
+ this._map.fire(new Event('moveend', {
439
+ originalEvent: originalEndEvent
440
+ }));
441
+ if (shouldSnapToNorth(this._map.getBearing())) {
442
+ this._map.resetNorth();
443
+ }
444
+ }
445
+ this._updatingCamera = false;
446
+ }
447
+ }
448
+ _fireEvent(type, e) {
449
+ this._map.fire(new Event(type, e ? {
450
+ originalEvent: e
451
+ } : {}));
452
+ }
453
+ _requestFrame() {
454
+ this._map.triggerRepaint();
455
+ return this._map._renderTaskQueue.add(timeStamp => {
456
+ delete this._frameId;
457
+ this.handleEvent(new RenderFrameEvent('renderFrame', timeStamp));
458
+ this._applyChanges();
459
+ });
460
+ }
461
+ _triggerRenderFrame() {
462
+ if (this._frameId === undefined) {
463
+ this._frameId = this._requestFrame();
464
+ }
465
+ }
466
+ }