@antv/l7-map 2.25.6 → 2.25.7

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.
Files changed (159) hide show
  1. package/package.json +2 -2
  2. package/es/index.d.ts +0 -5
  3. package/es/index.js +0 -4
  4. package/es/map/camera.d.ts +0 -690
  5. package/es/map/camera.js +0 -1138
  6. package/es/map/css/l7.css +0 -171
  7. package/es/map/events.d.ts +0 -384
  8. package/es/map/events.js +0 -231
  9. package/es/map/geo/edge_insets.d.ts +0 -97
  10. package/es/map/geo/edge_insets.js +0 -115
  11. package/es/map/geo/lng_lat.d.ts +0 -116
  12. package/es/map/geo/lng_lat.js +0 -159
  13. package/es/map/geo/lng_lat_bounds.d.ts +0 -217
  14. package/es/map/geo/lng_lat_bounds.js +0 -334
  15. package/es/map/geo/mercator_coordinate.d.ts +0 -113
  16. package/es/map/geo/mercator_coordinate.js +0 -142
  17. package/es/map/geo/transform.d.ts +0 -262
  18. package/es/map/geo/transform.js +0 -736
  19. package/es/map/handler/box_zoom.d.ts +0 -65
  20. package/es/map/handler/box_zoom.js +0 -145
  21. package/es/map/handler/click_zoom.d.ts +0 -24
  22. package/es/map/handler/click_zoom.js +0 -47
  23. package/es/map/handler/cooperative_gestures.d.ts +0 -40
  24. package/es/map/handler/cooperative_gestures.js +0 -94
  25. package/es/map/handler/drag_handler.d.ts +0 -88
  26. package/es/map/handler/drag_handler.js +0 -89
  27. package/es/map/handler/drag_move_state_manager.d.ts +0 -30
  28. package/es/map/handler/drag_move_state_manager.js +0 -94
  29. package/es/map/handler/handler_util.d.ts +0 -3
  30. package/es/map/handler/handler_util.js +0 -8
  31. package/es/map/handler/keyboard.d.ts +0 -88
  32. package/es/map/handler/keyboard.js +0 -197
  33. package/es/map/handler/map_event.d.ts +0 -46
  34. package/es/map/handler/map_event.js +0 -131
  35. package/es/map/handler/mouse.d.ts +0 -30
  36. package/es/map/handler/mouse.js +0 -85
  37. package/es/map/handler/one_finger_touch_drag.d.ts +0 -15
  38. package/es/map/handler/one_finger_touch_drag.js +0 -39
  39. package/es/map/handler/scroll_zoom.d.ts +0 -102
  40. package/es/map/handler/scroll_zoom.js +0 -312
  41. package/es/map/handler/shim/dblclick_zoom.d.ts +0 -44
  42. package/es/map/handler/shim/dblclick_zoom.js +0 -60
  43. package/es/map/handler/shim/drag_pan.d.ts +0 -79
  44. package/es/map/handler/shim/drag_pan.js +0 -77
  45. package/es/map/handler/shim/drag_rotate.d.ts +0 -54
  46. package/es/map/handler/shim/drag_rotate.js +0 -66
  47. package/es/map/handler/shim/two_fingers_touch.d.ts +0 -74
  48. package/es/map/handler/shim/two_fingers_touch.js +0 -106
  49. package/es/map/handler/tap_drag_zoom.d.ts +0 -28
  50. package/es/map/handler/tap_drag_zoom.js +0 -92
  51. package/es/map/handler/tap_recognizer.d.ts +0 -35
  52. package/es/map/handler/tap_recognizer.js +0 -107
  53. package/es/map/handler/tap_zoom.d.ts +0 -28
  54. package/es/map/handler/tap_zoom.js +0 -87
  55. package/es/map/handler/touch_pan.d.ts +0 -40
  56. package/es/map/handler/touch_pan.js +0 -85
  57. package/es/map/handler/transform-provider.d.ts +0 -23
  58. package/es/map/handler/transform-provider.js +0 -35
  59. package/es/map/handler/two_fingers_touch.d.ts +0 -107
  60. package/es/map/handler/two_fingers_touch.js +0 -289
  61. package/es/map/handler_inertia.d.ts +0 -20
  62. package/es/map/handler_inertia.js +0 -128
  63. package/es/map/handler_manager.d.ts +0 -154
  64. package/es/map/handler_manager.js +0 -466
  65. package/es/map/map.d.ts +0 -637
  66. package/es/map/map.js +0 -984
  67. package/es/map/util/abort_error.d.ts +0 -15
  68. package/es/map/util/abort_error.js +0 -21
  69. package/es/map/util/browser.d.ts +0 -10
  70. package/es/map/util/browser.js +0 -30
  71. package/es/map/util/dom.d.ts +0 -30
  72. package/es/map/util/dom.js +0 -105
  73. package/es/map/util/evented.d.ts +0 -75
  74. package/es/map/util/evented.js +0 -158
  75. package/es/map/util/simpleMapCoord.d.ts +0 -31
  76. package/es/map/util/simpleMapCoord.js +0 -54
  77. package/es/map/util/task_queue.d.ts +0 -18
  78. package/es/map/util/task_queue.js +0 -54
  79. package/es/map/util/util.d.ts +0 -104
  80. package/es/map/util/util.js +0 -155
  81. package/lib/index.d.ts +0 -5
  82. package/lib/index.js +0 -33
  83. package/lib/map/camera.d.ts +0 -690
  84. package/lib/map/camera.js +0 -1145
  85. package/lib/map/css/l7.css +0 -171
  86. package/lib/map/events.d.ts +0 -384
  87. package/lib/map/events.js +0 -240
  88. package/lib/map/geo/edge_insets.d.ts +0 -97
  89. package/lib/map/geo/edge_insets.js +0 -122
  90. package/lib/map/geo/lng_lat.d.ts +0 -116
  91. package/lib/map/geo/lng_lat.js +0 -166
  92. package/lib/map/geo/lng_lat_bounds.d.ts +0 -217
  93. package/lib/map/geo/lng_lat_bounds.js +0 -341
  94. package/lib/map/geo/mercator_coordinate.d.ts +0 -113
  95. package/lib/map/geo/mercator_coordinate.js +0 -157
  96. package/lib/map/geo/transform.d.ts +0 -262
  97. package/lib/map/geo/transform.js +0 -744
  98. package/lib/map/handler/box_zoom.d.ts +0 -65
  99. package/lib/map/handler/box_zoom.js +0 -153
  100. package/lib/map/handler/click_zoom.d.ts +0 -24
  101. package/lib/map/handler/click_zoom.js +0 -54
  102. package/lib/map/handler/cooperative_gestures.d.ts +0 -40
  103. package/lib/map/handler/cooperative_gestures.js +0 -101
  104. package/lib/map/handler/drag_handler.d.ts +0 -88
  105. package/lib/map/handler/drag_handler.js +0 -97
  106. package/lib/map/handler/drag_move_state_manager.d.ts +0 -30
  107. package/lib/map/handler/drag_move_state_manager.js +0 -103
  108. package/lib/map/handler/handler_util.d.ts +0 -3
  109. package/lib/map/handler/handler_util.js +0 -14
  110. package/lib/map/handler/keyboard.d.ts +0 -88
  111. package/lib/map/handler/keyboard.js +0 -205
  112. package/lib/map/handler/map_event.d.ts +0 -46
  113. package/lib/map/handler/map_event.js +0 -140
  114. package/lib/map/handler/mouse.d.ts +0 -30
  115. package/lib/map/handler/mouse.js +0 -93
  116. package/lib/map/handler/one_finger_touch_drag.d.ts +0 -15
  117. package/lib/map/handler/one_finger_touch_drag.js +0 -47
  118. package/lib/map/handler/scroll_zoom.d.ts +0 -102
  119. package/lib/map/handler/scroll_zoom.js +0 -320
  120. package/lib/map/handler/shim/dblclick_zoom.d.ts +0 -44
  121. package/lib/map/handler/shim/dblclick_zoom.js +0 -68
  122. package/lib/map/handler/shim/drag_pan.d.ts +0 -79
  123. package/lib/map/handler/shim/drag_pan.js +0 -85
  124. package/lib/map/handler/shim/drag_rotate.d.ts +0 -54
  125. package/lib/map/handler/shim/drag_rotate.js +0 -74
  126. package/lib/map/handler/shim/two_fingers_touch.d.ts +0 -74
  127. package/lib/map/handler/shim/two_fingers_touch.js +0 -114
  128. package/lib/map/handler/tap_drag_zoom.d.ts +0 -28
  129. package/lib/map/handler/tap_drag_zoom.js +0 -99
  130. package/lib/map/handler/tap_recognizer.d.ts +0 -35
  131. package/lib/map/handler/tap_recognizer.js +0 -116
  132. package/lib/map/handler/tap_zoom.d.ts +0 -28
  133. package/lib/map/handler/tap_zoom.js +0 -94
  134. package/lib/map/handler/touch_pan.d.ts +0 -40
  135. package/lib/map/handler/touch_pan.js +0 -92
  136. package/lib/map/handler/transform-provider.d.ts +0 -23
  137. package/lib/map/handler/transform-provider.js +0 -43
  138. package/lib/map/handler/two_fingers_touch.d.ts +0 -107
  139. package/lib/map/handler/two_fingers_touch.js +0 -296
  140. package/lib/map/handler_inertia.d.ts +0 -20
  141. package/lib/map/handler_inertia.js +0 -136
  142. package/lib/map/handler_manager.d.ts +0 -154
  143. package/lib/map/handler_manager.js +0 -474
  144. package/lib/map/map.d.ts +0 -637
  145. package/lib/map/map.js +0 -991
  146. package/lib/map/util/abort_error.d.ts +0 -15
  147. package/lib/map/util/abort_error.js +0 -29
  148. package/lib/map/util/browser.d.ts +0 -10
  149. package/lib/map/util/browser.js +0 -36
  150. package/lib/map/util/dom.d.ts +0 -30
  151. package/lib/map/util/dom.js +0 -113
  152. package/lib/map/util/evented.d.ts +0 -75
  153. package/lib/map/util/evented.js +0 -167
  154. package/lib/map/util/simpleMapCoord.d.ts +0 -31
  155. package/lib/map/util/simpleMapCoord.js +0 -62
  156. package/lib/map/util/task_queue.d.ts +0 -18
  157. package/lib/map/util/task_queue.js +0 -62
  158. package/lib/map/util/util.d.ts +0 -104
  159. package/lib/map/util/util.js +0 -171
