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