@antv/l7-map 2.25.7 → 2.25.9

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/es/index.d.ts +5 -0
  2. package/es/index.js +4 -0
  3. package/es/map/camera.d.ts +690 -0
  4. package/es/map/camera.js +1138 -0
  5. package/es/map/css/l7.css +171 -0
  6. package/es/map/events.d.ts +384 -0
  7. package/es/map/events.js +231 -0
  8. package/es/map/geo/edge_insets.d.ts +97 -0
  9. package/es/map/geo/edge_insets.js +115 -0
  10. package/es/map/geo/lng_lat.d.ts +116 -0
  11. package/es/map/geo/lng_lat.js +159 -0
  12. package/es/map/geo/lng_lat_bounds.d.ts +217 -0
  13. package/es/map/geo/lng_lat_bounds.js +334 -0
  14. package/es/map/geo/mercator_coordinate.d.ts +113 -0
  15. package/es/map/geo/mercator_coordinate.js +142 -0
  16. package/es/map/geo/transform.d.ts +262 -0
  17. package/es/map/geo/transform.js +736 -0
  18. package/es/map/handler/box_zoom.d.ts +65 -0
  19. package/es/map/handler/box_zoom.js +145 -0
  20. package/es/map/handler/click_zoom.d.ts +24 -0
  21. package/es/map/handler/click_zoom.js +47 -0
  22. package/es/map/handler/cooperative_gestures.d.ts +40 -0
  23. package/es/map/handler/cooperative_gestures.js +94 -0
  24. package/es/map/handler/drag_handler.d.ts +88 -0
  25. package/es/map/handler/drag_handler.js +89 -0
  26. package/es/map/handler/drag_move_state_manager.d.ts +30 -0
  27. package/es/map/handler/drag_move_state_manager.js +94 -0
  28. package/es/map/handler/handler_util.d.ts +3 -0
  29. package/es/map/handler/handler_util.js +8 -0
  30. package/es/map/handler/keyboard.d.ts +88 -0
  31. package/es/map/handler/keyboard.js +197 -0
  32. package/es/map/handler/map_event.d.ts +46 -0
  33. package/es/map/handler/map_event.js +131 -0
  34. package/es/map/handler/mouse.d.ts +30 -0
  35. package/es/map/handler/mouse.js +85 -0
  36. package/es/map/handler/one_finger_touch_drag.d.ts +15 -0
  37. package/es/map/handler/one_finger_touch_drag.js +39 -0
  38. package/es/map/handler/scroll_zoom.d.ts +102 -0
  39. package/es/map/handler/scroll_zoom.js +312 -0
  40. package/es/map/handler/shim/dblclick_zoom.d.ts +44 -0
  41. package/es/map/handler/shim/dblclick_zoom.js +60 -0
  42. package/es/map/handler/shim/drag_pan.d.ts +79 -0
  43. package/es/map/handler/shim/drag_pan.js +77 -0
  44. package/es/map/handler/shim/drag_rotate.d.ts +54 -0
  45. package/es/map/handler/shim/drag_rotate.js +66 -0
  46. package/es/map/handler/shim/two_fingers_touch.d.ts +74 -0
  47. package/es/map/handler/shim/two_fingers_touch.js +106 -0
  48. package/es/map/handler/tap_drag_zoom.d.ts +28 -0
  49. package/es/map/handler/tap_drag_zoom.js +92 -0
  50. package/es/map/handler/tap_recognizer.d.ts +35 -0
  51. package/es/map/handler/tap_recognizer.js +107 -0
  52. package/es/map/handler/tap_zoom.d.ts +28 -0
  53. package/es/map/handler/tap_zoom.js +87 -0
  54. package/es/map/handler/touch_pan.d.ts +40 -0
  55. package/es/map/handler/touch_pan.js +85 -0
  56. package/es/map/handler/transform-provider.d.ts +23 -0
  57. package/es/map/handler/transform-provider.js +35 -0
  58. package/es/map/handler/two_fingers_touch.d.ts +107 -0
  59. package/es/map/handler/two_fingers_touch.js +289 -0
  60. package/es/map/handler_inertia.d.ts +20 -0
  61. package/es/map/handler_inertia.js +128 -0
  62. package/es/map/handler_manager.d.ts +154 -0
  63. package/es/map/handler_manager.js +466 -0
  64. package/es/map/map.d.ts +637 -0
  65. package/es/map/map.js +984 -0
  66. package/es/map/util/abort_error.d.ts +15 -0
  67. package/es/map/util/abort_error.js +21 -0
  68. package/es/map/util/browser.d.ts +10 -0
  69. package/es/map/util/browser.js +30 -0
  70. package/es/map/util/dom.d.ts +30 -0
  71. package/es/map/util/dom.js +105 -0
  72. package/es/map/util/evented.d.ts +75 -0
  73. package/es/map/util/evented.js +158 -0
  74. package/es/map/util/simpleMapCoord.d.ts +31 -0
  75. package/es/map/util/simpleMapCoord.js +54 -0
  76. package/es/map/util/task_queue.d.ts +18 -0
  77. package/es/map/util/task_queue.js +54 -0
  78. package/es/map/util/util.d.ts +104 -0
  79. package/es/map/util/util.js +155 -0
  80. package/lib/index.d.ts +5 -0
  81. package/lib/index.js +33 -0
  82. package/lib/map/camera.d.ts +690 -0
  83. package/lib/map/camera.js +1145 -0
  84. package/lib/map/css/l7.css +171 -0
  85. package/lib/map/events.d.ts +384 -0
  86. package/lib/map/events.js +240 -0
  87. package/lib/map/geo/edge_insets.d.ts +97 -0
  88. package/lib/map/geo/edge_insets.js +122 -0
  89. package/lib/map/geo/lng_lat.d.ts +116 -0
  90. package/lib/map/geo/lng_lat.js +166 -0
  91. package/lib/map/geo/lng_lat_bounds.d.ts +217 -0
  92. package/lib/map/geo/lng_lat_bounds.js +341 -0
  93. package/lib/map/geo/mercator_coordinate.d.ts +113 -0
  94. package/lib/map/geo/mercator_coordinate.js +157 -0
  95. package/lib/map/geo/transform.d.ts +262 -0
  96. package/lib/map/geo/transform.js +744 -0
  97. package/lib/map/handler/box_zoom.d.ts +65 -0
  98. package/lib/map/handler/box_zoom.js +153 -0
  99. package/lib/map/handler/click_zoom.d.ts +24 -0
  100. package/lib/map/handler/click_zoom.js +54 -0
  101. package/lib/map/handler/cooperative_gestures.d.ts +40 -0
  102. package/lib/map/handler/cooperative_gestures.js +101 -0
  103. package/lib/map/handler/drag_handler.d.ts +88 -0
  104. package/lib/map/handler/drag_handler.js +97 -0
  105. package/lib/map/handler/drag_move_state_manager.d.ts +30 -0
  106. package/lib/map/handler/drag_move_state_manager.js +103 -0
  107. package/lib/map/handler/handler_util.d.ts +3 -0
  108. package/lib/map/handler/handler_util.js +14 -0
  109. package/lib/map/handler/keyboard.d.ts +88 -0
  110. package/lib/map/handler/keyboard.js +205 -0
  111. package/lib/map/handler/map_event.d.ts +46 -0
  112. package/lib/map/handler/map_event.js +140 -0
  113. package/lib/map/handler/mouse.d.ts +30 -0
  114. package/lib/map/handler/mouse.js +93 -0
  115. package/lib/map/handler/one_finger_touch_drag.d.ts +15 -0
  116. package/lib/map/handler/one_finger_touch_drag.js +47 -0
  117. package/lib/map/handler/scroll_zoom.d.ts +102 -0
  118. package/lib/map/handler/scroll_zoom.js +320 -0
  119. package/lib/map/handler/shim/dblclick_zoom.d.ts +44 -0
  120. package/lib/map/handler/shim/dblclick_zoom.js +68 -0
  121. package/lib/map/handler/shim/drag_pan.d.ts +79 -0
  122. package/lib/map/handler/shim/drag_pan.js +85 -0
  123. package/lib/map/handler/shim/drag_rotate.d.ts +54 -0
  124. package/lib/map/handler/shim/drag_rotate.js +74 -0
  125. package/lib/map/handler/shim/two_fingers_touch.d.ts +74 -0
  126. package/lib/map/handler/shim/two_fingers_touch.js +114 -0
  127. package/lib/map/handler/tap_drag_zoom.d.ts +28 -0
  128. package/lib/map/handler/tap_drag_zoom.js +99 -0
  129. package/lib/map/handler/tap_recognizer.d.ts +35 -0
  130. package/lib/map/handler/tap_recognizer.js +116 -0
  131. package/lib/map/handler/tap_zoom.d.ts +28 -0
  132. package/lib/map/handler/tap_zoom.js +94 -0
  133. package/lib/map/handler/touch_pan.d.ts +40 -0
  134. package/lib/map/handler/touch_pan.js +92 -0
  135. package/lib/map/handler/transform-provider.d.ts +23 -0
  136. package/lib/map/handler/transform-provider.js +43 -0
  137. package/lib/map/handler/two_fingers_touch.d.ts +107 -0
  138. package/lib/map/handler/two_fingers_touch.js +296 -0
  139. package/lib/map/handler_inertia.d.ts +20 -0
  140. package/lib/map/handler_inertia.js +136 -0
  141. package/lib/map/handler_manager.d.ts +154 -0
  142. package/lib/map/handler_manager.js +474 -0
  143. package/lib/map/map.d.ts +637 -0
  144. package/lib/map/map.js +991 -0
  145. package/lib/map/util/abort_error.d.ts +15 -0
  146. package/lib/map/util/abort_error.js +29 -0
  147. package/lib/map/util/browser.d.ts +10 -0
  148. package/lib/map/util/browser.js +36 -0
  149. package/lib/map/util/dom.d.ts +30 -0
  150. package/lib/map/util/dom.js +113 -0
  151. package/lib/map/util/evented.d.ts +75 -0
  152. package/lib/map/util/evented.js +167 -0
  153. package/lib/map/util/simpleMapCoord.d.ts +31 -0
  154. package/lib/map/util/simpleMapCoord.js +62 -0
  155. package/lib/map/util/task_queue.d.ts +18 -0
  156. package/lib/map/util/task_queue.js +62 -0
  157. package/lib/map/util/util.d.ts +104 -0
  158. package/lib/map/util/util.js +171 -0
  159. package/package.json +2 -2
