@antv/l7-map 2.17.4 → 2.17.6

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