@antv/l7-map 2.18.2 → 2.18.3

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