@@ -0,0 +1,341 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.LngLatBounds = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _lng_lat = require("./lng_lat");
10
+ /**
11
+ * A {@link LngLatBounds} object, an array of {@link LngLatLike} objects in [sw, ne] order,
12
+ * or an array of numbers in [west, south, east, north] order.
13
+ *
14
+ * @group Geography and Geometry
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * let v1 = new LngLatBounds(
19
+ * new LngLat(-73.9876, 40.7661),
20
+ * new LngLat(-73.9397, 40.8002)
21
+ * );
22
+ * let v2 = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002])
23
+ * let v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
24
+ * ```
25
+ */
26
+
27
+ /**
28
+ * A `LngLatBounds` object represents a geographical bounding box,
29
+ * defined by its southwest and northeast points in longitude and latitude.
30
+ *
31
+ * If no arguments are provided to the constructor, a `null` bounding box is created.
32
+ *
33
+ * Note that any Mapbox GL method that accepts a `LngLatBounds` object as an argument or option
34
+ * can also accept an `Array` of two {@link LngLatLike} constructs and will perform an implicit conversion.
35
+ * This flexible type is documented as {@link LngLatBoundsLike}.
36
+ *
37
+ * @group Geography and Geometry
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * let sw = new LngLat(-73.9876, 40.7661);
42
+ * let ne = new LngLat(-73.9397, 40.8002);
43
+ * let llb = new LngLatBounds(sw, ne);
44
+ * ```
45
+ */
46
+ class LngLatBounds {
47
+ /**
48
+ * @param sw - The southwest corner of the bounding box.
49
+ * OR array of 4 numbers in the order of west, south, east, north
50
+ * OR array of 2 LngLatLike: [sw,ne]
51
+ * @param ne - The northeast corner of the bounding box.
52
+ * @example
53
+ * ```ts
54
+ * let sw = new LngLat(-73.9876, 40.7661);
55
+ * let ne = new LngLat(-73.9397, 40.8002);
56
+ * let llb = new LngLatBounds(sw, ne);
57
+ * ```
58
+ * OR
59
+ * ```ts
60
+ * let llb = new LngLatBounds([-73.9876, 40.7661, -73.9397, 40.8002]);
61
+ * ```
62
+ * OR
63
+ * ```ts
64
+ * let llb = new LngLatBounds([sw, ne]);
65
+ * ```
66
+ */
67
+ constructor(sw, ne) {
68
+ (0, _defineProperty2.default)(this, "_ne", void 0);
69
+ (0, _defineProperty2.default)(this, "_sw", void 0);
70
+ if (!sw) {
71
+ // noop
72
+ } else if (ne) {
73
+ this.setSouthWest(sw).setNorthEast(ne);
74
+ } else if (Array.isArray(sw)) {
75
+ if (sw.length === 4) {
76
+ // 4 element array: west, south, east, north
77
+ this.setSouthWest([sw[0], sw[1]]).setNorthEast([sw[2], sw[3]]);
78
+ } else {
79
+ this.setSouthWest(sw[0]).setNorthEast(sw[1]);
80
+ }
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Set the northeast corner of the bounding box
86
+ *
87
+ * @param ne - a {@link LngLatLike} object describing the northeast corner of the bounding box.
88
+ */
89
+ setNorthEast(ne) {
90
+ this._ne = ne instanceof _lng_lat.LngLat ? new _lng_lat.LngLat(ne.lng, ne.lat) : _lng_lat.LngLat.convert(ne);
91
+ return this;
92
+ }
93
+
94
+ /**
95
+ * Set the southwest corner of the bounding box
96
+ *
97
+ * @param sw - a {@link LngLatLike} object describing the southwest corner of the bounding box.
98
+ */
99
+ setSouthWest(sw) {
100
+ this._sw = sw instanceof _lng_lat.LngLat ? new _lng_lat.LngLat(sw.lng, sw.lat) : _lng_lat.LngLat.convert(sw);
101
+ return this;
102
+ }
103
+
104
+ /**
105
+ * Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
106
+ *
107
+ * @param obj - object to extend to
108
+ */
109
+ extend(obj) {
110
+ const sw = this._sw,
111
+ ne = this._ne;
112
+ let sw2, ne2;
113
+ if (obj instanceof _lng_lat.LngLat) {
114
+ sw2 = obj;
115
+ ne2 = obj;
116
+ } else if (obj instanceof LngLatBounds) {
117
+ sw2 = obj._sw;
118
+ ne2 = obj._ne;
119
+ if (!sw2 || !ne2) return this;
120
+ } else {
121
+ if (Array.isArray(obj)) {
122
+ if (obj.length === 4 || obj.every(Array.isArray)) {
123
+ const lngLatBoundsObj = obj;
124
+ return this.extend(LngLatBounds.convert(lngLatBoundsObj));
125
+ } else {
126
+ const lngLatObj = obj;
127
+ return this.extend(_lng_lat.LngLat.convert(lngLatObj));
128
+ }
129
+ } else if (obj && ('lng' in obj || 'lon' in obj) && 'lat' in obj) {
130
+ return this.extend(_lng_lat.LngLat.convert(obj));
131
+ }
132
+ return this;
133
+ }
134
+ if (!sw && !ne) {
135
+ this._sw = new _lng_lat.LngLat(sw2.lng, sw2.lat);
136
+ this._ne = new _lng_lat.LngLat(ne2.lng, ne2.lat);
137
+ } else {
138
+ sw.lng = Math.min(sw2.lng, sw.lng);
139
+ sw.lat = Math.min(sw2.lat, sw.lat);
140
+ ne.lng = Math.max(ne2.lng, ne.lng);
141
+ ne.lat = Math.max(ne2.lat, ne.lat);
142
+ }
143
+ return this;
144
+ }
145
+
146
+ /**
147
+ * Returns the geographical coordinate equidistant from the bounding box's corners.
148
+ *
149
+ * @returns The bounding box's center.
150
+ * @example
151
+ * ```ts
152
+ * let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
153
+ * llb.getCenter(); // = LngLat {lng: -73.96365, lat: 40.78315}
154
+ * ```
155
+ */
156
+ getCenter() {
157
+ return new _lng_lat.LngLat((this._sw.lng + this._ne.lng) / 2, (this._sw.lat + this._ne.lat) / 2);
158
+ }
159
+
160
+ /**
161
+ * Returns the southwest corner of the bounding box.
162
+ *
163
+ * @returns The southwest corner of the bounding box.
164
+ */
165
+ getSouthWest() {
166
+ return this._sw;
167
+ }
168
+
169
+ /**
170
+ * Returns the northeast corner of the bounding box.
171
+ *
172
+ * @returns The northeast corner of the bounding box.
173
+ */
174
+ getNorthEast() {
175
+ return this._ne;
176
+ }
177
+
178
+ /**
179
+ * Returns the northwest corner of the bounding box.
180
+ *
181
+ * @returns The northwest corner of the bounding box.
182
+ */
183
+ getNorthWest() {
184
+ return new _lng_lat.LngLat(this.getWest(), this.getNorth());
185
+ }
186
+
187
+ /**
188
+ * Returns the southeast corner of the bounding box.
189
+ *
190
+ * @returns The southeast corner of the bounding box.
191
+ */
192
+ getSouthEast() {
193
+ return new _lng_lat.LngLat(this.getEast(), this.getSouth());
194
+ }
195
+
196
+ /**
197
+ * Returns the west edge of the bounding box.
198
+ *
199
+ * @returns The west edge of the bounding box.
200
+ */
201
+ getWest() {
202
+ return this._sw.lng;
203
+ }
204
+
205
+ /**
206
+ * Returns the south edge of the bounding box.
207
+ *
208
+ * @returns The south edge of the bounding box.
209
+ */
210
+ getSouth() {
211
+ return this._sw.lat;
212
+ }
213
+
214
+ /**
215
+ * Returns the east edge of the bounding box.
216
+ *
217
+ * @returns The east edge of the bounding box.
218
+ */
219
+ getEast() {
220
+ return this._ne.lng;
221
+ }
222
+
223
+ /**
224
+ * Returns the north edge of the bounding box.
225
+ *
226
+ * @returns The north edge of the bounding box.
227
+ */
228
+ getNorth() {
229
+ return this._ne.lat;
230
+ }
231
+
232
+ /**
233
+ * Returns the bounding box represented as an array.
234
+ *
235
+ * @returns The bounding box represented as an array, consisting of the
236
+ * southwest and northeast coordinates of the bounding represented as arrays of numbers.
237
+ * @example
238
+ * ```ts
239
+ * let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
240
+ * llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
241
+ * ```
242
+ */
243
+ toArray() {
244
+ return [this._sw.toArray(), this._ne.toArray()];
245
+ }
246
+
247
+ /**
248
+ * Return the bounding box represented as a string.
249
+ *
250
+ * @returns The bounding box represents as a string of the format
251
+ * `'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'`.
252
+ * @example
253
+ * ```ts
254
+ * let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
255
+ * llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
256
+ * ```
257
+ */
258
+ toString() {
259
+ return `LngLatBounds(${this._sw.toString()}, ${this._ne.toString()})`;
260
+ }
261
+
262
+ /**
263
+ * Check if the bounding box is an empty/`null`-type box.
264
+ *
265
+ * @returns True if bounds have been defined, otherwise false.
266
+ */
267
+ isEmpty() {
268
+ return !(this._sw && this._ne);
269
+ }
270
+
271
+ /**
272
+ * Check if the point is within the bounding box.
273
+ *
274
+ * @param lnglat - geographic point to check against.
275
+ * @returns `true` if the point is within the bounding box.
276
+ * @example
277
+ * ```ts
278
+ * let llb = new LngLatBounds(
279
+ * new LngLat(-73.9876, 40.7661),
280
+ * new LngLat(-73.9397, 40.8002)
281
+ * );
282
+ *
283
+ * let ll = new LngLat(-73.9567, 40.7789);
284
+ *
285
+ * console.log(llb.contains(ll)); // = true
286
+ * ```
287
+ */
288
+ contains(lnglat) {
289
+ const {
290
+ lng,
291
+ lat
292
+ } = _lng_lat.LngLat.convert(lnglat);
293
+ const containsLatitude = this._sw.lat <= lat && lat <= this._ne.lat;
294
+ let containsLongitude = this._sw.lng <= lng && lng <= this._ne.lng;
295
+ if (this._sw.lng > this._ne.lng) {
296
+ // wrapped coordinates
297
+ containsLongitude = this._sw.lng >= lng && lng >= this._ne.lng;
298
+ }
299
+ return containsLatitude && containsLongitude;
300
+ }
301
+
302
+ /**
303
+ * Converts an array to a `LngLatBounds` object.
304
+ *
305
+ * If a `LngLatBounds` object is passed in, the function returns it unchanged.
306
+ *
307
+ * Internally, the function calls `LngLat#convert` to convert arrays to `LngLat` values.
308
+ *
309
+ * @param input - An array of two coordinates to convert, or a `LngLatBounds` object to return.
310
+ * @returns A new `LngLatBounds` object, if a conversion occurred, or the original `LngLatBounds` object.
311
+ * @example
312
+ * ```ts
313
+ * let arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
314
+ * let llb = LngLatBounds.convert(arr); // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
315
+ * ```
316
+ */
317
+ static convert(input) {
318
+ if (input instanceof LngLatBounds) return input;
319
+ return new LngLatBounds(input);
320
+ }
321
+
322
+ /**
323
+ * Returns a `LngLatBounds` from the coordinates extended by a given `radius`. The returned `LngLatBounds` completely contains the `radius`.
324
+ *
325
+ * @param center - center coordinates of the new bounds.
326
+ * @param radius - Distance in meters from the coordinates to extend the bounds.
327
+ * @returns A new `LngLatBounds` object representing the coordinates extended by the `radius`.
328
+ * @example
329
+ * ```ts
330
+ * let center = new LngLat(-73.9749, 40.7736);
331
+ * LngLatBounds.fromLngLat(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
332
+ * ```
333
+ */
334
+ static fromLngLat(center, radius = 0) {
335
+ const earthCircumferenceInMetersAtEquator = 40075017;
336
+ const latAccuracy = 360 * radius / earthCircumferenceInMetersAtEquator,
337
+ lngAccuracy = latAccuracy / Math.cos(Math.PI / 180 * center.lat);
338
+ return new LngLatBounds(new _lng_lat.LngLat(center.lng - lngAccuracy, center.lat - latAccuracy), new _lng_lat.LngLat(center.lng + lngAccuracy, center.lat + latAccuracy));
339
+ }
340
+ }
341
+ exports.LngLatBounds = LngLatBounds;
@@ -0,0 +1,113 @@
1
+ import type { LngLatLike } from './lng_lat';
2
+ import { LngLat } from './lng_lat';
3
+ interface ILngLat {
4
+ lng: number;
5
+ lat: number;
6
+ wrap(): ILngLat;
7
+ toArray(): [number, number];
8
+ distanceTo(lngLat: ILngLat): number;
9
+ toString(): string;
10
+ }
11
+ interface IMercatorCoordinate {
12
+ x: number;
13
+ y: number;
14
+ z: number;
15
+ toLngLat(): ILngLat;
16
+ toAltitude(): number;
17
+ meterInMercatorCoordinateUnits(): number;
18
+ }
19
+ export declare function mercatorXfromLng(lng: number): number;
20
+ export declare function mercatorYfromLat(lat: number): number;
21
+ export declare function mercatorZfromAltitude(altitude: number, lat: number): number;
22
+ export declare function lngFromMercatorX(x: number): number;
23
+ export declare function latFromMercatorY(y: number): number;
24
+ export declare function altitudeFromMercatorZ(z: number, y: number): number;
25
+ /**
26
+ * Determine the Mercator scale factor for a given latitude, see
27
+ * https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor
28
+ *
29
+ * At the equator the scale factor will be 1, which increases at higher latitudes.
30
+ *
31
+ * @param lat - Latitude
32
+ * @returns scale factor
33
+ */
34
+ export declare function mercatorScale(lat: number): number;
35
+ /**
36
+ * A `MercatorCoordinate` object represents a projected three dimensional position.
37
+ *
38
+ * `MercatorCoordinate` uses the web mercator projection ([EPSG:3857](https://epsg.io/3857)) with slightly different units:
39
+ *
40
+ * - the size of 1 unit is the width of the projected world instead of the "mercator meter"
41
+ * - the origin of the coordinate space is at the north-west corner instead of the middle
42
+ *
43
+ * For example, `MercatorCoordinate(0, 0, 0)` is the north-west corner of the mercator world and
44
+ * `MercatorCoordinate(1, 1, 0)` is the south-east corner. If you are familiar with
45
+ * [vector tiles](https://github.com/mapbox/vector-tile-spec) it may be helpful to think
46
+ * of the coordinate space as the `0/0/0` tile with an extent of `1`.
47
+ *
48
+ * The `z` dimension of `MercatorCoordinate` is conformal. A cube in the mercator coordinate space would be rendered as a cube.
49
+ *
50
+ * @group Geography and Geometry
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * let nullIsland = new MercatorCoordinate(0.5, 0.5, 0);
55
+ * ```
56
+ * @see [Add a custom style layer](https://maplibre.org/maplibre-gl-js/docs/examples/custom-style-layer/)
57
+ */
58
+ export declare class MercatorCoordinate implements IMercatorCoordinate {
59
+ x: number;
60
+ y: number;
61
+ z: number;
62
+ /**
63
+ * @param x - The x component of the position.
64
+ * @param y - The y component of the position.
65
+ * @param z - The z component of the position.
66
+ */
67
+ constructor(x: number, y: number, z?: number);
68
+ /**
69
+ * Project a `LngLat` to a `MercatorCoordinate`.
70
+ *
71
+ * @param lngLatLike - The location to project.
72
+ * @param altitude - The altitude in meters of the position.
73
+ * @returns The projected mercator coordinate.
74
+ * @example
75
+ * ```ts
76
+ * let coord = MercatorCoordinate.fromLngLat({ lng: 0, lat: 0}, 0);
77
+ * coord; // MercatorCoordinate(0.5, 0.5, 0)
78
+ * ```
79
+ */
80
+ static fromLngLat(lngLatLike: LngLatLike, altitude?: number): MercatorCoordinate;
81
+ /**
82
+ * Returns the `LngLat` for the coordinate.
83
+ *
84
+ * @returns The `LngLat` object.
85
+ * @example
86
+ * ```ts
87
+ * let coord = new MercatorCoordinate(0.5, 0.5, 0);
88
+ * let lngLat = coord.toLngLat(); // LngLat(0, 0)
89
+ * ```
90
+ */
91
+ toLngLat(): LngLat;
92
+ /**
93
+ * Returns the altitude in meters of the coordinate.
94
+ *
95
+ * @returns The altitude in meters.
96
+ * @example
97
+ * ```ts
98
+ * let coord = new MercatorCoordinate(0, 0, 0.02);
99
+ * coord.toAltitude(); // 6914.281956295339
100
+ * ```
101
+ */
102
+ toAltitude(): number;
103
+ /**
104
+ * Returns the distance of 1 meter in `MercatorCoordinate` units at this latitude.
105
+ *
106
+ * For coordinates in real world units using meters, this naturally provides the scale
107
+ * to transform into `MercatorCoordinate`s.
108
+ *
109
+ * @returns Distance of 1 meter in `MercatorCoordinate` units.
110
+ */
111
+ meterInMercatorCoordinateUnits(): number;
112
+ }
113
+ export {};
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.MercatorCoordinate = void 0;
8
+ exports.altitudeFromMercatorZ = altitudeFromMercatorZ;
9
+ exports.latFromMercatorY = latFromMercatorY;
10
+ exports.lngFromMercatorX = lngFromMercatorX;
11
+ exports.mercatorScale = mercatorScale;
12
+ exports.mercatorXfromLng = mercatorXfromLng;
13
+ exports.mercatorYfromLat = mercatorYfromLat;
14
+ exports.mercatorZfromAltitude = mercatorZfromAltitude;
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+ var _lng_lat = require("./lng_lat");
17
+ /*
18
+ * The average circumference of the world in meters.
19
+ */
20
+ const earthCircumfrence = 2 * Math.PI * _lng_lat.earthRadius; // meters
21
+
22
+ /*
23
+ * The circumference at a line of latitude in meters.
24
+ */
25
+ function circumferenceAtLatitude(latitude) {
26
+ return earthCircumfrence * Math.cos(latitude * Math.PI / 180);
27
+ }
28
+ function mercatorXfromLng(lng) {
29
+ return (180 + lng) / 360;
30
+ }
31
+ function mercatorYfromLat(lat) {
32
+ return (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360))) / 360;
33
+ }
34
+ function mercatorZfromAltitude(altitude, lat) {
35
+ return altitude / circumferenceAtLatitude(lat);
36
+ }
37
+ function lngFromMercatorX(x) {
38
+ return x * 360 - 180;
39
+ }
40
+ function latFromMercatorY(y) {
41
+ const y2 = 180 - y * 360;
42
+ return 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
43
+ }
44
+ function altitudeFromMercatorZ(z, y) {
45
+ return z * circumferenceAtLatitude(latFromMercatorY(y));
46
+ }
47
+
48
+ /**
49
+ * Determine the Mercator scale factor for a given latitude, see
50
+ * https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor
51
+ *
52
+ * At the equator the scale factor will be 1, which increases at higher latitudes.
53
+ *
54
+ * @param lat - Latitude
55
+ * @returns scale factor
56
+ */
57
+ function mercatorScale(lat) {
58
+ return 1 / Math.cos(lat * Math.PI / 180);
59
+ }
60
+
61
+ /**
62
+ * A `MercatorCoordinate` object represents a projected three dimensional position.
63
+ *
64
+ * `MercatorCoordinate` uses the web mercator projection ([EPSG:3857](https://epsg.io/3857)) with slightly different units:
65
+ *
66
+ * - the size of 1 unit is the width of the projected world instead of the "mercator meter"
67
+ * - the origin of the coordinate space is at the north-west corner instead of the middle
68
+ *
69
+ * For example, `MercatorCoordinate(0, 0, 0)` is the north-west corner of the mercator world and
70
+ * `MercatorCoordinate(1, 1, 0)` is the south-east corner. If you are familiar with
71
+ * [vector tiles](https://github.com/mapbox/vector-tile-spec) it may be helpful to think
72
+ * of the coordinate space as the `0/0/0` tile with an extent of `1`.
73
+ *
74
+ * The `z` dimension of `MercatorCoordinate` is conformal. A cube in the mercator coordinate space would be rendered as a cube.
75
+ *
76
+ * @group Geography and Geometry
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * let nullIsland = new MercatorCoordinate(0.5, 0.5, 0);
81
+ * ```
82
+ * @see [Add a custom style layer](https://maplibre.org/maplibre-gl-js/docs/examples/custom-style-layer/)
83
+ */
84
+ class MercatorCoordinate {
85
+ /**
86
+ * @param x - The x component of the position.
87
+ * @param y - The y component of the position.
88
+ * @param z - The z component of the position.
89
+ */
90
+ constructor(x, y, z = 0) {
91
+ (0, _defineProperty2.default)(this, "x", void 0);
92
+ (0, _defineProperty2.default)(this, "y", void 0);
93
+ (0, _defineProperty2.default)(this, "z", void 0);
94
+ this.x = +x;
95
+ this.y = +y;
96
+ this.z = +z;
97
+ }
98
+
99
+ /**
100
+ * Project a `LngLat` to a `MercatorCoordinate`.
101
+ *
102
+ * @param lngLatLike - The location to project.
103
+ * @param altitude - The altitude in meters of the position.
104
+ * @returns The projected mercator coordinate.
105
+ * @example
106
+ * ```ts
107
+ * let coord = MercatorCoordinate.fromLngLat({ lng: 0, lat: 0}, 0);
108
+ * coord; // MercatorCoordinate(0.5, 0.5, 0)
109
+ * ```
110
+ */
111
+ static fromLngLat(lngLatLike, altitude = 0) {
112
+ const lngLat = _lng_lat.LngLat.convert(lngLatLike);
113
+ return new MercatorCoordinate(mercatorXfromLng(lngLat.lng), mercatorYfromLat(lngLat.lat), mercatorZfromAltitude(altitude, lngLat.lat));
114
+ }
115
+
116
+ /**
117
+ * Returns the `LngLat` for the coordinate.
118
+ *
119
+ * @returns The `LngLat` object.
120
+ * @example
121
+ * ```ts
122
+ * let coord = new MercatorCoordinate(0.5, 0.5, 0);
123
+ * let lngLat = coord.toLngLat(); // LngLat(0, 0)
124
+ * ```
125
+ */
126
+ toLngLat() {
127
+ return new _lng_lat.LngLat(lngFromMercatorX(this.x), latFromMercatorY(this.y));
128
+ }
129
+
130
+ /**
131
+ * Returns the altitude in meters of the coordinate.
132
+ *
133
+ * @returns The altitude in meters.
134
+ * @example
135
+ * ```ts
136
+ * let coord = new MercatorCoordinate(0, 0, 0.02);
137
+ * coord.toAltitude(); // 6914.281956295339
138
+ * ```
139
+ */
140
+ toAltitude() {
141
+ return altitudeFromMercatorZ(this.z, this.y);
142
+ }
143
+
144
+ /**
145
+ * Returns the distance of 1 meter in `MercatorCoordinate` units at this latitude.
146
+ *
147
+ * For coordinates in real world units using meters, this naturally provides the scale
148
+ * to transform into `MercatorCoordinate`s.
149
+ *
150
+ * @returns Distance of 1 meter in `MercatorCoordinate` units.
151
+ */
152
+ meterInMercatorCoordinateUnits() {
153
+ // 1 meter / circumference at equator in meters * Mercator projection scale factor at this latitude
154
+ return 1 / earthCircumfrence * mercatorScale(latFromMercatorY(this.y));
155
+ }
156
+ }
157
+ exports.MercatorCoordinate = MercatorCoordinate;