@antv/l7-map 2.17.10 → 2.17.12

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 -127
  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 +169 -91
  51. package/lib/earthmap.js +80 -12
  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 -127
  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 +20 -2
  65. package/lib/handler/events/map_touch_event.js +21 -2
  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 -5
  69. package/lib/handler/handler_manager.js +171 -56
  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 +18 -1
  76. package/lib/handler/mouse/mousepitch_hander.js +17 -1
  77. package/lib/handler/mouse/mouserotate_hander.js +17 -1
  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 +32 -10
  91. package/lib/handler/touch/touch_rotate.js +25 -8
  92. package/lib/handler/touch/touch_zoom.js +24 -5
  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 +95 -15
  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() {
@@ -224,10 +246,6 @@ var Transform = /*#__PURE__*/function () {
224
246
  get: function get() {
225
247
  return this.project(this.center);
226
248
  }
227
-
228
- // tslint:disable:variable-name
229
-
230
- // tslint:enable
231
249
  }, {
232
250
  key: "clone",
233
251
  value: function clone() {
@@ -246,7 +264,6 @@ var Transform = /*#__PURE__*/function () {
246
264
  clone.calcMatrices();
247
265
  return clone;
248
266
  }
249
-
250
267
  /**
251
268
  * Returns if the padding params match
252
269
  *
@@ -254,12 +271,12 @@ var Transform = /*#__PURE__*/function () {
254
271
  * @returns {boolean}
255
272
  * @memberof Transform
256
273
  */
274
+
257
275
  }, {
258
276
  key: "isPaddingEqual",
259
277
  value: function isPaddingEqual(padding) {
260
278
  return this.edgeInsets.equals(padding);
261
279
  }
262
-
263
280
  /**
264
281
  * Helper method to upadte edge-insets inplace
265
282
  *
@@ -267,6 +284,7 @@ var Transform = /*#__PURE__*/function () {
267
284
  * @param {number} t
268
285
  * @memberof Transform
269
286
  */
287
+
270
288
  }, {
271
289
  key: "interpolatePadding",
272
290
  value: function interpolatePadding(start, target, t) {
@@ -275,7 +293,6 @@ var Transform = /*#__PURE__*/function () {
275
293
  this.constrain();
276
294
  this.calcMatrices();
277
295
  }
278
-
279
296
  /**
280
297
  * Return a zoom level that will cover all tiles the transform
281
298
  * @param {Object} options options
@@ -283,14 +300,14 @@ var Transform = /*#__PURE__*/function () {
283
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.
284
301
  * @returns {number} zoom level An integer zoom level at which all tiles will be visible.
285
302
  */
303
+
286
304
  }, {
287
305
  key: "coveringZoomLevel",
288
306
  value: function coveringZoomLevel(options) {
289
- var z = (options.roundZoom ? Math.round : Math.floor)(this.zoom + this.scaleZoom(this.tileSize / options.tileSize));
290
- // 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
+
291
309
  return Math.max(0, z);
292
310
  }
293
-
294
311
  /**
295
312
  * Return any "wrapped" copies of a given tile coordinate that are visible
296
313
  * in the current view.
@@ -306,12 +323,10 @@ var Transform = /*#__PURE__*/function () {
306
323
  // const ubr = this.pointCoordinate(new Point(0, this.height));
307
324
  // const w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));
308
325
  // const w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));
309
-
310
326
  // // Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.
311
327
  // // Both sources draw outside the tile boundaries of the tile that "contains them" so we need
312
328
  // // to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.
313
329
  // const extraWorldCopy = 1;
314
-
315
330
  // for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {
316
331
  // if (w === 0) {
317
332
  // continue;
@@ -345,14 +360,12 @@ var Transform = /*#__PURE__*/function () {
345
360
  // }): OverscaledTileID[] {
346
361
  // let z = this.coveringZoomLevel(options);
347
362
  // const actualZ = z;
348
-
349
363
  // if (options.minzoom !== undefined && z < options.minzoom) {
350
364
  // return [];
351
365
  // }
352
366
  // if (options.maxzoom !== undefined && z > options.maxzoom) {
353
367
  // z = options.maxzoom;
354
368
  // }
355
-
356
369
  // const centerCoord = MercatorCoordinate.fromLngLat(this.center);
357
370
  // const numTiles = Math.pow(2, z);
358
371
  // const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0];
@@ -361,17 +374,14 @@ var Transform = /*#__PURE__*/function () {
361
374
  // this.worldSize,
362
375
  // z,
363
376
  // );
364
-
365
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
366
378
  // let minZoom = options.minzoom || 0;
367
379
  // // Use 0.1 as an epsilon to avoid for explicit == 0.0 floating point checks
368
380
  // if (this._pitch <= 60.0 && this.edgeInsets.top < 0.1) {
369
381
  // minZoom = z;
370
382
  // }
371
-
372
383
  // // There should always be a certain number of maximum zoom level tiles surrounding the center location
373
384
  // const radiusOfMaxLvlLodInTiles = 3;
374
-
375
385
  // const newRootTile = (wrap: number): any => {
376
386
  // return {
377
387
  // // All tiles are on zero elevation plane => z difference is zero
@@ -386,13 +396,11 @@ var Transform = /*#__PURE__*/function () {
386
396
  // fullyVisible: false,
387
397
  // };
388
398
  // };
389
-
390
399
  // // Do a depth-first traversal to find visible tiles and proper levels of detail
391
400
  // const stack = [];
392
401
  // const result = [];
393
402
  // const maxZoom = z;
394
403
  // const overscaledZ = options.reparseOverscaled ? actualZ : z;
395
-
396
404
  // if (this._renderWorldCopies) {
397
405
  // // Render copy of the globe thrice on both sides
398
406
  // for (let i = 1; i <= 3; i++) {
@@ -400,30 +408,23 @@ var Transform = /*#__PURE__*/function () {
400
408
  // stack.push(newRootTile(i));
401
409
  // }
402
410
  // }
403
-
404
411
  // stack.push(newRootTile(0));
405
-
406
412
  // while (stack.length > 0) {
407
413
  // const it = stack.pop();
408
414
  // const x = it.x;
409
415
  // const y = it.y;
410
416
  // let fullyVisible = it.fullyVisible;
411
-
412
417
  // // Visibility of a tile is not required if any of its ancestor if fully inside the frustum
413
418
  // if (!fullyVisible) {
414
419
  // const intersectResult = it.aabb.intersects(cameraFrustum);
415
-
416
420
  // if (intersectResult === 0) {
417
421
  // continue;
418
422
  // }
419
-
420
423
  // fullyVisible = intersectResult === 2;
421
424
  // }
422
-
423
425
  // const distanceX = it.aabb.distanceX(centerPoint);
424
426
  // const distanceY = it.aabb.distanceY(centerPoint);
425
427
  // const longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));
426
-
427
428
  // // We're using distance based heuristics to determine if a tile should be split into quadrants or not.
428
429
  // // radiusOfMaxLvlLodInTiles defines that there's always a certain number of maxLevel tiles next to the map center.
429
430
  // // Using the fact that a parent node in quadtree is twice the size of its children (per dimension)
@@ -431,7 +432,6 @@ var Transform = /*#__PURE__*/function () {
431
432
  // // f(k) = offset + 2 + 4 + 8 + 16 + ... + 2^k. This is the same as "offset+2^(k+1)-2"
432
433
  // const distToSplit =
433
434
  // radiusOfMaxLvlLodInTiles + (1 << (maxZoom - it.zoom)) - 2;
434
-
435
435
  // // Have we reached the target depth or is the tile too far away to be any split further?
436
436
  // if (
437
437
  // it.zoom === maxZoom ||
@@ -452,11 +452,9 @@ var Transform = /*#__PURE__*/function () {
452
452
  // });
453
453
  // continue;
454
454
  // }
455
-
456
455
  // for (let i = 0; i < 4; i++) {
457
456
  // const childX = (x << 1) + (i % 2);
458
457
  // const childY = (y << 1) + (i >> 1);
459
-
460
458
  // stack.push({
461
459
  // aabb: it.aabb.quadrant(i),
462
460
  // zoom: it.zoom + 1,
@@ -467,11 +465,11 @@ var Transform = /*#__PURE__*/function () {
467
465
  // });
468
466
  // }
469
467
  // }
470
-
471
468
  // return result
472
469
  // .sort((a, b) => a.distanceSq - b.distanceSq)
473
470
  // .map((a) => a.tileID);
474
471
  // }
472
+
475
473
  }, {
476
474
  key: "resize",
477
475
  value: function resize(width, height) {
@@ -510,6 +508,7 @@ var Transform = /*#__PURE__*/function () {
510
508
  var loc = this.locationCoordinate(lnglat);
511
509
  var newCenter = new MercatorCoordinate(loc.x - (a.x - b.x), loc.y - (a.y - b.y));
512
510
  this.center = this.coordinateLocation(newCenter);
511
+
513
512
  if (this._renderWorldCopies) {
514
513
  this.center = this.center.wrap();
515
514
  }
@@ -517,17 +516,15 @@ var Transform = /*#__PURE__*/function () {
517
516
  }, {
518
517
  key: "pointCoordinate",
519
518
  value: function pointCoordinate(p) {
520
- var targetZ = 0;
521
- // 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,
522
520
  // unproject two points to get a line and then find the point on that
523
521
  // line with z=0
524
522
 
525
523
  var coord0 = new Float64Array([p.x, p.y, 0, 1]);
526
- 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
527
527
 
528
- // @ts-ignore
529
- vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);
530
- // @ts-ignore
531
528
  vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);
532
529
  var w0 = coord0[3];
533
530
  var w1 = coord1[3];
@@ -540,35 +537,36 @@ var Transform = /*#__PURE__*/function () {
540
537
  var t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);
541
538
  return new MercatorCoordinate(interpolate(x0, x1, t) / this.worldSize, interpolate(y0, y1, t) / this.worldSize);
542
539
  }
543
-
544
540
  /**
545
541
  * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
546
542
  * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
547
543
  * @returns {LngLatBounds} Returns a {@link LngLatBounds} object describing the map's geographical bounds.
548
544
  */
545
+
549
546
  }, {
550
547
  key: "getBounds",
551
548
  value: function getBounds() {
552
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)));
553
550
  }
554
-
555
551
  /**
556
552
  * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
557
553
  * @returns {LngLatBounds} {@link LngLatBounds}
558
554
  */
555
+
559
556
  }, {
560
557
  key: "getMaxBounds",
561
558
  value: function getMaxBounds() {
562
559
  if (!this.latRange || this.latRange.length !== 2 || !this.lngRange || this.lngRange.length !== 2) {
563
560
  return null;
564
561
  }
562
+
565
563
  return new LngLatBounds([this.lngRange[0], this.latRange[0]], [this.lngRange[1], this.latRange[1]]);
566
564
  }
567
-
568
565
  /**
569
566
  * Sets or clears the map's geographical constraints.
570
567
  * @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.
571
568
  */
569
+
572
570
  }, {
573
571
  key: "setMaxBounds",
574
572
  value: function setMaxBounds(bounds) {
@@ -593,12 +591,12 @@ var Transform = /*#__PURE__*/function () {
593
591
  if (!this.pixelMatrixInverse) {
594
592
  return 1;
595
593
  }
594
+
596
595
  var coord = this.pointCoordinate(new Point(0, 0));
597
596
  var p = new Float32Array([coord.x * this.worldSize, coord.y * this.worldSize, 0, 1]);
598
597
  var topPoint = vec4.transformMat4(p, p, this.pixelMatrix);
599
598
  return topPoint[3] / this.cameraToCenterDistance;
600
599
  }
601
-
602
600
  /*
603
601
  * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`
604
602
  * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).
@@ -610,6 +608,7 @@ var Transform = /*#__PURE__*/function () {
610
608
  * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because
611
609
  * the camera is right above the center of the map.
612
610
  */
611
+
613
612
  }, {
614
613
  key: "getCameraPoint",
615
614
  value: function getCameraPoint() {
@@ -617,7 +616,6 @@ var Transform = /*#__PURE__*/function () {
617
616
  var yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);
618
617
  return this.centerPoint.add(new Point(0, yOffset));
619
618
  }
620
-
621
619
  /*
622
620
  * When the map is pitched, some of the 3D features that intersect a query will not intersect
623
621
  * the query at the surface of the earth. Instead the feature may be closer and only intersect
@@ -628,10 +626,12 @@ var Transform = /*#__PURE__*/function () {
628
626
  * - For point queries, the line from the query point to the "camera point"
629
627
  * - For other geometries, the envelope of the query geometry and the "camera point"
630
628
  */
629
+
631
630
  }, {
632
631
  key: "getCameraQueryGeometry",
633
632
  value: function getCameraQueryGeometry(queryGeometry) {
634
633
  var c = this.getCameraPoint();
634
+
635
635
  if (queryGeometry.length === 1) {
636
636
  return [queryGeometry[0], c];
637
637
  } else {
@@ -639,8 +639,10 @@ var Transform = /*#__PURE__*/function () {
639
639
  var minY = c.y;
640
640
  var maxX = c.x;
641
641
  var maxY = c.y;
642
+
642
643
  var _iterator = _createForOfIteratorHelper(queryGeometry),
643
- _step;
644
+ _step;
645
+
644
646
  try {
645
647
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
646
648
  var p = _step.value;
@@ -654,16 +656,17 @@ var Transform = /*#__PURE__*/function () {
654
656
  } finally {
655
657
  _iterator.f();
656
658
  }
659
+
657
660
  return [new Point(minX, minY), new Point(maxX, minY), new Point(maxX, maxY), new Point(minX, maxY), new Point(minX, minY)];
658
661
  }
659
662
  }
660
-
661
663
  /**
662
664
  * Given a coordinate, return the screen point that corresponds to it
663
665
  * @param {Coordinate} coord
664
666
  * @returns {Point} screen point
665
667
  * @private
666
668
  */
669
+
667
670
  }, {
668
671
  key: "coordinatePoint",
669
672
  value: function coordinatePoint(coord) {
@@ -677,28 +680,27 @@ var Transform = /*#__PURE__*/function () {
677
680
  * @returns {Point} screen point
678
681
  * @private
679
682
  */
683
+
680
684
  }, {
681
685
  key: "locationPoint",
682
686
  value: function locationPoint(lnglat) {
683
687
  return this.coordinatePoint(this.locationCoordinate(lnglat));
684
688
  }
685
-
686
689
  /**
687
690
  * Given a point on screen, return its lnglat
688
691
  * @param {Point} p screen point
689
692
  * @returns {LngLat} lnglat location
690
693
  * @private
691
694
  */
695
+
692
696
  }, {
693
697
  key: "pointLocation",
694
698
  value: function pointLocation(p) {
695
699
  // if(p.x !== 0 && p.x !== 1001) {
696
700
  // console.log(p.x)
697
701
  // }
698
-
699
702
  return this.coordinateLocation(this.pointCoordinate(p));
700
703
  }
701
-
702
704
  /**
703
705
  * Given a geographical lnglat, return an unrounded
704
706
  * coordinate that represents it at this transform's zoom level.
@@ -706,18 +708,19 @@ var Transform = /*#__PURE__*/function () {
706
708
  * @returns {Coordinate}
707
709
  * @private
708
710
  */
711
+
709
712
  }, {
710
713
  key: "locationCoordinate",
711
714
  value: function locationCoordinate(lnglat) {
712
715
  return MercatorCoordinate.fromLngLat(lnglat);
713
716
  }
714
-
715
717
  /**
716
718
  * Given a Coordinate, return its geographical position.
717
719
  * @param {Coordinate} coord
718
720
  * @returns {LngLat} lnglat
719
721
  * @private
720
722
  */
723
+
721
724
  }, {
722
725
  key: "coordinateLocation",
723
726
  value: function coordinateLocation(coord) {
@@ -742,12 +745,10 @@ var Transform = /*#__PURE__*/function () {
742
745
  // if (cache[posMatrixKey]) {
743
746
  // return cache[posMatrixKey];
744
747
  // }
745
-
746
748
  // const canonical = unwrappedTileID.canonical;
747
749
  // const scale = this.worldSize / this.zoomScale(canonical.z);
748
750
  // const unwrappedX =
749
751
  // canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;
750
-
751
752
  // const posMatrix = mat4.identity(new Float64Array(16));
752
753
  // mat4.translate(posMatrix, posMatrix, [
753
754
  // unwrappedX * scale,
@@ -760,16 +761,17 @@ var Transform = /*#__PURE__*/function () {
760
761
  // aligned ? this.alignedProjMatrix : this.projMatrix,
761
762
  // posMatrix,
762
763
  // );
763
-
764
764
  // cache[posMatrixKey] = new Float32Array(posMatrix);
765
765
  // return cache[posMatrixKey];
766
766
  // }
767
+
767
768
  }, {
768
769
  key: "constrain",
769
770
  value: function constrain() {
770
771
  if (!this.center || !this.width || !this.height || this.constraining) {
771
772
  return;
772
773
  }
774
+
773
775
  this.constraining = true;
774
776
  var minY = -90;
775
777
  var maxY = 90;
@@ -781,58 +783,70 @@ var Transform = /*#__PURE__*/function () {
781
783
  var y2;
782
784
  var size = this.size;
783
785
  var unmodified = this.unmodified;
786
+
784
787
  if (this.latRange) {
785
788
  var latRange = this.latRange;
786
789
  minY = mercatorYfromLat(latRange[1]) * this.worldSize;
787
790
  maxY = mercatorYfromLat(latRange[0]) * this.worldSize;
788
791
  sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;
789
792
  }
793
+
790
794
  if (this.lngRange) {
791
795
  var lngRange = this.lngRange;
792
796
  minX = mercatorXfromLng(lngRange[0]) * this.worldSize;
793
797
  maxX = mercatorXfromLng(lngRange[1]) * this.worldSize;
794
798
  sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;
795
799
  }
796
- var point = this.point;
797
800
 
798
- // 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
+
799
803
  var s = Math.max(sx || 0, sy || 0);
804
+
800
805
  if (s) {
801
806
  this.center = this.unproject(new Point(sx ? (maxX + minX) / 2 : point.x, sy ? (maxY + minY) / 2 : point.y));
807
+
802
808
  if (isMini) {
803
809
  this.zoom = Math.max(this.zoom, Math.max(-1, this.minZoom));
804
810
  } else {
805
811
  this.zoom += this.scaleZoom(s);
806
812
  }
813
+
807
814
  this.unmodified = unmodified;
808
815
  this.constraining = false;
809
816
  return;
810
817
  }
818
+
811
819
  if (this.latRange) {
812
820
  var y = point.y;
813
821
  var h2 = size.y / 2;
822
+
814
823
  if (y - h2 < minY) {
815
824
  y2 = minY + h2;
816
825
  }
826
+
817
827
  if (y + h2 > maxY) {
818
828
  y2 = maxY - h2;
819
829
  }
820
830
  }
831
+
821
832
  if (this.lngRange) {
822
833
  var x = point.x;
823
834
  var w2 = size.x / 2;
835
+
824
836
  if (x - w2 < minX) {
825
837
  x2 = minX + w2;
826
838
  }
839
+
827
840
  if (x + w2 > maxX) {
828
841
  x2 = maxX - w2;
829
842
  }
830
- }
843
+ } // pan the map if the screen goes off the range
844
+
831
845
 
832
- // pan the map if the screen goes off the range
833
846
  if (x2 !== undefined || y2 !== undefined) {
834
847
  this.center = this.unproject(new Point(x2 !== undefined ? x2 : point.x, y2 !== undefined ? y2 : point.y));
835
848
  }
849
+
836
850
  this.unmodified = unmodified;
837
851
  this.constraining = false;
838
852
  }
@@ -842,125 +856,116 @@ var Transform = /*#__PURE__*/function () {
842
856
  if (!this.height) {
843
857
  return;
844
858
  }
859
+
845
860
  var halfFov = this._fov / 2;
846
861
  var offset = this.centerOffset;
847
- this.cameraToCenterDistance = 0.5 / Math.tan(halfFov) * this.height;
848
-
849
- // 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
850
863
  // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.
851
864
  // 1 Z unit is equivalent to 1 horizontal px at the center of the map
852
865
  // (the distance between[width/2, height/2] and [width/2 + 1, height/2])
866
+
853
867
  var groundAngle = Math.PI / 2 + this._pitch;
854
868
  var fovAboveCenter = this._fov * (0.5 + offset.y / this.height);
855
869
  var topHalfSurfaceDistance = Math.sin(fovAboveCenter) * this.cameraToCenterDistance / Math.sin(clamp(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01));
856
870
  var point = this.point;
857
871
  var x = point.x;
858
- var y = point.y;
872
+ var y = point.y; // Calculate z distance of the farthest fragment that should be rendered.
859
873
 
860
- // Calculate z distance of the farthest fragment that should be rendered.
861
- var furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance;
862
- // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
863
- 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`
864
875
 
865
- // The larger the value of nearZ is
876
+ var farZ = furthestDistance * 1.01; // The larger the value of nearZ is
866
877
  // - the more depth precision is available for features (good)
867
878
  // - clipping starts appearing sooner when the camera is close to 3d features (bad)
868
879
  //
869
880
  // Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues
870
881
  // when rendering it's layers using custom layers. This value was experimentally chosen and
871
882
  // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.
872
- var nearZ = this.height / 50;
873
883
 
874
- // 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)
875
885
  // 使用 Float64Array 的原因是为了避免计算精度问题、 mat4.create() 默认使用 Float32Array
876
- var m = new Float64Array(16);
877
- // @ts-ignore
878
- mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);
879
886
 
880
- // 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
+
881
891
  m[8] = -offset.x * 2 / this.width;
882
- m[9] = offset.y * 2 / this.height;
892
+ m[9] = offset.y * 2 / this.height; // @ts-ignore
883
893
 
884
- // @ts-ignore
885
- mat4.scale(m, m, [1, -1, 1]);
886
- // @ts-ignore
887
- mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);
888
- // @ts-ignore
889
- mat4.rotateX(m, m, this._pitch);
890
- // @ts-ignore
891
- mat4.rotateZ(m, m, this.angle);
892
- // @ts-ignore
893
- 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
894
901
 
895
- // 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
896
903
  // ([0, 0] nw, [1, 1] se) to GL coordinates.
897
904
  // @ts-ignore
898
- this.mercatorMatrix = mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]);
899
- // scale vertically to meters per pixel (inverse of ground resolution):
900
905
 
906
+ this.mercatorMatrix = mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]); // scale vertically to meters per pixel (inverse of ground resolution):
901
907
  // @ts-ignore
902
- mat4.scale(m, m, [1, 1, mercatorZfromAltitude(1, this.center.lat) * this.worldSize, 1]);
903
- // @ts-ignore
904
- this.projMatrix = m;
905
- // @ts-ignore
906
- this.invProjMatrix = mat4.invert([], this.projMatrix);
907
908
 
908
- // 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.
909
914
  // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional
910
915
  // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension
911
916
  // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle
912
917
  // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that
913
918
  // it is always <= 0.5 pixels.
919
+
914
920
  var xShift = this.width % 2 / 2;
915
921
  var yShift = this.height % 2 / 2;
916
922
  var angleCos = Math.cos(this.angle);
917
923
  var angleSin = Math.sin(this.angle);
918
924
  var dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;
919
- var dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
920
- // const alignedM = mat4.clone(m);
921
- var alignedM = new Float64Array(m);
922
- // @ts-ignore
923
- mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]);
924
- // @ts-ignore
925
- this.alignedProjMatrix = alignedM;
925
+ var dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift; // const alignedM = mat4.clone(m);
926
926
 
927
- // @ts-ignore
928
- m = mat4.create();
929
- // @ts-ignore
930
- mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);
931
- // @ts-ignore
932
- mat4.translate(m, m, [1, -1, 0]);
933
- // @ts-ignore
934
- this.labelPlaneMatrix = m;
927
+ var alignedM = new Float64Array(m); // @ts-ignore
935
928
 
936
- // @ts-ignore
937
- m = mat4.create();
938
- // @ts-ignore
939
- mat4.scale(m, m, [1, -1, 1]);
940
- // @ts-ignore
941
- mat4.translate(m, m, [-1, -1, 0]);
942
- // @ts-ignore
943
- mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);
944
- // @ts-ignore
945
- this.glCoordMatrix = m;
929
+ mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]); // @ts-ignore
946
930
 
947
- // matrix for conversion from location to screen coordinates
948
- this.pixelMatrix = mat4.multiply(
949
- // @ts-ignore
950
- 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
951
948
 
952
- // 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
953
953
  // @ts-ignore
954
+
954
955
  m = mat4.invert(new Float64Array(16), this.pixelMatrix);
956
+
955
957
  if (!m) {
956
958
  throw new Error('failed to invert matrix');
957
- }
958
- // @ts-ignore
959
+ } // @ts-ignore
960
+
961
+
959
962
  this.pixelMatrixInverse = m;
960
963
  this.posMatrixCache = {};
961
964
  this.alignedPosMatrixCache = {};
962
965
  }
963
966
  }]);
967
+
964
968
  return Transform;
965
969
  }();
970
+
966
971
  export { Transform as default };