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