@@ -1,744 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.Transform = exports.MAX_VALID_LATITUDE = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _pointGeometry = _interopRequireDefault(require("@mapbox/point-geometry"));
10
- var _glMatrix = require("gl-matrix");
11
- var _util = require("../util/util");
12
- var _edge_insets = require("./edge_insets");
13
- var _lng_lat = require("./lng_lat");
14
- var _lng_lat_bounds = require("./lng_lat_bounds");
15
- var _mercator_coordinate = require("./mercator_coordinate");
16
- const MAX_VALID_LATITUDE = exports.MAX_VALID_LATITUDE = 85.051129;
17
-
18
- /**
19
- * @internal
20
- * A single transform, generally used for a single tile to be
21
- * scaled, rotated, and zoomed.
22
- */
23
- class Transform {
24
- constructor(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies) {
25
- (0, _defineProperty2.default)(this, "tileSize", void 0);
26
- (0, _defineProperty2.default)(this, "tileZoom", void 0);
27
- (0, _defineProperty2.default)(this, "lngRange", void 0);
28
- (0, _defineProperty2.default)(this, "latRange", void 0);
29
- (0, _defineProperty2.default)(this, "scale", void 0);
30
- (0, _defineProperty2.default)(this, "width", void 0);
31
- (0, _defineProperty2.default)(this, "height", void 0);
32
- (0, _defineProperty2.default)(this, "angle", void 0);
33
- (0, _defineProperty2.default)(this, "rotationMatrix", void 0);
34
- (0, _defineProperty2.default)(this, "pixelsToGLUnits", void 0);
35
- (0, _defineProperty2.default)(this, "cameraToCenterDistance", void 0);
36
- (0, _defineProperty2.default)(this, "mercatorMatrix", void 0);
37
- (0, _defineProperty2.default)(this, "projMatrix", void 0);
38
- (0, _defineProperty2.default)(this, "invProjMatrix", void 0);
39
- (0, _defineProperty2.default)(this, "alignedProjMatrix", void 0);
40
- (0, _defineProperty2.default)(this, "pixelMatrix", void 0);
41
- (0, _defineProperty2.default)(this, "pixelMatrix3D", void 0);
42
- (0, _defineProperty2.default)(this, "pixelMatrixInverse", void 0);
43
- (0, _defineProperty2.default)(this, "glCoordMatrix", void 0);
44
- (0, _defineProperty2.default)(this, "labelPlaneMatrix", void 0);
45
- (0, _defineProperty2.default)(this, "minElevationForCurrentTile", void 0);
46
- (0, _defineProperty2.default)(this, "_fov", void 0);
47
- (0, _defineProperty2.default)(this, "_pitch", void 0);
48
- (0, _defineProperty2.default)(this, "_zoom", void 0);
49
- (0, _defineProperty2.default)(this, "_unmodified", void 0);
50
- (0, _defineProperty2.default)(this, "_renderWorldCopies", void 0);
51
- (0, _defineProperty2.default)(this, "_minZoom", void 0);
52
- (0, _defineProperty2.default)(this, "_maxZoom", void 0);
53
- (0, _defineProperty2.default)(this, "_minPitch", void 0);
54
- (0, _defineProperty2.default)(this, "_maxPitch", void 0);
55
- (0, _defineProperty2.default)(this, "_center", void 0);
56
- (0, _defineProperty2.default)(this, "_elevation", void 0);
57
- (0, _defineProperty2.default)(this, "_pixelPerMeter", void 0);
58
- (0, _defineProperty2.default)(this, "_edgeInsets", void 0);
59
- (0, _defineProperty2.default)(this, "_constraining", void 0);
60
- (0, _defineProperty2.default)(this, "_posMatrixCache", void 0);
61
- (0, _defineProperty2.default)(this, "_alignedPosMatrixCache", void 0);
62
- this.tileSize = 512; // constant
63
-
64
- this._renderWorldCopies = renderWorldCopies === undefined ? true : !!renderWorldCopies;
65
- this._minZoom = minZoom || 0;
66
- this._maxZoom = maxZoom || 22;
67
- this._minPitch = minPitch === undefined || minPitch === null ? 0 : minPitch;
68
- this._maxPitch = maxPitch === undefined || maxPitch === null ? 60 : maxPitch;
69
- this.setMaxBounds();
70
- this.width = 0;
71
- this.height = 0;
72
- this._center = new _lng_lat.LngLat(0, 0);
73
- this._elevation = 0;
74
- this.zoom = 0;
75
- this.angle = 0;
76
- this._fov = 0.6435011087932844;
77
- this._pitch = 0;
78
- this._unmodified = true;
79
- this._edgeInsets = new _edge_insets.EdgeInsets();
80
- this._posMatrixCache = {};
81
- this._alignedPosMatrixCache = {};
82
- this.minElevationForCurrentTile = 0;
83
- }
84
- clone() {
85
- const clone = new Transform(this._minZoom, this._maxZoom, this._minPitch, this.maxPitch, this._renderWorldCopies);
86
- clone.apply(this);
87
- return clone;
88
- }
89
- apply(that) {
90
- this.tileSize = that.tileSize;
91
- this.latRange = that.latRange;
92
- this.width = that.width;
93
- this.height = that.height;
94
- this._center = that._center;
95
- this._elevation = that._elevation;
96
- this.minElevationForCurrentTile = that.minElevationForCurrentTile;
97
- this.zoom = that.zoom;
98
- this.angle = that.angle;
99
- this._fov = that._fov;
100
- this._pitch = that._pitch;
101
- this._unmodified = that._unmodified;
102
- this._edgeInsets = that._edgeInsets.clone();
103
- this._calcMatrices();
104
- }
105
- get minZoom() {
106
- return this._minZoom;
107
- }
108
- set minZoom(zoom) {
109
- if (this._minZoom === zoom) return;
110
- this._minZoom = zoom;
111
- this.zoom = Math.max(this.zoom, zoom);
112
- }
113
- get maxZoom() {
114
- return this._maxZoom;
115
- }
116
- set maxZoom(zoom) {
117
- if (this._maxZoom === zoom) return;
118
- this._maxZoom = zoom;
119
- this.zoom = Math.min(this.zoom, zoom);
120
- }
121
- get minPitch() {
122
- return this._minPitch;
123
- }
124
- set minPitch(pitch) {
125
- if (this._minPitch === pitch) return;
126
- this._minPitch = pitch;
127
- this.pitch = Math.max(this.pitch, pitch);
128
- }
129
- get maxPitch() {
130
- return this._maxPitch;
131
- }
132
- set maxPitch(pitch) {
133
- if (this._maxPitch === pitch) return;
134
- this._maxPitch = pitch;
135
- this.pitch = Math.min(this.pitch, pitch);
136
- }
137
- get renderWorldCopies() {
138
- return this._renderWorldCopies;
139
- }
140
- set renderWorldCopies(renderWorldCopies) {
141
- if (renderWorldCopies === undefined) {
142
- renderWorldCopies = true;
143
- } else if (renderWorldCopies === null) {
144
- renderWorldCopies = false;
145
- }
146
- this._renderWorldCopies = renderWorldCopies;
147
- }
148
- get worldSize() {
149
- return this.tileSize * this.scale;
150
- }
151
- get centerOffset() {
152
- return this.centerPoint._sub(this.size._div(2));
153
- }
154
- get size() {
155
- return new _pointGeometry.default(this.width, this.height);
156
- }
157
- get bearing() {
158
- return -this.angle / Math.PI * 180;
159
- }
160
- set bearing(bearing) {
161
- const b = -(0, _util.wrap)(bearing, -180, 180) * Math.PI / 180;
162
- if (this.angle === b) return;
163
- this._unmodified = false;
164
- this.angle = b;
165
- this._calcMatrices();
166
-
167
- // 2x2 matrix for rotating points
168
- this.rotationMatrix = _glMatrix.mat2.create();
169
- _glMatrix.mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);
170
- }
171
- get pitch() {
172
- return this._pitch / Math.PI * 180;
173
- }
174
- set pitch(pitch) {
175
- const p = (0, _util.clamp)(pitch, this.minPitch, this.maxPitch) / 180 * Math.PI;
176
- if (this._pitch === p) return;
177
- this._unmodified = false;
178
- this._pitch = p;
179
- this._calcMatrices();
180
- }
181
- get fov() {
182
- return this._fov / Math.PI * 180;
183
- }
184
- set fov(fov) {
185
- fov = Math.max(0.01, Math.min(60, fov));
186
- if (this._fov === fov) return;
187
- this._unmodified = false;
188
- this._fov = fov / 180 * Math.PI;
189
- this._calcMatrices();
190
- }
191
- get zoom() {
192
- return this._zoom;
193
- }
194
- set zoom(zoom) {
195
- const constrainedZoom = Math.min(Math.max(zoom, this.minZoom), this.maxZoom);
196
- if (this._zoom === constrainedZoom) return;
197
- this._unmodified = false;
198
- this._zoom = constrainedZoom;
199
- this.tileZoom = Math.max(0, Math.floor(constrainedZoom));
200
- this.scale = this.zoomScale(constrainedZoom);
201
- this._constrain();
202
- this._calcMatrices();
203
- }
204
- get center() {
205
- return this._center;
206
- }
207
- set center(center) {
208
- if (center.lat === this._center.lat && center.lng === this._center.lng) return;
209
- this._unmodified = false;
210
- this._center = center;
211
- this._constrain();
212
- this._calcMatrices();
213
- }
214
-
215
- /**
216
- * Elevation at current center point, meters above sea level
217
- */
218
- get elevation() {
219
- return this._elevation;
220
- }
221
- set elevation(elevation) {
222
- if (elevation === this._elevation) return;
223
- this._elevation = elevation;
224
- this._constrain();
225
- this._calcMatrices();
226
- }
227
- get padding() {
228
- return this._edgeInsets.toJSON();
229
- }
230
- set padding(padding) {
231
- if (this._edgeInsets.equals(padding)) return;
232
- this._unmodified = false;
233
- //Update edge-insets inplace
234
- this._edgeInsets.interpolate(this._edgeInsets, padding, 1);
235
- this._calcMatrices();
236
- }
237
-
238
- /**
239
- * The center of the screen in pixels with the top-left corner being (0,0)
240
- * and +y axis pointing downwards. This accounts for padding.
241
- */
242
- get centerPoint() {
243
- return this._edgeInsets.getCenter(this.width, this.height);
244
- }
245
-
246
- /**
247
- * Returns if the padding params match
248
- *
249
- * @param padding - the padding to check against
250
- * @returns true if they are equal, false otherwise
251
- */
252
- isPaddingEqual(padding) {
253
- return this._edgeInsets.equals(padding);
254
- }
255
-
256
- /**
257
- * Helper method to update edge-insets in place
258
- *
259
- * @param start - the starting padding
260
- * @param target - the target padding
261
- * @param t - the step/weight
262
- */
263
- interpolatePadding(start, target, t) {
264
- this._unmodified = false;
265
- this._edgeInsets.interpolate(start, target, t);
266
- this._constrain();
267
- this._calcMatrices();
268
- }
269
-
270
- /**
271
- * Return a zoom level that will cover all tiles the transform
272
- * @param options - the options
273
- * @returns 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
- }
280
- resize(width, height) {
281
- this.width = width;
282
- this.height = height;
283
- this.pixelsToGLUnits = [2 / width, -2 / height];
284
- this._constrain();
285
- this._calcMatrices();
286
- }
287
- get unmodified() {
288
- return this._unmodified;
289
- }
290
- zoomScale(zoom) {
291
- return Math.pow(2, zoom);
292
- }
293
- scaleZoom(scale) {
294
- return Math.log(scale) / Math.LN2;
295
- }
296
-
297
- /**
298
- * Convert from LngLat to world coordinates (Mercator coordinates scaled by 512)
299
- * @param lnglat - the lngLat
300
- * @returns Point
301
- */
302
- project(lnglat) {
303
- const lat = (0, _util.clamp)(lnglat.lat, -MAX_VALID_LATITUDE, MAX_VALID_LATITUDE);
304
- return new _pointGeometry.default((0, _mercator_coordinate.mercatorXfromLng)(lnglat.lng) * this.worldSize, (0, _mercator_coordinate.mercatorYfromLat)(lat) * this.worldSize);
305
- }
306
-
307
- /**
308
- * Convert from world coordinates ([0, 512],[0, 512]) to LngLat ([-180, 180], [-90, 90])
309
- * @param point - world coordinate
310
- * @returns LngLat
311
- */
312
- unproject(point) {
313
- return new _mercator_coordinate.MercatorCoordinate(point.x / this.worldSize, point.y / this.worldSize).toLngLat();
314
- }
315
- get point() {
316
- return this.project(this.center);
317
- }
318
-
319
- /**
320
- * get the camera position in LngLat and altitudes in meter
321
- * @returns An object with lngLat & altitude.
322
- */
323
- getCameraPosition() {
324
- const lngLat = this.pointLocation(this.getCameraPoint());
325
- const altitude = Math.cos(this._pitch) * this.cameraToCenterDistance / this._pixelPerMeter;
326
- return {
327
- lngLat,
328
- altitude: altitude + this.elevation
329
- };
330
- }
331
- setLocationAtPoint(lnglat, point) {
332
- const a = this.pointCoordinate(point);
333
- const b = this.pointCoordinate(this.centerPoint);
334
- const loc = this.locationCoordinate(lnglat);
335
- const newCenter = new _mercator_coordinate.MercatorCoordinate(loc.x - (a.x - b.x), loc.y - (a.y - b.y));
336
- this.center = this.coordinateLocation(newCenter);
337
- if (this._renderWorldCopies) {
338
- this.center = this.center.wrap();
339
- }
340
- }
341
-
342
- /**
343
- * Given a LngLat location, return the screen point that corresponds to it
344
- * @param lnglat - location
345
- * @param terrain - optional terrain
346
- * @returns screen point
347
- */
348
- locationPoint(lnglat) {
349
- return this.coordinatePoint(this.locationCoordinate(lnglat));
350
- }
351
-
352
- /**
353
- * Given a point on screen, return its lnglat
354
- * @param p - screen point
355
- * @param terrain - optional terrain
356
- * @returns lnglat location
357
- */
358
- pointLocation(p) {
359
- return this.coordinateLocation(this.pointCoordinate(p));
360
- }
361
-
362
- /**
363
- * Given a geographical lnglat, return an unrounded
364
- * coordinate that represents it at low zoom level.
365
- * @param lnglat - the location
366
- * @returns The mercator coordinate
367
- */
368
- locationCoordinate(lnglat) {
369
- return _mercator_coordinate.MercatorCoordinate.fromLngLat(lnglat);
370
- }
371
-
372
- /**
373
- * Given a Coordinate, return its geographical position.
374
- * @param coord - mercator coordinates
375
- * @returns lng and lat
376
- */
377
- coordinateLocation(coord) {
378
- return coord && coord.toLngLat();
379
- }
380
-
381
- /**
382
- * Given a Point, return its mercator coordinate.
383
- * @param p - the point
384
- * @param terrain - optional terrain
385
- * @returns lnglat
386
- */
387
- pointCoordinate(p) {
388
- // calculate point-coordinate on flat earth
389
- const targetZ = 0;
390
- // since we don't know the correct projected z value for the point,
391
- // unproject two points to get a line and then find the point on that
392
- // line with z=0
393
-
394
- const coord0 = [p.x, p.y, 0, 1];
395
- const coord1 = [p.x, p.y, 1, 1];
396
- _glMatrix.vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);
397
- _glMatrix.vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);
398
- const w0 = coord0[3];
399
- const w1 = coord1[3];
400
- const x0 = coord0[0] / w0;
401
- const x1 = coord1[0] / w1;
402
- const y0 = coord0[1] / w0;
403
- const y1 = coord1[1] / w1;
404
- const z0 = coord0[2] / w0;
405
- const z1 = coord1[2] / w1;
406
- const t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);
407
- return new _mercator_coordinate.MercatorCoordinate(_util.interpolates.number(x0, x1, t) / this.worldSize, _util.interpolates.number(y0, y1, t) / this.worldSize);
408
- }
409
-
410
- /**
411
- * Given a coordinate, return the screen point that corresponds to it
412
- * @param coord - the coordinates
413
- * @param elevation - the elevation
414
- * @param pixelMatrix - the pixel matrix
415
- * @returns screen point
416
- */
417
- coordinatePoint(coord, elevation = 0, pixelMatrix = this.pixelMatrix) {
418
- const p = [coord.x * this.worldSize, coord.y * this.worldSize, elevation, 1];
419
- _glMatrix.vec4.transformMat4(p, p, pixelMatrix);
420
- return new _pointGeometry.default(p[0] / p[3], p[1] / p[3]);
421
- }
422
-
423
- /**
424
- * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
425
- * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
426
- * @returns Returns a {@link LngLatBounds} object describing the map's geographical bounds.
427
- */
428
- getBounds() {
429
- const top = Math.max(0, this.height / 2 - this.getHorizon());
430
- return new _lng_lat_bounds.LngLatBounds().extend(this.pointLocation(new _pointGeometry.default(0, top))).extend(this.pointLocation(new _pointGeometry.default(this.width, top))).extend(this.pointLocation(new _pointGeometry.default(this.width, this.height))).extend(this.pointLocation(new _pointGeometry.default(0, this.height)));
431
- }
432
-
433
- /**
434
- * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
435
- * @returns max bounds
436
- */
437
- getMaxBounds() {
438
- if (!this.latRange || this.latRange.length !== 2 || !this.lngRange || this.lngRange.length !== 2) return null;
439
- return new _lng_lat_bounds.LngLatBounds([this.lngRange[0], this.latRange[0]], [this.lngRange[1], this.latRange[1]]);
440
- }
441
-
442
- /**
443
- * Calculate pixel height of the visible horizon in relation to map-center (e.g. height/2),
444
- * multiplied by a static factor to simulate the earth-radius.
445
- * The calculated value is the horizontal line from the camera-height to sea-level.
446
- * @returns Horizon above center in pixels.
447
- */
448
- getHorizon() {
449
- return Math.tan(Math.PI / 2 - this._pitch) * this.cameraToCenterDistance * 0.85;
450
- }
451
-
452
- /**
453
- * Sets or clears the map's geographical constraints.
454
- * @param bounds - A {@link LngLatBounds} object describing the new geographic boundaries of the map.
455
- */
456
- setMaxBounds(bounds) {
457
- if (bounds) {
458
- this.lngRange = [bounds.getWest(), bounds.getEast()];
459
- this.latRange = [bounds.getSouth(), bounds.getNorth()];
460
- this._constrain();
461
- } else {
462
- this.lngRange = null;
463
- this.latRange = [-MAX_VALID_LATITUDE, MAX_VALID_LATITUDE];
464
- }
465
- }
466
- customLayerMatrix() {
467
- return _glMatrix.mat4.clone(this.mercatorMatrix);
468
- }
469
-
470
- /**
471
- * Get center lngLat and zoom to ensure that
472
- * 1) everything beyond the bounds is excluded
473
- * 2) a given lngLat is as near the center as possible
474
- * Bounds are those set by maxBounds or North & South "Poles" and, if only 1 globe is displayed, antimeridian.
475
- */
476
- getConstrained(lngLat, zoom) {
477
- zoom = (0, _util.clamp)(+zoom, this.minZoom, this.maxZoom);
478
- const result = {
479
- center: new _lng_lat.LngLat(lngLat.lng, lngLat.lat),
480
- zoom
481
- };
482
- let lngRange = this.lngRange;
483
- if (!this._renderWorldCopies && lngRange === null) {
484
- const almost180 = 180 - 1e-10;
485
- lngRange = [-almost180, almost180];
486
- }
487
- const worldSize = this.tileSize * this.zoomScale(result.zoom); // A world size for the requested zoom level, not the current world size
488
- let minY = 0;
489
- let maxY = worldSize;
490
- let minX = 0;
491
- let maxX = worldSize;
492
- let scaleY = 0;
493
- let scaleX = 0;
494
- const {
495
- x: screenWidth,
496
- y: screenHeight
497
- } = this.size;
498
- if (this.latRange) {
499
- const latRange = this.latRange;
500
- minY = (0, _mercator_coordinate.mercatorYfromLat)(latRange[1]) * worldSize;
501
- maxY = (0, _mercator_coordinate.mercatorYfromLat)(latRange[0]) * worldSize;
502
- const shouldZoomIn = maxY - minY < screenHeight;
503
- if (shouldZoomIn) scaleY = screenHeight / (maxY - minY);
504
- }
505
- if (lngRange) {
506
- minX = (0, _util.wrap)((0, _mercator_coordinate.mercatorXfromLng)(lngRange[0]) * worldSize, 0, worldSize);
507
- maxX = (0, _util.wrap)((0, _mercator_coordinate.mercatorXfromLng)(lngRange[1]) * worldSize, 0, worldSize);
508
- if (maxX < minX) maxX += worldSize;
509
- const shouldZoomIn = maxX - minX < screenWidth;
510
- if (shouldZoomIn) scaleX = screenWidth / (maxX - minX);
511
- }
512
- const {
513
- x: originalX,
514
- y: originalY
515
- } = this.project.call({
516
- worldSize
517
- }, lngLat);
518
- let modifiedX, modifiedY;
519
- const scale = Math.max(scaleX || 0, scaleY || 0);
520
- if (scale) {
521
- // zoom in to exclude all beyond the given lng/lat ranges
522
- const newPoint = new _pointGeometry.default(scaleX ? (maxX + minX) / 2 : originalX, scaleY ? (maxY + minY) / 2 : originalY);
523
- result.center = this.unproject.call({
524
- worldSize
525
- }, newPoint).wrap();
526
- result.zoom += this.scaleZoom(scale);
527
- return result;
528
- }
529
- if (this.latRange) {
530
- const h2 = screenHeight / 2;
531
- if (originalY - h2 < minY) modifiedY = minY + h2;
532
- if (originalY + h2 > maxY) modifiedY = maxY - h2;
533
- }
534
- if (lngRange) {
535
- const centerX = (minX + maxX) / 2;
536
- let wrappedX = originalX;
537
- if (this._renderWorldCopies) {
538
- wrappedX = (0, _util.wrap)(originalX, centerX - worldSize / 2, centerX + worldSize / 2);
539
- }
540
- const w2 = screenWidth / 2;
541
- if (wrappedX - w2 < minX) modifiedX = minX + w2;
542
- if (wrappedX + w2 > maxX) modifiedX = maxX - w2;
543
- }
544
-
545
- // pan the map if the screen goes off the range
546
- if (modifiedX !== undefined || modifiedY !== undefined) {
547
- var _modifiedX, _modifiedY;
548
- const newPoint = new _pointGeometry.default((_modifiedX = modifiedX) !== null && _modifiedX !== void 0 ? _modifiedX : originalX, (_modifiedY = modifiedY) !== null && _modifiedY !== void 0 ? _modifiedY : originalY);
549
- result.center = this.unproject.call({
550
- worldSize
551
- }, newPoint).wrap();
552
- }
553
- return result;
554
- }
555
- _constrain() {
556
- if (!this.center || !this.width || !this.height || this._constraining) return;
557
- this._constraining = true;
558
- const unmodified = this._unmodified;
559
- const {
560
- center,
561
- zoom
562
- } = this.getConstrained(this.center, this.zoom);
563
- this.center = center;
564
- this.zoom = zoom;
565
- this._unmodified = unmodified;
566
- this._constraining = false;
567
- }
568
- _calcMatrices() {
569
- if (!this.height) return;
570
- const halfFov = this._fov / 2;
571
- const offset = this.centerOffset;
572
- const x = this.point.x,
573
- y = this.point.y;
574
- this.cameraToCenterDistance = 0.5 / Math.tan(halfFov) * this.height;
575
- this._pixelPerMeter = (0, _mercator_coordinate.mercatorZfromAltitude)(1, this.center.lat) * this.worldSize;
576
- let m = _glMatrix.mat4.identity(new Float64Array(16));
577
- _glMatrix.mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);
578
- _glMatrix.mat4.translate(m, m, [1, -1, 0]);
579
- this.labelPlaneMatrix = m;
580
- m = _glMatrix.mat4.identity(new Float64Array(16));
581
- _glMatrix.mat4.scale(m, m, [1, -1, 1]);
582
- _glMatrix.mat4.translate(m, m, [-1, -1, 0]);
583
- _glMatrix.mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);
584
- this.glCoordMatrix = m;
585
-
586
- // Calculate the camera to sea-level distance in pixel in respect of terrain
587
- const cameraToSeaLevelDistance = this.cameraToCenterDistance + this._elevation * this._pixelPerMeter / Math.cos(this._pitch);
588
- // In case of negative minimum elevation (e.g. the dead see, under the sea maps) use a lower plane for calculation
589
- const minElevation = Math.min(this.elevation, this.minElevationForCurrentTile);
590
- const cameraToLowestPointDistance = cameraToSeaLevelDistance - minElevation * this._pixelPerMeter / Math.cos(this._pitch);
591
- const lowestPlane = minElevation < 0 ? cameraToLowestPointDistance : cameraToSeaLevelDistance;
592
-
593
- // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the
594
- // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.
595
- // 1 Z unit is equivalent to 1 horizontal px at the center of the map
596
- // (the distance between[width/2, height/2] and [width/2 + 1, height/2])
597
- const groundAngle = Math.PI / 2 + this._pitch;
598
- const fovAboveCenter = this._fov * (0.5 + offset.y / this.height);
599
- const topHalfSurfaceDistance = Math.sin(fovAboveCenter) * lowestPlane / Math.sin((0, _util.clamp)(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01));
600
-
601
- // Find the distance from the center point to the horizon
602
- const horizon = this.getHorizon();
603
- const horizonAngle = Math.atan(horizon / this.cameraToCenterDistance);
604
- const fovCenterToHorizon = 2 * horizonAngle * (0.5 + offset.y / (horizon * 2));
605
- const topHalfSurfaceDistanceHorizon = Math.sin(fovCenterToHorizon) * lowestPlane / Math.sin((0, _util.clamp)(Math.PI - groundAngle - fovCenterToHorizon, 0.01, Math.PI - 0.01));
606
-
607
- // Calculate z distance of the farthest fragment that should be rendered.
608
- // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
609
- const topHalfMinDistance = Math.min(topHalfSurfaceDistance, topHalfSurfaceDistanceHorizon);
610
- const farZ = (Math.cos(Math.PI / 2 - this._pitch) * topHalfMinDistance + lowestPlane) * 1.01;
611
-
612
- // The larger the value of nearZ is
613
- // - the more depth precision is available for features (good)
614
- // - clipping starts appearing sooner when the camera is close to 3d features (bad)
615
- //
616
- // Other values work for mapbox-gl-js but deckgl was encountering precision issues
617
- // when rendering custom layers. This value was experimentally chosen and
618
- // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.
619
- const nearZ = this.height / 50;
620
-
621
- // matrix for conversion from location to clip space(-1 .. 1)
622
- m = new Float64Array(16);
623
- _glMatrix.mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);
624
-
625
- // Apply center of perspective offset
626
- m[8] = -offset.x * 2 / this.width;
627
- m[9] = offset.y * 2 / this.height;
628
- _glMatrix.mat4.scale(m, m, [1, -1, 1]);
629
- _glMatrix.mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);
630
- _glMatrix.mat4.rotateX(m, m, this._pitch);
631
- _glMatrix.mat4.rotateZ(m, m, this.angle);
632
- _glMatrix.mat4.translate(m, m, [-x, -y, 0]);
633
-
634
- // The mercatorMatrix can be used to transform points from mercator coordinates
635
- // ([0, 0] nw, [1, 1] se) to clip space.
636
- this.mercatorMatrix = _glMatrix.mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]);
637
-
638
- // scale vertically to meters per pixel (inverse of ground resolution):
639
- _glMatrix.mat4.scale(m, m, [1, 1, this._pixelPerMeter]);
640
-
641
- // matrix for conversion from world space to screen coordinates in 2D
642
- this.pixelMatrix = _glMatrix.mat4.multiply(new Float64Array(16), this.labelPlaneMatrix, m);
643
-
644
- // matrix for conversion from world space to clip space (-1 .. 1)
645
- _glMatrix.mat4.translate(m, m, [0, 0, -this.elevation]); // elevate camera over terrain
646
- this.projMatrix = m;
647
- this.invProjMatrix = _glMatrix.mat4.invert([], m);
648
-
649
- // matrix for conversion from world space to screen coordinates in 3D
650
- this.pixelMatrix3D = _glMatrix.mat4.multiply(new Float64Array(16), this.labelPlaneMatrix, m);
651
-
652
- // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.
653
- // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional
654
- // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension
655
- // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle
656
- // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that
657
- // it is always <= 0.5 pixels.
658
- const xShift = this.width % 2 / 2,
659
- yShift = this.height % 2 / 2,
660
- angleCos = Math.cos(this.angle),
661
- angleSin = Math.sin(this.angle),
662
- dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift,
663
- dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
664
- const alignedM = new Float64Array(m);
665
- _glMatrix.mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]);
666
- this.alignedProjMatrix = alignedM;
667
-
668
- // inverse matrix for conversion from screen coordinates to location
669
- m = _glMatrix.mat4.invert(new Float64Array(16), this.pixelMatrix);
670
- if (!m) throw new Error('failed to invert matrix');
671
- this.pixelMatrixInverse = m;
672
- this._posMatrixCache = {};
673
- this._alignedPosMatrixCache = {};
674
- }
675
- maxPitchScaleFactor() {
676
- // calcMatrices hasn't run yet
677
- if (!this.pixelMatrixInverse) return 1;
678
- const coord = this.pointCoordinate(new _pointGeometry.default(0, 0));
679
- const p = [coord.x * this.worldSize, coord.y * this.worldSize, 0, 1];
680
- const topPoint = _glMatrix.vec4.transformMat4(p, p, this.pixelMatrix);
681
- return topPoint[3] / this.cameraToCenterDistance;
682
- }
683
-
684
- /**
685
- * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`
686
- * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).
687
- * `cameraPoint` is the projected position of the `cameraLocation`.
688
- *
689
- * This point is useful to us because only fill-extrusions that are between `cameraPoint` and
690
- * the query point on the surface of the earth can extend and intersect the query.
691
- *
692
- * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because
693
- * the camera is right above the center of the map.
694
- */
695
- getCameraPoint() {
696
- const pitch = this._pitch;
697
- const yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);
698
- return this.centerPoint.add(new _pointGeometry.default(0, yOffset));
699
- }
700
-
701
- /**
702
- * When the map is pitched, some of the 3D features that intersect a query will not intersect
703
- * the query at the surface of the earth. Instead the feature may be closer and only intersect
704
- * the query because it extrudes into the air.
705
- * @param queryGeometry - For point queries, the line from the query point to the "camera point",
706
- * for other geometries, the envelope of the query geometry and the "camera point"
707
- * @returns a geometry that includes all of the original query as well as all possible ares of the
708
- * screen where the *base* of a visible extrusion could be.
709
- *
710
- */
711
- getCameraQueryGeometry(queryGeometry) {
712
- const c = this.getCameraPoint();
713
- if (queryGeometry.length === 1) {
714
- return [queryGeometry[0], c];
715
- } else {
716
- let minX = c.x;
717
- let minY = c.y;
718
- let maxX = c.x;
719
- let maxY = c.y;
720
- for (const p of queryGeometry) {
721
- minX = Math.min(minX, p.x);
722
- minY = Math.min(minY, p.y);
723
- maxX = Math.max(maxX, p.x);
724
- maxY = Math.max(maxY, p.y);
725
- }
726
- return [new _pointGeometry.default(minX, minY), new _pointGeometry.default(maxX, minY), new _pointGeometry.default(maxX, maxY), new _pointGeometry.default(minX, maxY), new _pointGeometry.default(minX, minY)];
727
- }
728
- }
729
- /**
730
- * Return the distance to the camera in clip space from a LngLat.
731
- * This can be compared to the value from the depth buffer (terrain.depthAtPoint)
732
- * to determine whether a point is occluded.
733
- * @param lngLat - the point
734
- * @param elevation - the point's elevation
735
- * @returns depth value in clip space (between 0 and 1)
736
- */
737
- lngLatToCameraDepth(lngLat, elevation) {
738
- const coord = this.locationCoordinate(lngLat);
739
- const p = [coord.x * this.worldSize, coord.y * this.worldSize, elevation, 1];
740
- _glMatrix.vec4.transformMat4(p, p, this.projMatrix);
741
- return p[2] / p[3];
742
- }
743
- }
744
- exports.Transform = Transform;