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