@antv/l7-map 2.9.37-alpha.2 → 2.9.37-alpha.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.
Files changed (168) hide show
  1. package/es/camera.d.ts +84 -0
  2. package/es/camera.js +767 -0
  3. package/es/css/l7.css +98 -0
  4. package/es/earthmap.d.ts +66 -0
  5. package/es/earthmap.js +422 -0
  6. package/es/geo/edge_insets.d.ts +54 -0
  7. package/es/geo/edge_insets.js +118 -0
  8. package/es/geo/lng_lat.d.ts +18 -0
  9. package/es/geo/lng_lat.js +81 -0
  10. package/es/geo/lng_lat_bounds.d.ts +24 -0
  11. package/es/geo/lng_lat_bounds.js +167 -0
  12. package/es/geo/mercator.d.ts +28 -0
  13. package/es/geo/mercator.js +91 -0
  14. package/es/geo/point.d.ts +40 -0
  15. package/es/geo/point.js +231 -0
  16. package/es/geo/simple.d.ts +29 -0
  17. package/es/geo/simple.js +92 -0
  18. package/es/geo/transform.d.ts +198 -0
  19. package/es/geo/transform.js +971 -0
  20. package/es/handler/IHandler.d.ts +34 -0
  21. package/es/handler/IHandler.js +1 -0
  22. package/es/handler/blockable_map_event.d.ts +17 -0
  23. package/es/handler/blockable_map_event.js +83 -0
  24. package/es/handler/box_zoom.d.ts +59 -0
  25. package/es/handler/box_zoom.js +200 -0
  26. package/es/handler/click_zoom.d.ts +16 -0
  27. package/es/handler/click_zoom.js +59 -0
  28. package/es/handler/events/event.d.ts +4 -0
  29. package/es/handler/events/event.js +12 -0
  30. package/es/handler/events/index.d.ts +4 -0
  31. package/es/handler/events/index.js +4 -0
  32. package/es/handler/events/map_mouse_event.d.ts +34 -0
  33. package/es/handler/events/map_mouse_event.js +75 -0
  34. package/es/handler/events/map_touch_event.d.ts +57 -0
  35. package/es/handler/events/map_touch_event.js +105 -0
  36. package/es/handler/events/map_wheel_event.d.ts +33 -0
  37. package/es/handler/events/map_wheel_event.js +61 -0
  38. package/es/handler/events/render_event.d.ts +5 -0
  39. package/es/handler/events/render_event.js +39 -0
  40. package/es/handler/handler_inertia.d.ts +23 -0
  41. package/es/handler/handler_inertia.js +184 -0
  42. package/es/handler/handler_manager.d.ts +61 -0
  43. package/es/handler/handler_manager.js +684 -0
  44. package/es/handler/handler_util.d.ts +4 -0
  45. package/es/handler/handler_util.js +10 -0
  46. package/es/handler/keyboard.d.ts +36 -0
  47. package/es/handler/keyboard.js +162 -0
  48. package/es/handler/map_event.d.ts +29 -0
  49. package/es/handler/map_event.js +131 -0
  50. package/es/handler/mouse/index.d.ts +4 -0
  51. package/es/handler/mouse/index.js +4 -0
  52. package/es/handler/mouse/mouse_handler.d.ts +22 -0
  53. package/es/handler/mouse/mouse_handler.js +131 -0
  54. package/es/handler/mouse/mousepan_handler.d.ts +10 -0
  55. package/es/handler/mouse/mousepan_handler.js +54 -0
  56. package/es/handler/mouse/mousepitch_hander.d.ts +9 -0
  57. package/es/handler/mouse/mousepitch_hander.js +56 -0
  58. package/es/handler/mouse/mouserotate_hander.d.ts +9 -0
  59. package/es/handler/mouse/mouserotate_hander.js +56 -0
  60. package/es/handler/mouse/util.d.ts +6 -0
  61. package/es/handler/mouse/util.js +12 -0
  62. package/es/handler/scroll_zoom.d.ts +93 -0
  63. package/es/handler/scroll_zoom.js +353 -0
  64. package/es/handler/shim/dblclick_zoom.d.ts +40 -0
  65. package/es/handler/shim/dblclick_zoom.js +72 -0
  66. package/es/handler/shim/drag_pan.d.ts +61 -0
  67. package/es/handler/shim/drag_pan.js +96 -0
  68. package/es/handler/shim/drag_rotate.d.ts +46 -0
  69. package/es/handler/shim/drag_rotate.js +80 -0
  70. package/es/handler/shim/touch_zoom_rotate.d.ts +70 -0
  71. package/es/handler/shim/touch_zoom_rotate.js +130 -0
  72. package/es/handler/tap/single_tap_recognizer.d.ts +20 -0
  73. package/es/handler/tap/single_tap_recognizer.js +120 -0
  74. package/es/handler/tap/tap_drag_zoom.d.ts +22 -0
  75. package/es/handler/tap/tap_drag_zoom.js +114 -0
  76. package/es/handler/tap/tap_recognizer.d.ts +17 -0
  77. package/es/handler/tap/tap_recognizer.js +62 -0
  78. package/es/handler/tap/tap_zoom.d.ts +22 -0
  79. package/es/handler/tap/tap_zoom.js +115 -0
  80. package/es/handler/touch/index.d.ts +5 -0
  81. package/es/handler/touch/index.js +5 -0
  82. package/es/handler/touch/touch_pan.d.ts +30 -0
  83. package/es/handler/touch/touch_pan.js +128 -0
  84. package/es/handler/touch/touch_pitch.d.ts +13 -0
  85. package/es/handler/touch/touch_pitch.js +110 -0
  86. package/es/handler/touch/touch_rotate.d.ts +12 -0
  87. package/es/handler/touch/touch_rotate.js +88 -0
  88. package/es/handler/touch/touch_zoom.d.ts +12 -0
  89. package/es/handler/touch/touch_zoom.js +67 -0
  90. package/es/handler/touch/two_touch.d.ts +23 -0
  91. package/es/handler/touch/two_touch.js +138 -0
  92. package/es/hash.d.ts +14 -0
  93. package/es/hash.js +156 -0
  94. package/es/index.d.ts +3 -0
  95. package/es/index.js +3 -0
  96. package/es/interface.d.ts +34 -0
  97. package/es/interface.js +1 -0
  98. package/es/map.d.ts +70 -0
  99. package/es/map.js +464 -0
  100. package/es/util.d.ts +18 -0
  101. package/es/util.js +84 -0
  102. package/es/utils/Aabb.d.ts +12 -0
  103. package/es/utils/Aabb.js +133 -0
  104. package/es/utils/dom.d.ts +4 -0
  105. package/es/utils/dom.js +218 -0
  106. package/es/utils/performance.d.ts +17 -0
  107. package/es/utils/performance.js +62 -0
  108. package/es/utils/primitives.d.ts +6 -0
  109. package/es/utils/primitives.js +45 -0
  110. package/es/utils/task_queue.d.ts +13 -0
  111. package/es/utils/task_queue.js +106 -0
  112. package/lib/camera.js +793 -0
  113. package/lib/css/l7.css +98 -0
  114. package/lib/earthmap.js +445 -0
  115. package/lib/geo/edge_insets.js +129 -0
  116. package/lib/geo/lng_lat.js +94 -0
  117. package/lib/geo/lng_lat_bounds.js +177 -0
  118. package/lib/geo/mercator.js +120 -0
  119. package/lib/geo/point.js +239 -0
  120. package/lib/geo/simple.js +123 -0
  121. package/lib/geo/transform.js +1013 -0
  122. package/lib/handler/IHandler.js +5 -0
  123. package/lib/handler/blockable_map_event.js +92 -0
  124. package/lib/handler/box_zoom.js +217 -0
  125. package/lib/handler/click_zoom.js +67 -0
  126. package/lib/handler/events/event.js +23 -0
  127. package/lib/handler/events/index.js +31 -0
  128. package/lib/handler/events/map_mouse_event.js +87 -0
  129. package/lib/handler/events/map_touch_event.js +119 -0
  130. package/lib/handler/events/map_wheel_event.js +72 -0
  131. package/lib/handler/events/render_event.js +52 -0
  132. package/lib/handler/handler_inertia.js +193 -0
  133. package/lib/handler/handler_manager.js +714 -0
  134. package/lib/handler/handler_util.js +17 -0
  135. package/lib/handler/keyboard.js +172 -0
  136. package/lib/handler/map_event.js +140 -0
  137. package/lib/handler/mouse/index.js +31 -0
  138. package/lib/handler/mouse/mouse_handler.js +141 -0
  139. package/lib/handler/mouse/mousepan_handler.js +66 -0
  140. package/lib/handler/mouse/mousepitch_hander.js +67 -0
  141. package/lib/handler/mouse/mouserotate_hander.js +67 -0
  142. package/lib/handler/mouse/util.js +26 -0
  143. package/lib/handler/scroll_zoom.js +367 -0
  144. package/lib/handler/shim/dblclick_zoom.js +80 -0
  145. package/lib/handler/shim/drag_pan.js +105 -0
  146. package/lib/handler/shim/drag_rotate.js +88 -0
  147. package/lib/handler/shim/touch_zoom_rotate.js +139 -0
  148. package/lib/handler/tap/single_tap_recognizer.js +131 -0
  149. package/lib/handler/tap/tap_drag_zoom.js +124 -0
  150. package/lib/handler/tap/tap_recognizer.js +78 -0
  151. package/lib/handler/tap/tap_zoom.js +124 -0
  152. package/lib/handler/touch/index.js +39 -0
  153. package/lib/handler/touch/touch_pan.js +138 -0
  154. package/lib/handler/touch/touch_pitch.js +120 -0
  155. package/lib/handler/touch/touch_rotate.js +99 -0
  156. package/lib/handler/touch/touch_zoom.js +78 -0
  157. package/lib/handler/touch/two_touch.js +148 -0
  158. package/lib/hash.js +169 -0
  159. package/lib/index.js +44 -0
  160. package/lib/interface.js +5 -0
  161. package/lib/map.js +489 -0
  162. package/lib/util.js +116 -0
  163. package/lib/utils/Aabb.js +143 -0
  164. package/lib/utils/dom.js +233 -0
  165. package/lib/utils/performance.js +72 -0
  166. package/lib/utils/primitives.js +57 -0
  167. package/lib/utils/task_queue.js +115 -0
  168. package/package.json +3 -3
