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