@antv/l7-map 2.17.2 → 2.17.4

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 +26 -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 +38 -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
@@ -1,8 +1,12 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+
3
4
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
5
+
4
6
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
9
+
6
10
  // @ts-ignore
7
11
  import { isMini } from '@antv/l7-utils';
8
12
  import { mat2, mat4, vec4 } from 'gl-matrix';
@@ -13,10 +17,13 @@ import LngLat from "./lng_lat";
13
17
  import LngLatBounds from "./lng_lat_bounds";
14
18
  import MercatorCoordinate, { mercatorXfromLng, mercatorYfromLat, mercatorZfromAltitude } from "./mercator";
15
19
  export var EXTENT = 8192;
20
+
16
21
  var Transform = /*#__PURE__*/function () {
17
22
  function Transform(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies) {
18
23
  _classCallCheck(this, Transform);
24
+
19
25
  this.tileSize = 512; // constant
26
+
20
27
  this.maxValidLatitude = 85.051129; // constant
21
28
 
22
29
  this._renderWorldCopies = renderWorldCopies === undefined ? true : renderWorldCopies;
@@ -37,6 +44,7 @@ var Transform = /*#__PURE__*/function () {
37
44
  this.posMatrixCache = {};
38
45
  this.alignedPosMatrixCache = {};
39
46
  }
47
+
40
48
  _createClass(Transform, [{
41
49
  key: "minZoom",
42
50
  get: function get() {
@@ -46,6 +54,7 @@ var Transform = /*#__PURE__*/function () {
46
54
  if (this._minZoom === zoom) {
47
55
  return;
48
56
  }
57
+
49
58
  this._minZoom = zoom;
50
59
  this.zoom = Math.max(this.zoom, zoom);
51
60
  }
@@ -58,6 +67,7 @@ var Transform = /*#__PURE__*/function () {
58
67
  if (this._maxZoom === zoom) {
59
68
  return;
60
69
  }
70
+
61
71
  this._maxZoom = zoom;
62
72
  this.zoom = Math.min(this.zoom, zoom);
63
73
  }
@@ -70,6 +80,7 @@ var Transform = /*#__PURE__*/function () {
70
80
  if (this._minPitch === pitch) {
71
81
  return;
72
82
  }
83
+
73
84
  this._minPitch = pitch;
74
85
  this._pitch = Math.max(this._pitch, pitch);
75
86
  }
@@ -82,6 +93,7 @@ var Transform = /*#__PURE__*/function () {
82
93
  if (this._maxPitch === pitch) {
83
94
  return;
84
95
  }
96
+
85
97
  this._maxPitch = pitch;
86
98
  this._pitch = Math.min(this._pitch, pitch);
87
99
  }
@@ -96,6 +108,7 @@ var Transform = /*#__PURE__*/function () {
96
108
  } else if (renderWorldCopies === null) {
97
109
  renderWorldCopies = false;
98
110
  }
111
+
99
112
  this._renderWorldCopies = renderWorldCopies;
100
113
  }
101
114
  }, {
@@ -120,14 +133,15 @@ var Transform = /*#__PURE__*/function () {
120
133
  },
121
134
  set: function set(bearing) {
122
135
  var b = -wrap(bearing, -180, 180) * Math.PI / 180;
136
+
123
137
  if (this.angle === b) {
124
138
  return;
125
139
  }
140
+
126
141
  this.unmodified = false;
127
142
  this.angle = b;
128
- this.calcMatrices();
143
+ this.calcMatrices(); // 2x2 matrix for rotating points
129
144
 
130
- // 2x2 matrix for rotating points
131
145
  this.rotationMatrix = mat2.create();
132
146
  mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);
133
147
  }
@@ -138,9 +152,11 @@ var Transform = /*#__PURE__*/function () {
138
152
  },
139
153
  set: function set(pitch) {
140
154
  var p = clamp(pitch, this._minPitch, this._maxPitch) / 180 * Math.PI;
155
+
141
156
  if (this._pitch === p) {
142
157
  return;
143
158
  }
159
+
144
160
  this.unmodified = false;
145
161
  this._pitch = p;
146
162
  this.calcMatrices();
@@ -152,9 +168,11 @@ var Transform = /*#__PURE__*/function () {
152
168
  },
153
169
  set: function set(fov) {
154
170
  fov = Math.max(0.01, Math.min(60, fov));
171
+
155
172
  if (this._fov === fov) {
156
173
  return;
157
174
  }
175
+
158
176
  this.unmodified = false;
159
177
  this._fov = fov / 180 * Math.PI;
160
178
  this.calcMatrices();
@@ -166,9 +184,11 @@ var Transform = /*#__PURE__*/function () {
166
184
  },
167
185
  set: function set(zoom) {
168
186
  var z = Math.min(Math.max(zoom, this._minZoom), this._maxZoom);
187
+
169
188
  if (this._zoom === z) {
170
189
  return;
171
190
  }
191
+
172
192
  this.unmodified = false;
173
193
  this._zoom = z;
174
194
  this.scale = this.zoomScale(z);
@@ -186,6 +206,7 @@ var Transform = /*#__PURE__*/function () {
186
206
  if (center.lat === this._center.lat && center.lng === this._center.lng) {
187
207
  return;
188
208
  }
209
+
189
210
  this.unmodified = false;
190
211
  this._center = center;
191
212
  this.constrain();
@@ -200,12 +221,12 @@ var Transform = /*#__PURE__*/function () {
200
221
  if (this.edgeInsets.equals(padding)) {
201
222
  return;
202
223
  }
203
- this.unmodified = false;
204
- // Update edge-insets inplace
224
+
225
+ this.unmodified = false; // Update edge-insets inplace
226
+
205
227
  this.edgeInsets.interpolate(this.edgeInsets, padding, 1);
206
228
  this.calcMatrices();
207
229
  }
208
-
209
230
  /**
210
231
  * The center of the screen in pixels with the top-left corner being (0,0)
211
232
  * and +y axis pointing downwards. This accounts for padding.
@@ -214,6 +235,7 @@ var Transform = /*#__PURE__*/function () {
214
235
  * @type {Point}
215
236
  * @memberof Transform
216
237
  */
238
+
217
239
  }, {
218
240
  key: "centerPoint",
219
241
  get: function get() {
@@ -242,7 +264,6 @@ var Transform = /*#__PURE__*/function () {
242
264
  clone.calcMatrices();
243
265
  return clone;
244
266
  }
245
-
246
267
  /**
247
268
  * Returns if the padding params match
248
269
  *
@@ -250,12 +271,12 @@ var Transform = /*#__PURE__*/function () {
250
271
  * @returns {boolean}
251
272
  * @memberof Transform
252
273
  */
274
+
253
275
  }, {
254
276
  key: "isPaddingEqual",
255
277
  value: function isPaddingEqual(padding) {
256
278
  return this.edgeInsets.equals(padding);
257
279
  }
258
-
259
280
  /**
260
281
  * Helper method to upadte edge-insets inplace
261
282
  *
@@ -263,6 +284,7 @@ var Transform = /*#__PURE__*/function () {
263
284
  * @param {number} t
264
285
  * @memberof Transform
265
286
  */
287
+
266
288
  }, {
267
289
  key: "interpolatePadding",
268
290
  value: function interpolatePadding(start, target, t) {
@@ -271,7 +293,6 @@ var Transform = /*#__PURE__*/function () {
271
293
  this.constrain();
272
294
  this.calcMatrices();
273
295
  }
274
-
275
296
  /**
276
297
  * Return a zoom level that will cover all tiles the transform
277
298
  * @param {Object} options options
@@ -279,14 +300,14 @@ var Transform = /*#__PURE__*/function () {
279
300
  * @param {boolean} options.roundZoom Target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored.
280
301
  * @returns {number} zoom level An integer zoom level at which all tiles will be visible.
281
302
  */
303
+
282
304
  }, {
283
305
  key: "coveringZoomLevel",
284
306
  value: function coveringZoomLevel(options) {
285
- var z = (options.roundZoom ? Math.round : Math.floor)(this.zoom + this.scaleZoom(this.tileSize / options.tileSize));
286
- // At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.
307
+ var z = (options.roundZoom ? Math.round : Math.floor)(this.zoom + this.scaleZoom(this.tileSize / options.tileSize)); // At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.
308
+
287
309
  return Math.max(0, z);
288
310
  }
289
-
290
311
  /**
291
312
  * Return any "wrapped" copies of a given tile coordinate that are visible
292
313
  * in the current view.
@@ -302,12 +323,10 @@ var Transform = /*#__PURE__*/function () {
302
323
  // const ubr = this.pointCoordinate(new Point(0, this.height));
303
324
  // const w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));
304
325
  // const w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));
305
-
306
326
  // // Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.
307
327
  // // Both sources draw outside the tile boundaries of the tile that "contains them" so we need
308
328
  // // to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.
309
329
  // const extraWorldCopy = 1;
310
-
311
330
  // for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {
312
331
  // if (w === 0) {
313
332
  // continue;
@@ -341,14 +360,12 @@ var Transform = /*#__PURE__*/function () {
341
360
  // }): OverscaledTileID[] {
342
361
  // let z = this.coveringZoomLevel(options);
343
362
  // const actualZ = z;
344
-
345
363
  // if (options.minzoom !== undefined && z < options.minzoom) {
346
364
  // return [];
347
365
  // }
348
366
  // if (options.maxzoom !== undefined && z > options.maxzoom) {
349
367
  // z = options.maxzoom;
350
368
  // }
351
-
352
369
  // const centerCoord = MercatorCoordinate.fromLngLat(this.center);
353
370
  // const numTiles = Math.pow(2, z);
354
371
  // const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0];
@@ -357,17 +374,14 @@ var Transform = /*#__PURE__*/function () {
357
374
  // this.worldSize,
358
375
  // z,
359
376
  // );
360
-
361
377
  // // No change of LOD behavior for pitch lower than 60 and when there is no top padding: return only tile ids from the requested zoom level
362
378
  // let minZoom = options.minzoom || 0;
363
379
  // // Use 0.1 as an epsilon to avoid for explicit == 0.0 floating point checks
364
380
  // if (this._pitch <= 60.0 && this.edgeInsets.top < 0.1) {
365
381
  // minZoom = z;
366
382
  // }
367
-
368
383
  // // There should always be a certain number of maximum zoom level tiles surrounding the center location
369
384
  // const radiusOfMaxLvlLodInTiles = 3;
370
-
371
385
  // const newRootTile = (wrap: number): any => {
372
386
  // return {
373
387
  // // All tiles are on zero elevation plane => z difference is zero
@@ -382,13 +396,11 @@ var Transform = /*#__PURE__*/function () {
382
396
  // fullyVisible: false,
383
397
  // };
384
398
  // };
385
-
386
399
  // // Do a depth-first traversal to find visible tiles and proper levels of detail
387
400
  // const stack = [];
388
401
  // const result = [];
389
402
  // const maxZoom = z;
390
403
  // const overscaledZ = options.reparseOverscaled ? actualZ : z;
391
-
392
404
  // if (this._renderWorldCopies) {
393
405
  // // Render copy of the globe thrice on both sides
394
406
  // for (let i = 1; i <= 3; i++) {
@@ -396,30 +408,23 @@ var Transform = /*#__PURE__*/function () {
396
408
  // stack.push(newRootTile(i));
397
409
  // }
398
410
  // }
399
-
400
411
  // stack.push(newRootTile(0));
401
-
402
412
  // while (stack.length > 0) {
403
413
  // const it = stack.pop();
404
414
  // const x = it.x;
405
415
  // const y = it.y;
406
416
  // let fullyVisible = it.fullyVisible;
407
-
408
417
  // // Visibility of a tile is not required if any of its ancestor if fully inside the frustum
409
418
  // if (!fullyVisible) {
410
419
  // const intersectResult = it.aabb.intersects(cameraFrustum);
411
-
412
420
  // if (intersectResult === 0) {
413
421
  // continue;
414
422
  // }
415
-
416
423
  // fullyVisible = intersectResult === 2;
417
424
  // }
418
-
419
425
  // const distanceX = it.aabb.distanceX(centerPoint);
420
426
  // const distanceY = it.aabb.distanceY(centerPoint);
421
427
  // const longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));
422
-
423
428
  // // We're using distance based heuristics to determine if a tile should be split into quadrants or not.
424
429
  // // radiusOfMaxLvlLodInTiles defines that there's always a certain number of maxLevel tiles next to the map center.
425
430
  // // Using the fact that a parent node in quadtree is twice the size of its children (per dimension)
@@ -427,7 +432,6 @@ var Transform = /*#__PURE__*/function () {
427
432
  // // f(k) = offset + 2 + 4 + 8 + 16 + ... + 2^k. This is the same as "offset+2^(k+1)-2"
428
433
  // const distToSplit =
429
434
  // radiusOfMaxLvlLodInTiles + (1 << (maxZoom - it.zoom)) - 2;
430
-
431
435
  // // Have we reached the target depth or is the tile too far away to be any split further?
432
436
  // if (
433
437
  // it.zoom === maxZoom ||
@@ -448,11 +452,9 @@ var Transform = /*#__PURE__*/function () {
448
452
  // });
449
453
  // continue;
450
454
  // }
451
-
452
455
  // for (let i = 0; i < 4; i++) {
453
456
  // const childX = (x << 1) + (i % 2);
454
457
  // const childY = (y << 1) + (i >> 1);
455
-
456
458
  // stack.push({
457
459
  // aabb: it.aabb.quadrant(i),
458
460
  // zoom: it.zoom + 1,
@@ -463,11 +465,11 @@ var Transform = /*#__PURE__*/function () {
463
465
  // });
464
466
  // }
465
467
  // }
466
-
467
468
  // return result
468
469
  // .sort((a, b) => a.distanceSq - b.distanceSq)
469
470
  // .map((a) => a.tileID);
470
471
  // }
472
+
471
473
  }, {
472
474
  key: "resize",
473
475
  value: function resize(width, height) {
@@ -506,6 +508,7 @@ var Transform = /*#__PURE__*/function () {
506
508
  var loc = this.locationCoordinate(lnglat);
507
509
  var newCenter = new MercatorCoordinate(loc.x - (a.x - b.x), loc.y - (a.y - b.y));
508
510
  this.center = this.coordinateLocation(newCenter);
511
+
509
512
  if (this._renderWorldCopies) {
510
513
  this.center = this.center.wrap();
511
514
  }
@@ -513,17 +516,15 @@ var Transform = /*#__PURE__*/function () {
513
516
  }, {
514
517
  key: "pointCoordinate",
515
518
  value: function pointCoordinate(p) {
516
- var targetZ = 0;
517
- // since we don't know the correct projected z value for the point,
519
+ var targetZ = 0; // since we don't know the correct projected z value for the point,
518
520
  // unproject two points to get a line and then find the point on that
519
521
  // line with z=0
520
522
 
521
523
  var coord0 = new Float64Array([p.x, p.y, 0, 1]);
522
- var coord1 = new Float64Array([p.x, p.y, 1, 1]);
524
+ var coord1 = new Float64Array([p.x, p.y, 1, 1]); // @ts-ignore
525
+
526
+ vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse); // @ts-ignore
523
527
 
524
- // @ts-ignore
525
- vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);
526
- // @ts-ignore
527
528
  vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);
528
529
  var w0 = coord0[3];
529
530
  var w1 = coord1[3];
@@ -536,35 +537,36 @@ var Transform = /*#__PURE__*/function () {
536
537
  var t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);
537
538
  return new MercatorCoordinate(interpolate(x0, x1, t) / this.worldSize, interpolate(y0, y1, t) / this.worldSize);
538
539
  }
539
-
540
540
  /**
541
541
  * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
542
542
  * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
543
543
  * @returns {LngLatBounds} Returns a {@link LngLatBounds} object describing the map's geographical bounds.
544
544
  */
545
+
545
546
  }, {
546
547
  key: "getBounds",
547
548
  value: function getBounds() {
548
549
  return new LngLatBounds().extend(this.pointLocation(new Point(0, 0))).extend(this.pointLocation(new Point(this.width, 0))).extend(this.pointLocation(new Point(this.width, this.height))).extend(this.pointLocation(new Point(0, this.height)));
549
550
  }
550
-
551
551
  /**
552
552
  * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
553
553
  * @returns {LngLatBounds} {@link LngLatBounds}
554
554
  */
555
+
555
556
  }, {
556
557
  key: "getMaxBounds",
557
558
  value: function getMaxBounds() {
558
559
  if (!this.latRange || this.latRange.length !== 2 || !this.lngRange || this.lngRange.length !== 2) {
559
560
  return null;
560
561
  }
562
+
561
563
  return new LngLatBounds([this.lngRange[0], this.latRange[0]], [this.lngRange[1], this.latRange[1]]);
562
564
  }
563
-
564
565
  /**
565
566
  * Sets or clears the map's geographical constraints.
566
567
  * @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.
567
568
  */
569
+
568
570
  }, {
569
571
  key: "setMaxBounds",
570
572
  value: function setMaxBounds(bounds) {
@@ -589,12 +591,12 @@ var Transform = /*#__PURE__*/function () {
589
591
  if (!this.pixelMatrixInverse) {
590
592
  return 1;
591
593
  }
594
+
592
595
  var coord = this.pointCoordinate(new Point(0, 0));
593
596
  var p = new Float32Array([coord.x * this.worldSize, coord.y * this.worldSize, 0, 1]);
594
597
  var topPoint = vec4.transformMat4(p, p, this.pixelMatrix);
595
598
  return topPoint[3] / this.cameraToCenterDistance;
596
599
  }
597
-
598
600
  /*
599
601
  * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`
600
602
  * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).
@@ -606,6 +608,7 @@ var Transform = /*#__PURE__*/function () {
606
608
  * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because
607
609
  * the camera is right above the center of the map.
608
610
  */
611
+
609
612
  }, {
610
613
  key: "getCameraPoint",
611
614
  value: function getCameraPoint() {
@@ -613,7 +616,6 @@ var Transform = /*#__PURE__*/function () {
613
616
  var yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);
614
617
  return this.centerPoint.add(new Point(0, yOffset));
615
618
  }
616
-
617
619
  /*
618
620
  * When the map is pitched, some of the 3D features that intersect a query will not intersect
619
621
  * the query at the surface of the earth. Instead the feature may be closer and only intersect
@@ -624,10 +626,12 @@ var Transform = /*#__PURE__*/function () {
624
626
  * - For point queries, the line from the query point to the "camera point"
625
627
  * - For other geometries, the envelope of the query geometry and the "camera point"
626
628
  */
629
+
627
630
  }, {
628
631
  key: "getCameraQueryGeometry",
629
632
  value: function getCameraQueryGeometry(queryGeometry) {
630
633
  var c = this.getCameraPoint();
634
+
631
635
  if (queryGeometry.length === 1) {
632
636
  return [queryGeometry[0], c];
633
637
  } else {
@@ -635,8 +639,10 @@ var Transform = /*#__PURE__*/function () {
635
639
  var minY = c.y;
636
640
  var maxX = c.x;
637
641
  var maxY = c.y;
642
+
638
643
  var _iterator = _createForOfIteratorHelper(queryGeometry),
639
- _step;
644
+ _step;
645
+
640
646
  try {
641
647
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
642
648
  var p = _step.value;
@@ -650,16 +656,17 @@ var Transform = /*#__PURE__*/function () {
650
656
  } finally {
651
657
  _iterator.f();
652
658
  }
659
+
653
660
  return [new Point(minX, minY), new Point(maxX, minY), new Point(maxX, maxY), new Point(minX, maxY), new Point(minX, minY)];
654
661
  }
655
662
  }
656
-
657
663
  /**
658
664
  * Given a coordinate, return the screen point that corresponds to it
659
665
  * @param {Coordinate} coord
660
666
  * @returns {Point} screen point
661
667
  * @private
662
668
  */
669
+
663
670
  }, {
664
671
  key: "coordinatePoint",
665
672
  value: function coordinatePoint(coord) {
@@ -673,28 +680,27 @@ var Transform = /*#__PURE__*/function () {
673
680
  * @returns {Point} screen point
674
681
  * @private
675
682
  */
683
+
676
684
  }, {
677
685
  key: "locationPoint",
678
686
  value: function locationPoint(lnglat) {
679
687
  return this.coordinatePoint(this.locationCoordinate(lnglat));
680
688
  }
681
-
682
689
  /**
683
690
  * Given a point on screen, return its lnglat
684
691
  * @param {Point} p screen point
685
692
  * @returns {LngLat} lnglat location
686
693
  * @private
687
694
  */
695
+
688
696
  }, {
689
697
  key: "pointLocation",
690
698
  value: function pointLocation(p) {
691
699
  // if(p.x !== 0 && p.x !== 1001) {
692
700
  // console.log(p.x)
693
701
  // }
694
-
695
702
  return this.coordinateLocation(this.pointCoordinate(p));
696
703
  }
697
-
698
704
  /**
699
705
  * Given a geographical lnglat, return an unrounded
700
706
  * coordinate that represents it at this transform's zoom level.
@@ -702,18 +708,19 @@ var Transform = /*#__PURE__*/function () {
702
708
  * @returns {Coordinate}
703
709
  * @private
704
710
  */
711
+
705
712
  }, {
706
713
  key: "locationCoordinate",
707
714
  value: function locationCoordinate(lnglat) {
708
715
  return MercatorCoordinate.fromLngLat(lnglat);
709
716
  }
710
-
711
717
  /**
712
718
  * Given a Coordinate, return its geographical position.
713
719
  * @param {Coordinate} coord
714
720
  * @returns {LngLat} lnglat
715
721
  * @private
716
722
  */
723
+
717
724
  }, {
718
725
  key: "coordinateLocation",
719
726
  value: function coordinateLocation(coord) {
@@ -738,12 +745,10 @@ var Transform = /*#__PURE__*/function () {
738
745
  // if (cache[posMatrixKey]) {
739
746
  // return cache[posMatrixKey];
740
747
  // }
741
-
742
748
  // const canonical = unwrappedTileID.canonical;
743
749
  // const scale = this.worldSize / this.zoomScale(canonical.z);
744
750
  // const unwrappedX =
745
751
  // canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;
746
-
747
752
  // const posMatrix = mat4.identity(new Float64Array(16));
748
753
  // mat4.translate(posMatrix, posMatrix, [
749
754
  // unwrappedX * scale,
@@ -756,16 +761,17 @@ var Transform = /*#__PURE__*/function () {
756
761
  // aligned ? this.alignedProjMatrix : this.projMatrix,
757
762
  // posMatrix,
758
763
  // );
759
-
760
764
  // cache[posMatrixKey] = new Float32Array(posMatrix);
761
765
  // return cache[posMatrixKey];
762
766
  // }
767
+
763
768
  }, {
764
769
  key: "constrain",
765
770
  value: function constrain() {
766
771
  if (!this.center || !this.width || !this.height || this.constraining) {
767
772
  return;
768
773
  }
774
+
769
775
  this.constraining = true;
770
776
  var minY = -90;
771
777
  var maxY = 90;
@@ -777,58 +783,70 @@ var Transform = /*#__PURE__*/function () {
777
783
  var y2;
778
784
  var size = this.size;
779
785
  var unmodified = this.unmodified;
786
+
780
787
  if (this.latRange) {
781
788
  var latRange = this.latRange;
782
789
  minY = mercatorYfromLat(latRange[1]) * this.worldSize;
783
790
  maxY = mercatorYfromLat(latRange[0]) * this.worldSize;
784
791
  sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;
785
792
  }
793
+
786
794
  if (this.lngRange) {
787
795
  var lngRange = this.lngRange;
788
796
  minX = mercatorXfromLng(lngRange[0]) * this.worldSize;
789
797
  maxX = mercatorXfromLng(lngRange[1]) * this.worldSize;
790
798
  sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;
791
799
  }
792
- var point = this.point;
793
800
 
794
- // how much the map should scale to fit the screen into given latitude/longitude ranges
801
+ var point = this.point; // how much the map should scale to fit the screen into given latitude/longitude ranges
802
+
795
803
  var s = Math.max(sx || 0, sy || 0);
804
+
796
805
  if (s) {
797
806
  this.center = this.unproject(new Point(sx ? (maxX + minX) / 2 : point.x, sy ? (maxY + minY) / 2 : point.y));
807
+
798
808
  if (isMini) {
799
809
  this.zoom = Math.max(this.zoom, Math.max(-1, this.minZoom));
800
810
  } else {
801
811
  this.zoom += this.scaleZoom(s);
802
812
  }
813
+
803
814
  this.unmodified = unmodified;
804
815
  this.constraining = false;
805
816
  return;
806
817
  }
818
+
807
819
  if (this.latRange) {
808
820
  var y = point.y;
809
821
  var h2 = size.y / 2;
822
+
810
823
  if (y - h2 < minY) {
811
824
  y2 = minY + h2;
812
825
  }
826
+
813
827
  if (y + h2 > maxY) {
814
828
  y2 = maxY - h2;
815
829
  }
816
830
  }
831
+
817
832
  if (this.lngRange) {
818
833
  var x = point.x;
819
834
  var w2 = size.x / 2;
835
+
820
836
  if (x - w2 < minX) {
821
837
  x2 = minX + w2;
822
838
  }
839
+
823
840
  if (x + w2 > maxX) {
824
841
  x2 = maxX - w2;
825
842
  }
826
- }
843
+ } // pan the map if the screen goes off the range
844
+
827
845
 
828
- // pan the map if the screen goes off the range
829
846
  if (x2 !== undefined || y2 !== undefined) {
830
847
  this.center = this.unproject(new Point(x2 !== undefined ? x2 : point.x, y2 !== undefined ? y2 : point.y));
831
848
  }
849
+
832
850
  this.unmodified = unmodified;
833
851
  this.constraining = false;
834
852
  }
@@ -838,125 +856,116 @@ var Transform = /*#__PURE__*/function () {
838
856
  if (!this.height) {
839
857
  return;
840
858
  }
859
+
841
860
  var halfFov = this._fov / 2;
842
861
  var offset = this.centerOffset;
843
- this.cameraToCenterDistance = 0.5 / Math.tan(halfFov) * this.height;
844
-
845
- // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the
862
+ this.cameraToCenterDistance = 0.5 / Math.tan(halfFov) * this.height; // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the
846
863
  // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.
847
864
  // 1 Z unit is equivalent to 1 horizontal px at the center of the map
848
865
  // (the distance between[width/2, height/2] and [width/2 + 1, height/2])
866
+
849
867
  var groundAngle = Math.PI / 2 + this._pitch;
850
868
  var fovAboveCenter = this._fov * (0.5 + offset.y / this.height);
851
869
  var topHalfSurfaceDistance = Math.sin(fovAboveCenter) * this.cameraToCenterDistance / Math.sin(clamp(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01));
852
870
  var point = this.point;
853
871
  var x = point.x;
854
- var y = point.y;
872
+ var y = point.y; // Calculate z distance of the farthest fragment that should be rendered.
855
873
 
856
- // Calculate z distance of the farthest fragment that should be rendered.
857
- var furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance;
858
- // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
859
- var farZ = furthestDistance * 1.01;
874
+ var furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance; // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
860
875
 
861
- // The larger the value of nearZ is
876
+ var farZ = furthestDistance * 1.01; // The larger the value of nearZ is
862
877
  // - the more depth precision is available for features (good)
863
878
  // - clipping starts appearing sooner when the camera is close to 3d features (bad)
864
879
  //
865
880
  // Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues
866
881
  // when rendering it's layers using custom layers. This value was experimentally chosen and
867
882
  // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.
868
- var nearZ = this.height / 50;
869
883
 
870
- // matrix for conversion from location to GL coordinates (-1 .. 1)
884
+ var nearZ = this.height / 50; // matrix for conversion from location to GL coordinates (-1 .. 1)
871
885
  // 使用 Float64Array 的原因是为了避免计算精度问题、 mat4.create() 默认使用 Float32Array
872
- var m = new Float64Array(16);
873
- // @ts-ignore
874
- mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);
875
886
 
876
- // Apply center of perspective offset
887
+ var m = new Float64Array(16); // @ts-ignore
888
+
889
+ mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ); // Apply center of perspective offset
890
+
877
891
  m[8] = -offset.x * 2 / this.width;
878
- m[9] = offset.y * 2 / this.height;
892
+ m[9] = offset.y * 2 / this.height; // @ts-ignore
879
893
 
880
- // @ts-ignore
881
- mat4.scale(m, m, [1, -1, 1]);
882
- // @ts-ignore
883
- mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);
884
- // @ts-ignore
885
- mat4.rotateX(m, m, this._pitch);
886
- // @ts-ignore
887
- mat4.rotateZ(m, m, this.angle);
888
- // @ts-ignore
889
- mat4.translate(m, m, [-x, -y, 0]);
894
+ mat4.scale(m, m, [1, -1, 1]); // @ts-ignore
895
+
896
+ mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]); // @ts-ignore
897
+
898
+ mat4.rotateX(m, m, this._pitch); // @ts-ignore
899
+
900
+ mat4.rotateZ(m, m, this.angle); // @ts-ignore
890
901
 
891
- // The mercatorMatrix can be used to transform points from mercator coordinates
902
+ mat4.translate(m, m, [-x, -y, 0]); // The mercatorMatrix can be used to transform points from mercator coordinates
892
903
  // ([0, 0] nw, [1, 1] se) to GL coordinates.
893
904
  // @ts-ignore
894
- this.mercatorMatrix = mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]);
895
- // scale vertically to meters per pixel (inverse of ground resolution):
896
905
 
906
+ this.mercatorMatrix = mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]); // scale vertically to meters per pixel (inverse of ground resolution):
897
907
  // @ts-ignore
898
- mat4.scale(m, m, [1, 1, mercatorZfromAltitude(1, this.center.lat) * this.worldSize, 1]);
899
- // @ts-ignore
900
- this.projMatrix = m;
901
- // @ts-ignore
902
- this.invProjMatrix = mat4.invert([], this.projMatrix);
903
908
 
904
- // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.
909
+ mat4.scale(m, m, [1, 1, mercatorZfromAltitude(1, this.center.lat) * this.worldSize, 1]); // @ts-ignore
910
+
911
+ this.projMatrix = m; // @ts-ignore
912
+
913
+ this.invProjMatrix = mat4.invert([], this.projMatrix); // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.
905
914
  // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional
906
915
  // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension
907
916
  // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle
908
917
  // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that
909
918
  // it is always <= 0.5 pixels.
919
+
910
920
  var xShift = this.width % 2 / 2;
911
921
  var yShift = this.height % 2 / 2;
912
922
  var angleCos = Math.cos(this.angle);
913
923
  var angleSin = Math.sin(this.angle);
914
924
  var dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;
915
- var dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
916
- // const alignedM = mat4.clone(m);
917
- var alignedM = new Float64Array(m);
918
- // @ts-ignore
919
- mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]);
920
- // @ts-ignore
921
- this.alignedProjMatrix = alignedM;
925
+ var dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift; // const alignedM = mat4.clone(m);
922
926
 
923
- // @ts-ignore
924
- m = mat4.create();
925
- // @ts-ignore
926
- mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);
927
- // @ts-ignore
928
- mat4.translate(m, m, [1, -1, 0]);
929
- // @ts-ignore
930
- this.labelPlaneMatrix = m;
927
+ var alignedM = new Float64Array(m); // @ts-ignore
931
928
 
932
- // @ts-ignore
933
- m = mat4.create();
934
- // @ts-ignore
935
- mat4.scale(m, m, [1, -1, 1]);
936
- // @ts-ignore
937
- mat4.translate(m, m, [-1, -1, 0]);
938
- // @ts-ignore
939
- mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);
940
- // @ts-ignore
941
- this.glCoordMatrix = m;
929
+ mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]); // @ts-ignore
942
930
 
943
- // matrix for conversion from location to screen coordinates
944
- this.pixelMatrix = mat4.multiply(
945
- // @ts-ignore
946
- new Float64Array(16), this.labelPlaneMatrix, this.projMatrix);
931
+ this.alignedProjMatrix = alignedM; // @ts-ignore
932
+
933
+ m = mat4.create(); // @ts-ignore
934
+
935
+ mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]); // @ts-ignore
936
+
937
+ mat4.translate(m, m, [1, -1, 0]); // @ts-ignore
938
+
939
+ this.labelPlaneMatrix = m; // @ts-ignore
940
+
941
+ m = mat4.create(); // @ts-ignore
942
+
943
+ mat4.scale(m, m, [1, -1, 1]); // @ts-ignore
944
+
945
+ mat4.translate(m, m, [-1, -1, 0]); // @ts-ignore
946
+
947
+ mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]); // @ts-ignore
947
948
 
948
- // inverse matrix for conversion from screen coordinaes to location
949
+ this.glCoordMatrix = m; // matrix for conversion from location to screen coordinates
950
+
951
+ this.pixelMatrix = mat4.multiply( // @ts-ignore
952
+ new Float64Array(16), this.labelPlaneMatrix, this.projMatrix); // inverse matrix for conversion from screen coordinaes to location
949
953
  // @ts-ignore
954
+
950
955
  m = mat4.invert(new Float64Array(16), this.pixelMatrix);
956
+
951
957
  if (!m) {
952
958
  throw new Error('failed to invert matrix');
953
- }
954
- // @ts-ignore
959
+ } // @ts-ignore
960
+
961
+
955
962
  this.pixelMatrixInverse = m;
956
963
  this.posMatrixCache = {};
957
964
  this.alignedPosMatrixCache = {};
958
965
  }
959
966
  }]);
967
+
960
968
  return Transform;
961
969
  }();
970
+
962
971
  export { Transform as default };