package/es/camera.js ADDED
@@ -0,0 +1,767 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+
9
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+
11
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
+
13
+ // @ts-ignore
14
+ import { EventEmitter } from 'eventemitter3';
15
+ import { merge } from 'lodash';
16
+ import LngLat from "./geo/lng_lat";
17
+ import LngLatBounds from "./geo/lng_lat_bounds";
18
+ import Point from "./geo/point";
19
+ import Transform from "./geo/transform";
20
+ import { Event } from "./handler/events/event";
21
+ import { clamp, ease as defaultEasing, interpolate, now, pick, prefersReducedMotion, wrap } from "./util";
22
+
23
+ var Camera = /*#__PURE__*/function (_EventEmitter) {
24
+ _inherits(Camera, _EventEmitter);
25
+
26
+ var _super = _createSuper(Camera);
27
+
28
+ // public requestRenderFrame: (_: any) => number;
29
+ // public cancelRenderFrame: (_: number) => void;
30
+ function Camera(options) {
31
+ var _this;
32
+
33
+ _classCallCheck(this, Camera);
34
+
35
+ _this = _super.call(this);
36
+
37
+ _defineProperty(_assertThisInitialized(_this), "renderFrameCallback", function () {
38
+ var t = Math.min((now() - _this.easeStart) / _this.easeOptions.duration, 1);
39
+
40
+ _this.onEaseFrame(_this.easeOptions.easing(t));
41
+
42
+ if (t < 1) {
43
+ // this.easeFrameId = window.requestAnimationFrame(this.renderFrameCallback);
44
+ _this.easeFrameId = _this.requestRenderFrame(_this.renderFrameCallback);
45
+ } else {
46
+ _this.stop();
47
+ }
48
+ });
49
+
50
+ _this.options = options;
51
+ var minZoom = options.minZoom,
52
+ maxZoom = options.maxZoom,
53
+ minPitch = options.minPitch,
54
+ maxPitch = options.maxPitch,
55
+ renderWorldCopies = options.renderWorldCopies;
56
+ _this.moving = false;
57
+ _this.zooming = false;
58
+ _this.bearingSnap = options.bearingSnap;
59
+ _this.pitchEnabled = options.pitchEnabled;
60
+ _this.rotateEnabled = options.rotateEnabled;
61
+ _this.transform = new Transform(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies);
62
+ return _this;
63
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
64
+
65
+
66
+ _createClass(Camera, [{
67
+ key: "requestRenderFrame",
68
+ value: function requestRenderFrame(cb) {
69
+ return 0;
70
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
+
72
+ }, {
73
+ key: "cancelRenderFrame",
74
+ value: function cancelRenderFrame(_) {
75
+ return;
76
+ }
77
+ }, {
78
+ key: "getCenter",
79
+ value: function getCenter() {
80
+ var _this$transform$cente = this.transform.center,
81
+ lng = _this$transform$cente.lng,
82
+ lat = _this$transform$cente.lat;
83
+ return new LngLat(lng, lat);
84
+ }
85
+ }, {
86
+ key: "getZoom",
87
+ value: function getZoom() {
88
+ return this.transform.zoom;
89
+ }
90
+ }, {
91
+ key: "getPitch",
92
+ value: function getPitch() {
93
+ return this.transform.pitch;
94
+ }
95
+ }, {
96
+ key: "setCenter",
97
+ value: function setCenter(center, eventData) {
98
+ return this.jumpTo({
99
+ center: center
100
+ }, eventData);
101
+ }
102
+ }, {
103
+ key: "setPitch",
104
+ value: function setPitch(pitch, eventData) {
105
+ this.jumpTo({
106
+ pitch: pitch
107
+ }, eventData);
108
+ return this;
109
+ }
110
+ }, {
111
+ key: "getBearing",
112
+ value: function getBearing() {
113
+ return this.transform.bearing;
114
+ }
115
+ }, {
116
+ key: "panTo",
117
+ value: function panTo(lnglat, options, eventData) {
118
+ return this.easeTo(merge({
119
+ center: lnglat
120
+ }, options), eventData);
121
+ }
122
+ }, {
123
+ key: "zoomOut",
124
+ value: function zoomOut(options, eventData) {
125
+ this.zoomTo(this.getZoom() - 1, options, eventData);
126
+ return this;
127
+ }
128
+ }, {
129
+ key: "setBearing",
130
+ value: function setBearing(bearing, eventData) {
131
+ this.jumpTo({
132
+ bearing: bearing
133
+ }, eventData);
134
+ return this;
135
+ }
136
+ }, {
137
+ key: "setZoom",
138
+ value: function setZoom(zoom, eventData) {
139
+ this.jumpTo({
140
+ zoom: zoom
141
+ }, eventData);
142
+ return this;
143
+ }
144
+ }, {
145
+ key: "zoomIn",
146
+ value: function zoomIn(options, eventData) {
147
+ this.zoomTo(this.getZoom() + 1, options, eventData);
148
+ return this;
149
+ }
150
+ }, {
151
+ key: "zoomTo",
152
+ value: function zoomTo(zoom, options, eventData) {
153
+ return this.easeTo(merge({
154
+ zoom: zoom
155
+ }, options), eventData);
156
+ }
157
+ }, {
158
+ key: "getPadding",
159
+ value: function getPadding() {
160
+ return this.transform.padding;
161
+ }
162
+ }, {
163
+ key: "setPadding",
164
+ value: function setPadding(padding, eventData) {
165
+ this.jumpTo({
166
+ padding: padding
167
+ }, eventData);
168
+ return this;
169
+ }
170
+ }, {
171
+ key: "rotateTo",
172
+ value: function rotateTo(bearing, options, eventData) {
173
+ return this.easeTo(merge({
174
+ bearing: bearing
175
+ }, options), eventData);
176
+ }
177
+ }, {
178
+ key: "resetNorth",
179
+ value: function resetNorth(options, eventData) {
180
+ this.rotateTo(0, merge({
181
+ duration: 1000
182
+ }, options), eventData);
183
+ return this;
184
+ }
185
+ }, {
186
+ key: "resetNorthPitch",
187
+ value: function resetNorthPitch(options, eventData) {
188
+ this.easeTo(merge({
189
+ bearing: 0,
190
+ pitch: 0,
191
+ duration: 1000
192
+ }, options), eventData);
193
+ return this;
194
+ }
195
+ }, {
196
+ key: "fitBounds",
197
+ value: function fitBounds(bounds, options, eventData) {
198
+ return this.fitInternal( // @ts-ignore
199
+ this.cameraForBounds(bounds, options), options, eventData);
200
+ }
201
+ }, {
202
+ key: "cameraForBounds",
203
+ value: function cameraForBounds(bounds, options) {
204
+ bounds = LngLatBounds.convert(bounds);
205
+ return this.cameraForBoxAndBearing(bounds.getNorthWest(), bounds.getSouthEast(), 0, // @ts-ignore
206
+ options);
207
+ }
208
+ }, {
209
+ key: "snapToNorth",
210
+ value: function snapToNorth(options, eventData) {
211
+ if (Math.abs(this.getBearing()) < this.bearingSnap) {
212
+ return this.resetNorth(options, eventData);
213
+ }
214
+
215
+ return this;
216
+ }
217
+ }, {
218
+ key: "jumpTo",
219
+ value: function jumpTo() {
220
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
221
+ var eventData = arguments.length > 1 ? arguments[1] : undefined;
222
+ this.stop();
223
+ var tr = this.transform;
224
+ var zoomChanged = false;
225
+ var bearingChanged = false;
226
+ var pitchChanged = false;
227
+
228
+ if (options.zoom && tr.zoom !== +options.zoom) {
229
+ zoomChanged = true;
230
+ tr.zoom = +options.zoom;
231
+ }
232
+
233
+ if (options.center !== undefined) {
234
+ tr.center = LngLat.convert(options.center);
235
+ }
236
+
237
+ if (options.bearing && tr.bearing !== +options.bearing) {
238
+ bearingChanged = true;
239
+ tr.bearing = +options.bearing;
240
+ }
241
+
242
+ if (options.pitch && tr.pitch !== +options.pitch) {
243
+ pitchChanged = true;
244
+ tr.pitch = +options.pitch;
245
+ }
246
+
247
+ if (options.padding != null && !tr.isPaddingEqual(options.padding)) {
248
+ tr.padding = options.padding;
249
+ }
250
+
251
+ this.emit('movestart', new Event('movestart', eventData));
252
+ this.emit('move', new Event('move', eventData));
253
+
254
+ if (zoomChanged) {
255
+ this.emit('zoomstart', new Event('zoomstart', eventData));
256
+ this.emit('zoom', new Event('zoom', eventData));
257
+ this.emit('zoomend', new Event('zoomend', eventData));
258
+ }
259
+
260
+ if (bearingChanged) {
261
+ this.emit('rotatestart', new Event('rotatestart', eventData));
262
+ this.emit('rotate', new Event('rotate', eventData));
263
+ this.emit('rotateend', new Event('rotateend', eventData));
264
+ }
265
+
266
+ if (pitchChanged) {
267
+ this.emit('pitchstart', new Event('pitchstart', eventData));
268
+ this.emit('pitch', new Event('pitch', eventData));
269
+ this.emit('pitchend', new Event('pitchend', eventData));
270
+ }
271
+
272
+ return this.emit('moveend', new Event('moveend', eventData));
273
+ }
274
+ }, {
275
+ key: "easeTo",
276
+ value: function easeTo() {
277
+ var _this2 = this;
278
+
279
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
280
+ var eventData = arguments.length > 1 ? arguments[1] : undefined;
281
+ options = merge({
282
+ offset: [0, 0],
283
+ duration: 500,
284
+ easing: defaultEasing
285
+ }, options);
286
+
287
+ if (options.animate === false || !options.essential && prefersReducedMotion()) {
288
+ options.duration = 0;
289
+ }
290
+
291
+ var tr = this.transform;
292
+ var startZoom = this.getZoom();
293
+ var startBearing = this.getBearing();
294
+ var startPitch = this.getPitch();
295
+ var startPadding = this.getPadding();
296
+ var zoom = options.zoom ? +options.zoom : startZoom;
297
+ var bearing = options.bearing ? this.normalizeBearing(options.bearing, startBearing) : startBearing;
298
+ var pitch = options.pitch ? +options.pitch : startPitch;
299
+ var padding = options.padding ? options.padding : tr.padding;
300
+ var offsetAsPoint = Point.convert(options.offset);
301
+ var pointAtOffset = tr.centerPoint.add(offsetAsPoint);
302
+ var locationAtOffset = tr.pointLocation(pointAtOffset);
303
+ var center = LngLat.convert(options.center || locationAtOffset);
304
+ this.normalizeCenter(center);
305
+ var from = tr.project(locationAtOffset);
306
+ var delta = tr.project(center).sub(from);
307
+ var finalScale = tr.zoomScale(zoom - startZoom);
308
+ var around;
309
+ var aroundPoint;
310
+
311
+ if (options.around) {
312
+ around = LngLat.convert(options.around);
313
+ aroundPoint = tr.locationPoint(around);
314
+ }
315
+
316
+ var currently = {
317
+ moving: this.moving,
318
+ zooming: this.zooming,
319
+ rotating: this.rotating,
320
+ pitching: this.pitching
321
+ };
322
+ this.zooming = this.zooming || zoom !== startZoom;
323
+ this.rotating = this.rotating || startBearing !== bearing;
324
+ this.pitching = this.pitching || pitch !== startPitch;
325
+ this.padding = !tr.isPaddingEqual(padding);
326
+ this.easeId = options.easeId;
327
+ this.prepareEase(eventData, options.noMoveStart, currently);
328
+ clearTimeout(this.easeEndTimeoutID);
329
+ this.ease(function (k) {
330
+ if (_this2.zooming) {
331
+ tr.zoom = interpolate(startZoom, zoom, k);
332
+ }
333
+
334
+ if (_this2.rotating && _this2.rotateEnabled) {
335
+ tr.bearing = interpolate(startBearing, bearing, k);
336
+ }
337
+
338
+ if (_this2.pitching && _this2.pitchEnabled) {
339
+ tr.pitch = interpolate(startPitch, pitch, k);
340
+ }
341
+
342
+ if (_this2.padding) {
343
+ tr.interpolatePadding(startPadding, padding, k); // When padding is being applied, Transform#centerPoint is changing continously,
344
+ // thus we need to recalculate offsetPoint every fra,e
345
+
346
+ pointAtOffset = tr.centerPoint.add(offsetAsPoint);
347
+ }
348
+
349
+ if (around) {
350
+ tr.setLocationAtPoint(around, aroundPoint);
351
+ } else {
352
+ var scale = tr.zoomScale(tr.zoom - startZoom);
353
+ var base = zoom > startZoom ? Math.min(2, finalScale) : Math.max(0.5, finalScale);
354
+ var speedup = Math.pow(base, 1 - k);
355
+ var newCenter = tr.unproject(from.add(delta.mult(k * speedup)).mult(scale));
356
+ tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
357
+ }
358
+
359
+ _this2.fireMoveEvents(eventData);
360
+ }, function (interruptingEaseId) {
361
+ _this2.afterEase(eventData, interruptingEaseId);
362
+ }, // @ts-ignore
363
+ options);
364
+ return this;
365
+ }
366
+ }, {
367
+ key: "flyTo",
368
+ value: function flyTo() {
369
+ var _this3 = this;
370
+
371
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
372
+ var eventData = arguments.length > 1 ? arguments[1] : undefined;
373
+
374
+ // Fall through to jumpTo if user has set prefers-reduced-motion
375
+ if (!options.essential && prefersReducedMotion()) {
376
+ var coercedOptions = pick(options, ['center', 'zoom', 'bearing', 'pitch', 'around']);
377
+ return this.jumpTo(coercedOptions, eventData);
378
+ }
379
+
380
+ this.stop();
381
+ options = merge({
382
+ offset: [0, 0],
383
+ speed: 1.2,
384
+ curve: 1.42,
385
+ easing: defaultEasing
386
+ }, options);
387
+ var tr = this.transform;
388
+ var startZoom = this.getZoom();
389
+ var startBearing = this.getBearing();
390
+ var startPitch = this.getPitch();
391
+ var startPadding = this.getPadding();
392
+ var zoom = options.zoom ? clamp(+options.zoom, tr.minZoom, tr.maxZoom) : startZoom;
393
+ var bearing = options.bearing ? this.normalizeBearing(options.bearing, startBearing) : startBearing;
394
+ var pitch = options.pitch ? +options.pitch : startPitch;
395
+ var padding = 'padding' in options ? options.padding : tr.padding;
396
+ var scale = tr.zoomScale(zoom - startZoom);
397
+ var offsetAsPoint = Point.convert(options.offset);
398
+ var pointAtOffset = tr.centerPoint.add(offsetAsPoint);
399
+ var locationAtOffset = tr.pointLocation(pointAtOffset);
400
+ var center = LngLat.convert(options.center || locationAtOffset);
401
+ this.normalizeCenter(center);
402
+ var from = tr.project(locationAtOffset);
403
+ var delta = tr.project(center).sub(from);
404
+ var rho = options.curve; // w₀: Initial visible span, measured in pixels at the initial scale.
405
+
406
+ var w0 = Math.max(tr.width, tr.height); // w₁: Final visible span, measured in pixels with respect to the initial scale.
407
+
408
+ var w1 = w0 / scale; // Length of the flight path as projected onto the ground plane, measured in pixels from
409
+ // the world image origin at the initial scale.
410
+
411
+ var u1 = delta.mag();
412
+
413
+ if ('minZoom' in options) {
414
+ var minZoom = clamp(Math.min(options.minZoom, startZoom, zoom), tr.minZoom, tr.maxZoom); // w<sub>m</sub>: Maximum visible span, measured in pixels with respect to the initial
415
+ // scale.
416
+
417
+ var wMax = w0 / tr.zoomScale(minZoom - startZoom);
418
+ rho = Math.sqrt(wMax / u1 * 2);
419
+ } // ρ²
420
+
421
+
422
+ var rho2 = rho * rho;
423
+ /**
424
+ * rᵢ: Returns the zoom-out factor at one end of the animation.
425
+ *
426
+ * @param i 0 for the ascent or 1 for the descent.
427
+ * @private
428
+ */
429
+
430
+ function r(i) {
431
+ var b = (w1 * w1 - w0 * w0 + (i ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (i ? w1 : w0) * rho2 * u1);
432
+ return Math.log(Math.sqrt(b * b + 1) - b);
433
+ }
434
+
435
+ function sinh(n) {
436
+ return (Math.exp(n) - Math.exp(-n)) / 2;
437
+ }
438
+
439
+ function cosh(n) {
440
+ return (Math.exp(n) + Math.exp(-n)) / 2;
441
+ }
442
+
443
+ function tanh(n) {
444
+ return sinh(n) / cosh(n);
445
+ } // r₀: Zoom-out factor during ascent.
446
+
447
+
448
+ var r0 = r(0); // w(s): Returns the visible span on the ground, measured in pixels with respect to the
449
+ // initial scale. Assumes an angular field of view of 2 arctan ½ ≈ 53°.
450
+
451
+ var w = function w(s) {
452
+ return cosh(r0) / cosh(r0 + rho * s);
453
+ }; // u(s): Returns the distance along the flight path as projected onto the ground plane,
454
+ // measured in pixels from the world image origin at the initial scale.
455
+
456
+
457
+ var u = function u(s) {
458
+ return w0 * ((cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2) / u1;
459
+ }; // S: Total length of the flight path, measured in ρ-screenfuls.
460
+
461
+
462
+ var S = (r(1) - r0) / rho; // When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
463
+
464
+ if (Math.abs(u1) < 0.000001 || !isFinite(S)) {
465
+ // Perform a more or less instantaneous transition if the path is too short.
466
+ if (Math.abs(w0 - w1) < 0.000001) {
467
+ return this.easeTo(options, eventData);
468
+ }
469
+
470
+ var k = w1 < w0 ? -1 : 1;
471
+ S = Math.abs(Math.log(w1 / w0)) / rho;
472
+
473
+ u = function u() {
474
+ return 0;
475
+ };
476
+
477
+ w = function w(s) {
478
+ return Math.exp(k * rho * s);
479
+ };
480
+ }
481
+
482
+ if ('duration' in options) {
483
+ options.duration = +options.duration;
484
+ } else {
485
+ var V = 'screenSpeed' in options ? +options.screenSpeed / rho : +options.speed;
486
+ options.duration = 1000 * S / V;
487
+ }
488
+
489
+ if (options.maxDuration && options.duration > options.maxDuration) {
490
+ options.duration = 0;
491
+ }
492
+
493
+ this.zooming = true;
494
+ this.rotating = startBearing !== bearing;
495
+ this.pitching = pitch !== startPitch;
496
+ this.padding = !tr.isPaddingEqual(padding);
497
+ this.prepareEase(eventData, false);
498
+ this.ease(function (k) {
499
+ // s: The distance traveled along the flight path, measured in ρ-screenfuls.
500
+ var s = k * S; // @ts-ignore
501
+
502
+ var easeScale = 1 / w(s);
503
+ tr.zoom = k === 1 ? zoom : startZoom + tr.scaleZoom(easeScale);
504
+
505
+ if (_this3.rotating) {
506
+ tr.bearing = interpolate(startBearing, bearing, k);
507
+ }
508
+
509
+ if (_this3.pitching) {
510
+ tr.pitch = interpolate(startPitch, pitch, k);
511
+ }
512
+
513
+ if (_this3.padding) {
514
+ tr.interpolatePadding(startPadding, padding, k); // When padding is being applied, Transform#centerPoint is changing continously,
515
+ // thus we need to recalculate offsetPoint every frame
516
+
517
+ pointAtOffset = tr.centerPoint.add(offsetAsPoint);
518
+ }
519
+
520
+ var newCenter = k === 1 ? center : tr.unproject(from.add(delta.mult(u(s))).mult(easeScale));
521
+ tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
522
+
523
+ _this3.fireMoveEvents(eventData);
524
+ }, function () {
525
+ return _this3.afterEase(eventData);
526
+ }, options);
527
+ return this;
528
+ }
529
+ }, {
530
+ key: "fitScreenCoordinates",
531
+ value: function fitScreenCoordinates(p0, p1, bearing, options, eventData) {
532
+ return this.fitInternal( // @ts-ignore
533
+ this.cameraForBoxAndBearing(this.transform.pointLocation(Point.convert(p0)), this.transform.pointLocation(Point.convert(p1)), bearing, // @ts-ignore
534
+ options), options, eventData);
535
+ }
536
+ }, {
537
+ key: "stop",
538
+ value: function stop(allowGestures, easeId) {
539
+ if (this.easeFrameId) {
540
+ this.cancelRenderFrame(this.easeFrameId); // @ts-ignore
541
+
542
+ delete this.easeFrameId; // @ts-ignore
543
+
544
+ delete this.onEaseFrame;
545
+ }
546
+
547
+ if (this.onEaseEnd) {
548
+ // The _onEaseEnd function might emit events which trigger new
549
+ // animation, which sets a new _onEaseEnd. Ensure we don't delete
550
+ // it unintentionally.
551
+ var onEaseEnd = this.onEaseEnd; // @ts-ignore
552
+
553
+ delete this.onEaseEnd;
554
+ onEaseEnd.call(this, easeId);
555
+ } // if (!allowGestures) {
556
+ // const handlers = (this: any).handlers;
557
+ // if (handlers) handlers.stop();
558
+ // }
559
+
560
+
561
+ return this;
562
+ }
563
+ }, {
564
+ key: "normalizeBearing",
565
+ value: function normalizeBearing(bearing, currentBearing) {
566
+ bearing = wrap(bearing, -180, 180);
567
+ var diff = Math.abs(bearing - currentBearing);
568
+
569
+ if (Math.abs(bearing - 360 - currentBearing) < diff) {
570
+ bearing -= 360;
571
+ }
572
+
573
+ if (Math.abs(bearing + 360 - currentBearing) < diff) {
574
+ bearing += 360;
575
+ }
576
+
577
+ return bearing;
578
+ }
579
+ }, {
580
+ key: "normalizeCenter",
581
+ value: function normalizeCenter(center) {
582
+ var tr = this.transform;
583
+
584
+ if (!tr.renderWorldCopies || tr.lngRange) {
585
+ return;
586
+ }
587
+
588
+ var delta = center.lng - tr.center.lng;
589
+ center.lng += delta > 180 ? -360 : delta < -180 ? 360 : 0;
590
+ }
591
+ }, {
592
+ key: "fireMoveEvents",
593
+ value: function fireMoveEvents(eventData) {
594
+ this.emit('move', new Event('move', eventData));
595
+
596
+ if (this.zooming) {
597
+ this.emit('zoom', new Event('zoom', eventData));
598
+ }
599
+
600
+ if (this.rotating) {
601
+ this.emit('rotate', new Event('rotate', eventData));
602
+ }
603
+
604
+ if (this.pitching) {
605
+ this.emit('rotate', new Event('pitch', eventData));
606
+ }
607
+ }
608
+ }, {
609
+ key: "prepareEase",
610
+ value: function prepareEase(eventData) {
611
+ var noMoveStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
612
+ var currently = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
613
+ this.moving = true;
614
+
615
+ if (!noMoveStart && !currently.moving) {
616
+ this.emit('movestart', new Event('movestart', eventData));
617
+ }
618
+
619
+ if (this.zooming && !currently.zooming) {
620
+ this.emit('zoomstart', new Event('zoomstart', eventData));
621
+ }
622
+
623
+ if (this.rotating && !currently.rotating) {
624
+ this.emit('rotatestart', new Event('rotatestart', eventData));
625
+ }
626
+
627
+ if (this.pitching && !currently.pitching) {
628
+ this.emit('pitchstart', new Event('pitchstart', eventData));
629
+ }
630
+ }
631
+ }, {
632
+ key: "afterEase",
633
+ value: function afterEase(eventData, easeId) {
634
+ // if this easing is being stopped to start another easing with
635
+ // the same id then don't fire any events to avoid extra start/stop events
636
+ if (this.easeId && easeId && this.easeId === easeId) {
637
+ return;
638
+ } // @ts-ignore
639
+
640
+
641
+ delete this.easeId;
642
+ var wasZooming = this.zooming;
643
+ var wasRotating = this.rotating;
644
+ var wasPitching = this.pitching;
645
+ this.moving = false;
646
+ this.zooming = false;
647
+ this.rotating = false;
648
+ this.pitching = false;
649
+ this.padding = false;
650
+
651
+ if (wasZooming) {
652
+ this.emit('zoomend', new Event('zoomend', eventData));
653
+ }
654
+
655
+ if (wasRotating) {
656
+ this.emit('rotateend', new Event('rotateend', eventData));
657
+ }
658
+
659
+ if (wasPitching) {
660
+ this.emit('pitchend', new Event('pitchend', eventData));
661
+ }
662
+
663
+ this.emit('moveend', new Event('moveend', eventData));
664
+ }
665
+ }, {
666
+ key: "ease",
667
+ value: function ease(frame, finish, options) {
668
+ if (options.animate === false || options.duration === 0) {
669
+ frame(1);
670
+ finish();
671
+ } else {
672
+ this.easeStart = now();
673
+ this.easeOptions = options;
674
+ this.onEaseFrame = frame;
675
+ this.onEaseEnd = finish;
676
+ this.easeFrameId = this.requestRenderFrame(this.renderFrameCallback);
677
+ }
678
+ }
679
+ }, {
680
+ key: "cameraForBoxAndBearing",
681
+ value: function cameraForBoxAndBearing(p0, p1, bearing, options) {
682
+ var defaultPadding = {
683
+ top: 0,
684
+ bottom: 0,
685
+ right: 0,
686
+ left: 0
687
+ };
688
+ options = merge({
689
+ padding: defaultPadding,
690
+ offset: [0, 0],
691
+ maxZoom: this.transform.maxZoom
692
+ }, options);
693
+
694
+ if (typeof options.padding === 'number') {
695
+ var p = options.padding;
696
+ options.padding = {
697
+ top: p,
698
+ bottom: p,
699
+ right: p,
700
+ left: p
701
+ };
702
+ }
703
+
704
+ options.padding = merge(defaultPadding, options.padding);
705
+ var tr = this.transform;
706
+ var edgePadding = tr.padding; // We want to calculate the upper right and lower left of the box defined by p0 and p1
707
+ // in a coordinate system rotate to match the destination bearing.
708
+
709
+ var p0world = tr.project(LngLat.convert(p0));
710
+ var p1world = tr.project(LngLat.convert(p1));
711
+ var p0rotated = p0world.rotate(-bearing * Math.PI / 180);
712
+ var p1rotated = p1world.rotate(-bearing * Math.PI / 180);
713
+ var upperRight = new Point(Math.max(p0rotated.x, p1rotated.x), Math.max(p0rotated.y, p1rotated.y));
714
+ var lowerLeft = new Point(Math.min(p0rotated.x, p1rotated.x), Math.min(p0rotated.y, p1rotated.y)); // Calculate zoom: consider the original bbox and padding.
715
+
716
+ var size = upperRight.sub(lowerLeft);
717
+ var scaleX = (tr.width - ( // @ts-ignore
718
+ edgePadding.left + // @ts-ignore
719
+ edgePadding.right + // @ts-ignore
720
+ options.padding.left + // @ts-ignore
721
+ options.padding.right)) / size.x;
722
+ var scaleY = (tr.height - ( // @ts-ignore
723
+ edgePadding.top + // @ts-ignore
724
+ edgePadding.bottom + // @ts-ignore
725
+ options.padding.top + // @ts-ignore
726
+ options.padding.bottom)) / size.y;
727
+
728
+ if (scaleY < 0 || scaleX < 0) {
729
+ return;
730
+ }
731
+
732
+ var zoom = Math.min(tr.scaleZoom(tr.scale * Math.min(scaleX, scaleY)), options.maxZoom); // Calculate center: apply the zoom, the configured offset, as well as offset that exists as a result of padding.
733
+
734
+ var offset = Point.convert(options.offset); // @ts-ignore
735
+
736
+ var paddingOffsetX = (options.padding.left - options.padding.right) / 2; // @ts-ignore
737
+
738
+ var paddingOffsetY = (options.padding.top - options.padding.bottom) / 2;
739
+ var offsetAtInitialZoom = new Point(offset.x + paddingOffsetX, offset.y + paddingOffsetY);
740
+ var offsetAtFinalZoom = offsetAtInitialZoom.mult(tr.scale / tr.zoomScale(zoom));
741
+ var center = tr.unproject(p0world.add(p1world).div(2).sub(offsetAtFinalZoom));
742
+ return {
743
+ center: center,
744
+ zoom: zoom,
745
+ bearing: bearing
746
+ };
747
+ }
748
+ }, {
749
+ key: "fitInternal",
750
+ value: function fitInternal(calculatedOptions, options, eventData) {
751
+ // cameraForBounds warns + returns undefined if unable to fit:
752
+ if (!calculatedOptions) {
753
+ return this;
754
+ }
755
+
756
+ options = merge(calculatedOptions, options); // Explictly remove the padding field because, calculatedOptions already accounts for padding by setting zoom and center accordingly.
757
+
758
+ delete options.padding; // @ts-ignore
759
+
760
+ return options.linear ? this.easeTo(options, eventData) : this.flyTo(options, eventData);
761
+ }
762
+ }]);
763
+
764
+ return Camera;
765
+ }(EventEmitter);
766
+
767
+ export { Camera as default };