@antv/l7-map 2.15.5 → 2.16.1

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