@antv/l7-map 2.17.12 → 2.18.0

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