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