@antv/l7-map 2.18.0 → 2.18.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/package.json +3 -3
- package/es/camera.d.ts +0 -85
- package/es/camera.js +0 -718
- package/es/css/l7.css +0 -98
- package/es/earthmap.d.ts +0 -66
- package/es/earthmap.js +0 -369
- package/es/geo/edge_insets.d.ts +0 -54
- package/es/geo/edge_insets.js +0 -108
- package/es/geo/lng_lat.d.ts +0 -18
- package/es/geo/lng_lat.js +0 -73
- package/es/geo/lng_lat_bounds.d.ts +0 -24
- package/es/geo/lng_lat_bounds.js +0 -154
- package/es/geo/mercator.d.ts +0 -29
- package/es/geo/mercator.js +0 -84
- package/es/geo/point.d.ts +0 -40
- package/es/geo/point.js +0 -224
- package/es/geo/simple.d.ts +0 -29
- package/es/geo/simple.js +0 -87
- package/es/geo/transform.d.ts +0 -198
- package/es/geo/transform.js +0 -961
- package/es/handler/IHandler.d.ts +0 -34
- package/es/handler/IHandler.js +0 -1
- package/es/handler/blockable_map_event.d.ts +0 -17
- package/es/handler/blockable_map_event.js +0 -78
- package/es/handler/box_zoom.d.ts +0 -59
- package/es/handler/box_zoom.js +0 -180
- package/es/handler/click_zoom.d.ts +0 -16
- package/es/handler/click_zoom.js +0 -54
- package/es/handler/events/event.d.ts +0 -4
- package/es/handler/events/event.js +0 -11
- package/es/handler/events/index.d.ts +0 -4
- package/es/handler/events/index.js +0 -4
- package/es/handler/events/map_mouse_event.d.ts +0 -34
- package/es/handler/events/map_mouse_event.js +0 -64
- package/es/handler/events/map_touch_event.d.ts +0 -57
- package/es/handler/events/map_touch_event.js +0 -95
- package/es/handler/events/map_wheel_event.d.ts +0 -33
- package/es/handler/events/map_wheel_event.js +0 -50
- package/es/handler/events/render_event.d.ts +0 -5
- package/es/handler/events/render_event.js +0 -26
- package/es/handler/handler_inertia.d.ts +0 -23
- package/es/handler/handler_inertia.js +0 -157
- package/es/handler/handler_manager.d.ts +0 -61
- package/es/handler/handler_manager.js +0 -577
- package/es/handler/handler_util.d.ts +0 -4
- package/es/handler/handler_util.js +0 -9
- package/es/handler/keyboard.d.ts +0 -36
- package/es/handler/keyboard.js +0 -143
- package/es/handler/map_event.d.ts +0 -29
- package/es/handler/map_event.js +0 -125
- package/es/handler/mouse/index.d.ts +0 -4
- package/es/handler/mouse/index.js +0 -4
- package/es/handler/mouse/mouse_handler.d.ts +0 -22
- package/es/handler/mouse/mouse_handler.js +0 -118
- package/es/handler/mouse/mousepan_handler.d.ts +0 -10
- package/es/handler/mouse/mousepan_handler.js +0 -44
- package/es/handler/mouse/mousepitch_hander.d.ts +0 -9
- package/es/handler/mouse/mousepitch_hander.js +0 -46
- package/es/handler/mouse/mouserotate_hander.d.ts +0 -9
- package/es/handler/mouse/mouserotate_hander.js +0 -46
- package/es/handler/mouse/util.d.ts +0 -6
- package/es/handler/mouse/util.js +0 -11
- package/es/handler/scroll_zoom.d.ts +0 -93
- package/es/handler/scroll_zoom.js +0 -325
- package/es/handler/shim/dblclick_zoom.d.ts +0 -40
- package/es/handler/shim/dblclick_zoom.js +0 -67
- package/es/handler/shim/drag_pan.d.ts +0 -61
- package/es/handler/shim/drag_pan.js +0 -84
- package/es/handler/shim/drag_rotate.d.ts +0 -46
- package/es/handler/shim/drag_rotate.js +0 -74
- package/es/handler/shim/touch_zoom_rotate.d.ts +0 -70
- package/es/handler/shim/touch_zoom_rotate.js +0 -115
- package/es/handler/tap/single_tap_recognizer.d.ts +0 -20
- package/es/handler/tap/single_tap_recognizer.js +0 -97
- package/es/handler/tap/tap_drag_zoom.d.ts +0 -22
- package/es/handler/tap/tap_drag_zoom.js +0 -106
- package/es/handler/tap/tap_recognizer.d.ts +0 -17
- package/es/handler/tap/tap_recognizer.js +0 -54
- package/es/handler/tap/tap_zoom.d.ts +0 -22
- package/es/handler/tap/tap_zoom.js +0 -109
- package/es/handler/touch/index.d.ts +0 -5
- package/es/handler/touch/index.js +0 -5
- package/es/handler/touch/touch_pan.d.ts +0 -30
- package/es/handler/touch/touch_pan.js +0 -110
- package/es/handler/touch/touch_pitch.d.ts +0 -13
- package/es/handler/touch/touch_pitch.js +0 -93
- package/es/handler/touch/touch_rotate.d.ts +0 -12
- package/es/handler/touch/touch_rotate.js +0 -77
- package/es/handler/touch/touch_zoom.d.ts +0 -12
- package/es/handler/touch/touch_zoom.js +0 -54
- package/es/handler/touch/two_touch.d.ts +0 -23
- package/es/handler/touch/two_touch.js +0 -125
- package/es/hash.d.ts +0 -14
- package/es/hash.js +0 -134
- package/es/index.d.ts +0 -4
- package/es/index.js +0 -4
- package/es/interface.d.ts +0 -34
- package/es/interface.js +0 -1
- package/es/map.d.ts +0 -70
- package/es/map.js +0 -387
- package/es/util.d.ts +0 -25
- package/es/util.js +0 -88
- package/es/utils/Aabb.d.ts +0 -12
- package/es/utils/Aabb.js +0 -112
- package/es/utils/dom.d.ts +0 -4
- package/es/utils/dom.js +0 -140
- package/es/utils/performance.d.ts +0 -17
- package/es/utils/performance.js +0 -62
- package/es/utils/primitives.d.ts +0 -6
- package/es/utils/primitives.js +0 -47
- package/es/utils/task_queue.d.ts +0 -13
- package/es/utils/task_queue.js +0 -89
- package/lib/camera.js +0 -724
- package/lib/css/l7.css +0 -98
- package/lib/earthmap.js +0 -376
- package/lib/geo/edge_insets.js +0 -114
- package/lib/geo/lng_lat.js +0 -81
- package/lib/geo/lng_lat_bounds.js +0 -161
- package/lib/geo/mercator.js +0 -100
- package/lib/geo/point.js +0 -231
- package/lib/geo/simple.js +0 -104
- package/lib/geo/transform.js +0 -971
- package/lib/handler/IHandler.js +0 -5
- package/lib/handler/blockable_map_event.js +0 -84
- package/lib/handler/box_zoom.js +0 -186
- package/lib/handler/click_zoom.js +0 -61
- package/lib/handler/events/event.js +0 -20
- package/lib/handler/events/index.js +0 -27
- package/lib/handler/events/map_mouse_event.js +0 -70
- package/lib/handler/events/map_touch_event.js +0 -100
- package/lib/handler/events/map_wheel_event.js +0 -57
- package/lib/handler/events/render_event.js +0 -33
- package/lib/handler/handler_inertia.js +0 -162
- package/lib/handler/handler_manager.js +0 -584
- package/lib/handler/handler_util.js +0 -15
- package/lib/handler/keyboard.js +0 -151
- package/lib/handler/map_event.js +0 -131
- package/lib/handler/mouse/index.js +0 -27
- package/lib/handler/mouse/mouse_handler.js +0 -124
- package/lib/handler/mouse/mousepan_handler.js +0 -49
- package/lib/handler/mouse/mousepitch_hander.js +0 -51
- package/lib/handler/mouse/mouserotate_hander.js +0 -51
- package/lib/handler/mouse/util.js +0 -22
- package/lib/handler/scroll_zoom.js +0 -333
- package/lib/handler/shim/dblclick_zoom.js +0 -74
- package/lib/handler/shim/drag_pan.js +0 -91
- package/lib/handler/shim/drag_rotate.js +0 -81
- package/lib/handler/shim/touch_zoom_rotate.js +0 -122
- package/lib/handler/tap/single_tap_recognizer.js +0 -106
- package/lib/handler/tap/tap_drag_zoom.js +0 -112
- package/lib/handler/tap/tap_recognizer.js +0 -63
- package/lib/handler/tap/tap_zoom.js +0 -115
- package/lib/handler/touch/index.js +0 -34
- package/lib/handler/touch/touch_pan.js +0 -117
- package/lib/handler/touch/touch_pitch.js +0 -98
- package/lib/handler/touch/touch_rotate.js +0 -82
- package/lib/handler/touch/touch_zoom.js +0 -59
- package/lib/handler/touch/two_touch.js +0 -131
- package/lib/hash.js +0 -143
- package/lib/index.js +0 -49
- package/lib/interface.js +0 -5
- package/lib/map.js +0 -394
- package/lib/util.js +0 -108
- package/lib/utils/Aabb.js +0 -119
- package/lib/utils/dom.js +0 -147
- package/lib/utils/performance.js +0 -70
- package/lib/utils/primitives.js +0 -54
- package/lib/utils/task_queue.js +0 -97
package/es/geo/transform.js
DELETED
|
@@ -1,961 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
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; }
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
import { mat2, mat4, vec4 } from 'gl-matrix';
|
|
8
|
-
import Point from "../geo/point";
|
|
9
|
-
import { clamp, interpolate, wrap } from "../util";
|
|
10
|
-
import EdgeInsets from "./edge_insets";
|
|
11
|
-
import LngLat from "./lng_lat";
|
|
12
|
-
import LngLatBounds from "./lng_lat_bounds";
|
|
13
|
-
import MercatorCoordinate, { mercatorXfromLng, mercatorYfromLat, mercatorZfromAltitude } from "./mercator";
|
|
14
|
-
export var EXTENT = 8192;
|
|
15
|
-
var Transform = /*#__PURE__*/function () {
|
|
16
|
-
function Transform(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies) {
|
|
17
|
-
_classCallCheck(this, Transform);
|
|
18
|
-
this.tileSize = 512; // constant
|
|
19
|
-
this.maxValidLatitude = 85.051129; // constant
|
|
20
|
-
|
|
21
|
-
this._renderWorldCopies = renderWorldCopies === undefined ? true : renderWorldCopies;
|
|
22
|
-
this._minZoom = minZoom || 0;
|
|
23
|
-
this._maxZoom = maxZoom || 22;
|
|
24
|
-
this._minPitch = minPitch === undefined || minPitch === null ? 0 : minPitch;
|
|
25
|
-
this._maxPitch = maxPitch === undefined || maxPitch === null ? 60 : maxPitch;
|
|
26
|
-
this.setMaxBounds();
|
|
27
|
-
this.width = 0;
|
|
28
|
-
this.height = 0;
|
|
29
|
-
this._center = new LngLat(0, 0);
|
|
30
|
-
this.zoom = 0;
|
|
31
|
-
this.angle = 0;
|
|
32
|
-
this._fov = 0.6435011087932844;
|
|
33
|
-
this._pitch = 0;
|
|
34
|
-
this.unmodified = true;
|
|
35
|
-
this.edgeInsets = new EdgeInsets();
|
|
36
|
-
this.posMatrixCache = {};
|
|
37
|
-
this.alignedPosMatrixCache = {};
|
|
38
|
-
}
|
|
39
|
-
_createClass(Transform, [{
|
|
40
|
-
key: "minZoom",
|
|
41
|
-
get: function get() {
|
|
42
|
-
return this._minZoom;
|
|
43
|
-
},
|
|
44
|
-
set: function set(zoom) {
|
|
45
|
-
if (this._minZoom === zoom) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
this._minZoom = zoom;
|
|
49
|
-
this.zoom = Math.max(this.zoom, zoom);
|
|
50
|
-
}
|
|
51
|
-
}, {
|
|
52
|
-
key: "maxZoom",
|
|
53
|
-
get: function get() {
|
|
54
|
-
return this._maxZoom;
|
|
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
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* The center of the screen in pixels with the top-left corner being (0,0)
|
|
210
|
-
* and +y axis pointing downwards. This accounts for padding.
|
|
211
|
-
*
|
|
212
|
-
* @readonly
|
|
213
|
-
* @type {Point}
|
|
214
|
-
* @memberof Transform
|
|
215
|
-
*/
|
|
216
|
-
}, {
|
|
217
|
-
key: "centerPoint",
|
|
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
|
-
}
|
|
226
|
-
|
|
227
|
-
// tslint:disable:variable-name
|
|
228
|
-
|
|
229
|
-
// tslint:enable
|
|
230
|
-
}, {
|
|
231
|
-
key: "clone",
|
|
232
|
-
value: function clone() {
|
|
233
|
-
var clone = new Transform(this._minZoom, this._maxZoom, this._minPitch, this._maxPitch, this._renderWorldCopies);
|
|
234
|
-
clone.tileSize = this.tileSize;
|
|
235
|
-
clone.latRange = this.latRange;
|
|
236
|
-
clone.width = this.width;
|
|
237
|
-
clone.height = this.height;
|
|
238
|
-
clone.center = this._center;
|
|
239
|
-
clone.zoom = this.zoom;
|
|
240
|
-
clone.angle = this.angle;
|
|
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
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Returns if the padding params match
|
|
251
|
-
*
|
|
252
|
-
* @param {IPaddingOptions} padding
|
|
253
|
-
* @returns {boolean}
|
|
254
|
-
* @memberof Transform
|
|
255
|
-
*/
|
|
256
|
-
}, {
|
|
257
|
-
key: "isPaddingEqual",
|
|
258
|
-
value: function isPaddingEqual(padding) {
|
|
259
|
-
return this.edgeInsets.equals(padding);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Helper method to upadte edge-insets inplace
|
|
264
|
-
*
|
|
265
|
-
* @param {IPaddingOptions} target
|
|
266
|
-
* @param {number} t
|
|
267
|
-
* @memberof Transform
|
|
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
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Return a zoom level that will cover all tiles the transform
|
|
280
|
-
* @param {Object} options options
|
|
281
|
-
* @param {number} options.tileSize Tile size, expressed in screen pixels.
|
|
282
|
-
* @param {boolean} options.roundZoom Target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored.
|
|
283
|
-
* @returns {number} zoom level An integer zoom level at which all tiles will be visible.
|
|
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);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Return any "wrapped" copies of a given tile coordinate that are visible
|
|
295
|
-
* in the current view.
|
|
296
|
-
*
|
|
297
|
-
* @private
|
|
298
|
-
*/
|
|
299
|
-
// public getVisibleUnwrappedCoordinates(tileID: CanonicalTileID) {
|
|
300
|
-
// const result = [new UnwrappedTileID(0, tileID)];
|
|
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];
|
|
480
|
-
this.constrain();
|
|
481
|
-
this.calcMatrices();
|
|
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)));
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
|
|
556
|
-
* @returns {LngLatBounds} {@link LngLatBounds}
|
|
557
|
-
*/
|
|
558
|
-
}, {
|
|
559
|
-
key: "getMaxBounds",
|
|
560
|
-
value: function getMaxBounds() {
|
|
561
|
-
if (!this.latRange || this.latRange.length !== 2 || !this.lngRange || this.lngRange.length !== 2) {
|
|
562
|
-
return null;
|
|
563
|
-
}
|
|
564
|
-
return new LngLatBounds([this.lngRange[0], this.latRange[0]], [this.lngRange[1], this.latRange[1]]);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* Sets or clears the map's geographical constraints.
|
|
569
|
-
* @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.
|
|
570
|
-
*/
|
|
571
|
-
}, {
|
|
572
|
-
key: "setMaxBounds",
|
|
573
|
-
value: function setMaxBounds(bounds) {
|
|
574
|
-
if (bounds) {
|
|
575
|
-
this.lngRange = [bounds.getWest(), bounds.getEast()];
|
|
576
|
-
this.latRange = [bounds.getSouth(), bounds.getNorth()];
|
|
577
|
-
this.constrain();
|
|
578
|
-
} else {
|
|
579
|
-
this.lngRange = undefined;
|
|
580
|
-
this.latRange = [-this.maxValidLatitude, this.maxValidLatitude];
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}, {
|
|
584
|
-
key: "customLayerMatrix",
|
|
585
|
-
value: function customLayerMatrix() {
|
|
586
|
-
return this.mercatorMatrix.slice();
|
|
587
|
-
}
|
|
588
|
-
}, {
|
|
589
|
-
key: "maxPitchScaleFactor",
|
|
590
|
-
value: function maxPitchScaleFactor() {
|
|
591
|
-
// calcMatrices hasn't run yet
|
|
592
|
-
if (!this.pixelMatrixInverse) {
|
|
593
|
-
return 1;
|
|
594
|
-
}
|
|
595
|
-
var coord = this.pointCoordinate(new Point(0, 0));
|
|
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));
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/*
|
|
621
|
-
* When the map is pitched, some of the 3D features that intersect a query will not intersect
|
|
622
|
-
* the query at the surface of the earth. Instead the feature may be closer and only intersect
|
|
623
|
-
* the query because it extrudes into the air.
|
|
624
|
-
*
|
|
625
|
-
* This returns a geometry that includes all of the original query as well as all possible ares of the
|
|
626
|
-
* screen where the *base* of a visible extrusion could be.
|
|
627
|
-
* - For point queries, the line from the query point to the "camera point"
|
|
628
|
-
* - For other geometries, the envelope of the query geometry and the "camera point"
|
|
629
|
-
*/
|
|
630
|
-
}, {
|
|
631
|
-
key: "getCameraQueryGeometry",
|
|
632
|
-
value: function getCameraQueryGeometry(queryGeometry) {
|
|
633
|
-
var c = this.getCameraPoint();
|
|
634
|
-
if (queryGeometry.length === 1) {
|
|
635
|
-
return [queryGeometry[0], c];
|
|
636
|
-
} else {
|
|
637
|
-
var minX = c.x;
|
|
638
|
-
var minY = c.y;
|
|
639
|
-
var maxX = c.x;
|
|
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
|
-
}
|
|
659
|
-
|
|
660
|
-
/**
|
|
661
|
-
* Given a coordinate, return the screen point that corresponds to it
|
|
662
|
-
* @param {Coordinate} coord
|
|
663
|
-
* @returns {Point} screen point
|
|
664
|
-
* @private
|
|
665
|
-
*/
|
|
666
|
-
}, {
|
|
667
|
-
key: "coordinatePoint",
|
|
668
|
-
value: function coordinatePoint(coord) {
|
|
669
|
-
var p = vec4.fromValues(coord.x * this.worldSize, coord.y * this.worldSize, 0, 1);
|
|
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
|
-
}
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* Given a point on screen, return its lnglat
|
|
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
|
-
}
|
|
700
|
-
|
|
701
|
-
/**
|
|
702
|
-
* Given a geographical lnglat, return an unrounded
|
|
703
|
-
* coordinate that represents it at this transform's zoom level.
|
|
704
|
-
* @param {LngLat} lnglat
|
|
705
|
-
* @returns {Coordinate}
|
|
706
|
-
* @private
|
|
707
|
-
*/
|
|
708
|
-
}, {
|
|
709
|
-
key: "locationCoordinate",
|
|
710
|
-
value: function locationCoordinate(lnglat) {
|
|
711
|
-
return MercatorCoordinate.fromLngLat(lnglat);
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* Given a Coordinate, return its geographical position.
|
|
716
|
-
* @param {Coordinate} coord
|
|
717
|
-
* @returns {LngLat} lnglat
|
|
718
|
-
* @private
|
|
719
|
-
*/
|
|
720
|
-
}, {
|
|
721
|
-
key: "coordinateLocation",
|
|
722
|
-
value: function coordinateLocation(coord) {
|
|
723
|
-
return coord.toLngLat();
|
|
724
|
-
}
|
|
725
|
-
}, {
|
|
726
|
-
key: "getProjectionMatrix",
|
|
727
|
-
value: function getProjectionMatrix() {
|
|
728
|
-
return this.projMatrix;
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.
|
|
732
|
-
* @param {UnwrappedTileID} unwrappedTileID;
|
|
733
|
-
* @private
|
|
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;
|
|
794
|
-
}
|
|
795
|
-
var point = this.point;
|
|
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));
|
|
830
|
-
}
|
|
831
|
-
this.unmodified = unmodified;
|
|
832
|
-
this.constraining = false;
|
|
833
|
-
}
|
|
834
|
-
}, {
|
|
835
|
-
key: "calcMatrices",
|
|
836
|
-
value: function calcMatrices() {
|
|
837
|
-
if (!this.height) {
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
var halfFov = this._fov / 2;
|
|
841
|
-
var offset = this.centerOffset;
|
|
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');
|
|
952
|
-
}
|
|
953
|
-
// @ts-ignore
|
|
954
|
-
this.pixelMatrixInverse = m;
|
|
955
|
-
this.posMatrixCache = {};
|
|
956
|
-
this.alignedPosMatrixCache = {};
|
|
957
|
-
}
|
|
958
|
-
}]);
|
|
959
|
-
return Transform;
|
|
960
|
-
}();
|
|
961
|
-
export { Transform as default };
|