@antv/l7-map 2.25.7 → 2.25.10

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,1145 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.Camera = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _pointGeometry = _interopRequireDefault(require("@mapbox/point-geometry"));
10
+ var _lng_lat = require("./geo/lng_lat");
11
+ var _lng_lat_bounds = require("./geo/lng_lat_bounds");
12
+ var _mercator_coordinate = require("./geo/mercator_coordinate");
13
+ var _browser = require("./util/browser");
14
+ var _evented = require("./util/evented");
15
+ var _util = require("./util/util");
16
+ /**
17
+ * A [Point](https://github.com/mapbox/point-geometry) or an array of two numbers representing `x` and `y` screen coordinates in pixels.
18
+ *
19
+ * @group Geography and Geometry
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * let p1 = new Point(-77, 38); // a PointLike which is a Point
24
+ * let p2 = [-77, 38]; // a PointLike which is an array of two numbers
25
+ * ```
26
+ */
27
+
28
+ /**
29
+ * A helper to allow require of at least one property
30
+ */
31
+
32
+ /**
33
+ * Options common to {@link Map#jumpTo}, {@link Map#easeTo}, and {@link Map#flyTo}, controlling the desired location,
34
+ * zoom, bearing, and pitch of the camera. All properties are optional, and when a property is omitted, the current
35
+ * camera value for that property will remain unchanged.
36
+ *
37
+ * @example
38
+ * Set the map's initial perspective with CameraOptions
39
+ * ```ts
40
+ * let map = new Map({
41
+ * container: 'map',
42
+ * style: 'https://demotiles.maplibre.org/style.json',
43
+ * center: [-73.5804, 45.53483],
44
+ * pitch: 60,
45
+ * bearing: -60,
46
+ * zoom: 10
47
+ * });
48
+ * ```
49
+ * @see [Set pitch and bearing](https://maplibre.org/maplibre-gl-js/docs/examples/set-perspective/)
50
+ * @see [Jump to a series of locations](https://maplibre.org/maplibre-gl-js/docs/examples/jump-to/)
51
+ * @see [Fly to a location](https://maplibre.org/maplibre-gl-js/docs/examples/flyto/)
52
+ * @see [Display buildings in 3D](https://maplibre.org/maplibre-gl-js/docs/examples/3d-buildings/)
53
+ */
54
+
55
+ /**
56
+ * Holds center, zoom and bearing properties
57
+ */
58
+
59
+ /**
60
+ * The options object related to the {@link Map#jumpTo} method
61
+ */
62
+
63
+ /**
64
+ * A options object for the {@link Map#cameraForBounds} method
65
+ */
66
+
67
+ /**
68
+ * The {@link Map#flyTo} options object
69
+ */
70
+
71
+ /**
72
+ * Options for {@link Map#fitBounds} method
73
+ */
74
+
75
+ /**
76
+ * Options common to map movement methods that involve animation, such as {@link Map#panBy} and
77
+ * {@link Map#easeTo}, controlling the duration and easing function of the animation. All properties
78
+ * are optional.
79
+ *
80
+ */
81
+
82
+ /**
83
+ * A callback hook that allows manipulating the camera and being notified about camera updates before they happen
84
+ */
85
+
86
+ class Camera extends _evented.Evented {
87
+ constructor(transform, options) {
88
+ super();
89
+ (0, _defineProperty2.default)(this, "transform", void 0);
90
+ (0, _defineProperty2.default)(this, "handlers", void 0);
91
+ (0, _defineProperty2.default)(this, "_moving", void 0);
92
+ (0, _defineProperty2.default)(this, "_zooming", void 0);
93
+ (0, _defineProperty2.default)(this, "_rotating", void 0);
94
+ (0, _defineProperty2.default)(this, "_pitching", void 0);
95
+ (0, _defineProperty2.default)(this, "_padding", void 0);
96
+ (0, _defineProperty2.default)(this, "_bearingSnap", void 0);
97
+ (0, _defineProperty2.default)(this, "_easeStart", void 0);
98
+ (0, _defineProperty2.default)(this, "_easeOptions", void 0);
99
+ (0, _defineProperty2.default)(this, "_easeId", void 0);
100
+ (0, _defineProperty2.default)(this, "_onEaseFrame", void 0);
101
+ (0, _defineProperty2.default)(this, "_onEaseEnd", void 0);
102
+ (0, _defineProperty2.default)(this, "_easeFrameId", void 0);
103
+ /**
104
+ * @internal
105
+ * Used to track accumulated changes during continuous interaction
106
+ */
107
+ (0, _defineProperty2.default)(this, "_requestedCameraState", void 0);
108
+ /**
109
+ * A callback used to defer camera updates or apply arbitrary constraints.
110
+ * If specified, this Camera instance can be used as a stateless component in React etc.
111
+ */
112
+ (0, _defineProperty2.default)(this, "transformCameraUpdate", void 0);
113
+ // Callback for map._requestRenderFrame
114
+ (0, _defineProperty2.default)(this, "_renderFrameCallback", () => {
115
+ const t = Math.min((_browser.browser.now() - this._easeStart) / this._easeOptions.duration, 1);
116
+ this._onEaseFrame(this._easeOptions.easing(t));
117
+
118
+ // if _stop is called during _onEaseFrame from _fireMoveEvents we should avoid a new _requestRenderFrame, checking it by ensuring _easeFrameId was not deleted
119
+ if (t < 1 && this._easeFrameId) {
120
+ this._easeFrameId = this._requestRenderFrame(this._renderFrameCallback);
121
+ } else {
122
+ this.stop();
123
+ }
124
+ });
125
+ this._moving = false;
126
+ this._zooming = false;
127
+ this.transform = transform;
128
+ this._bearingSnap = options.bearingSnap;
129
+ this.on('moveend', () => {
130
+ delete this._requestedCameraState;
131
+ });
132
+ }
133
+
134
+ /**
135
+ * Returns the map's geographical centerpoint.
136
+ *
137
+ * @returns The map's geographical centerpoint.
138
+ * @example
139
+ * Return a LngLat object such as `{lng: 0, lat: 0}`
140
+ * ```ts
141
+ * let center = map.getCenter();
142
+ * // access longitude and latitude values directly
143
+ * let {lng, lat} = map.getCenter();
144
+ * ```
145
+ */
146
+ getCenter() {
147
+ return new _lng_lat.LngLat(this.transform.center.lng, this.transform.center.lat);
148
+ }
149
+
150
+ /**
151
+ * Sets the map's geographical centerpoint. Equivalent to `jumpTo({center: center})`.
152
+ *
153
+ * Triggers the following events: `movestart` and `moveend`.
154
+ *
155
+ * @param center - The centerpoint to set.
156
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
157
+ * @example
158
+ * ```ts
159
+ * map.setCenter([-74, 38]);
160
+ * ```
161
+ */
162
+ setCenter(center, eventData) {
163
+ return this.jumpTo({
164
+ center
165
+ }, eventData);
166
+ }
167
+
168
+ /**
169
+ * Pans the map by the specified offset.
170
+ *
171
+ * Triggers the following events: `movestart` and `moveend`.
172
+ *
173
+ * @param offset - `x` and `y` coordinates by which to pan the map.
174
+ * @param options - Options object
175
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
176
+ * @see [Navigate the map with game-like controls](https://maplibre.org/maplibre-gl-js/docs/examples/game-controls/)
177
+ */
178
+ panBy(offset, options, eventData) {
179
+ offset = _pointGeometry.default.convert(offset).mult(-1);
180
+ return this.panTo(this.transform.center, (0, _util.extend)({
181
+ offset
182
+ }, options), eventData);
183
+ }
184
+
185
+ /**
186
+ * Pans the map to the specified location with an animated transition.
187
+ *
188
+ * Triggers the following events: `movestart` and `moveend`.
189
+ *
190
+ * @param lnglat - The location to pan the map to.
191
+ * @param options - Options describing the destination and animation of the transition.
192
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
193
+ * @example
194
+ * ```ts
195
+ * map.panTo([-74, 38]);
196
+ * // Specify that the panTo animation should last 5000 milliseconds.
197
+ * map.panTo([-74, 38], {duration: 5000});
198
+ * ```
199
+ * @see [Update a feature in realtime](https://maplibre.org/maplibre-gl-js/docs/examples/live-update-feature/)
200
+ */
201
+ panTo(lnglat, options, eventData) {
202
+ return this.easeTo((0, _util.extend)({
203
+ center: lnglat
204
+ }, options), eventData);
205
+ }
206
+
207
+ /**
208
+ * Returns the map's current zoom level.
209
+ *
210
+ * @returns The map's current zoom level.
211
+ * @example
212
+ * ```ts
213
+ * map.getZoom();
214
+ * ```
215
+ */
216
+ getZoom() {
217
+ return this.transform.zoom;
218
+ }
219
+
220
+ /**
221
+ * Sets the map's zoom level. Equivalent to `jumpTo({zoom: zoom})`.
222
+ *
223
+ * Triggers the following events: `movestart`, `move`, `moveend`, `zoomstart`, `zoom`, and `zoomend`.
224
+ *
225
+ * @param zoom - The zoom level to set (0-20).
226
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
227
+ * @example
228
+ * Zoom to the zoom level 5 without an animated transition
229
+ * ```ts
230
+ * map.setZoom(5);
231
+ * ```
232
+ */
233
+ setZoom(zoom, eventData) {
234
+ this.jumpTo({
235
+ zoom
236
+ }, eventData);
237
+ return this;
238
+ }
239
+
240
+ /**
241
+ * Zooms the map to the specified zoom level, with an animated transition.
242
+ *
243
+ * Triggers the following events: `movestart`, `move`, `moveend`, `zoomstart`, `zoom`, and `zoomend`.
244
+ *
245
+ * @param zoom - The zoom level to transition to.
246
+ * @param options - Options object
247
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
248
+ * @example
249
+ * ```ts
250
+ * // Zoom to the zoom level 5 without an animated transition
251
+ * map.zoomTo(5);
252
+ * // Zoom to the zoom level 8 with an animated transition
253
+ * map.zoomTo(8, {
254
+ * duration: 2000,
255
+ * offset: [100, 50]
256
+ * });
257
+ * ```
258
+ */
259
+ zoomTo(zoom, options, eventData) {
260
+ return this.easeTo((0, _util.extend)({
261
+ zoom
262
+ }, options), eventData);
263
+ }
264
+
265
+ /**
266
+ * Increases the map's zoom level by 1.
267
+ *
268
+ * Triggers the following events: `movestart`, `move`, `moveend`, `zoomstart`, `zoom`, and `zoomend`.
269
+ *
270
+ * @param options - Options object
271
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
272
+ * @example
273
+ * Zoom the map in one level with a custom animation duration
274
+ * ```ts
275
+ * map.zoomIn({duration: 1000});
276
+ * ```
277
+ */
278
+ zoomIn(options, eventData) {
279
+ this.zoomTo(this.getZoom() + 1, options, eventData);
280
+ return this;
281
+ }
282
+
283
+ /**
284
+ * Decreases the map's zoom level by 1.
285
+ *
286
+ * Triggers the following events: `movestart`, `move`, `moveend`, `zoomstart`, `zoom`, and `zoomend`.
287
+ *
288
+ * @param options - Options object
289
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
290
+ * @example
291
+ * Zoom the map out one level with a custom animation offset
292
+ * ```ts
293
+ * map.zoomOut({offset: [80, 60]});
294
+ * ```
295
+ */
296
+ zoomOut(options, eventData) {
297
+ this.zoomTo(this.getZoom() - 1, options, eventData);
298
+ return this;
299
+ }
300
+
301
+ /**
302
+ * Returns the map's current bearing. The bearing is the compass direction that is "up"; for example, a bearing
303
+ * of 90° orients the map so that east is up.
304
+ *
305
+ * @returns The map's current bearing.
306
+ * @see [Navigate the map with game-like controls](https://maplibre.org/maplibre-gl-js/docs/examples/game-controls/)
307
+ */
308
+ getBearing() {
309
+ return this.transform.bearing;
310
+ }
311
+
312
+ /**
313
+ * Sets the map's bearing (rotation). The bearing is the compass direction that is "up"; for example, a bearing
314
+ * of 90° orients the map so that east is up.
315
+ *
316
+ * Equivalent to `jumpTo({bearing: bearing})`.
317
+ *
318
+ * Triggers the following events: `movestart`, `moveend`, and `rotate`.
319
+ *
320
+ * @param bearing - The desired bearing.
321
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
322
+ * @example
323
+ * Rotate the map to 90 degrees
324
+ * ```ts
325
+ * map.setBearing(90);
326
+ * ```
327
+ */
328
+ setBearing(bearing, eventData) {
329
+ this.jumpTo({
330
+ bearing
331
+ }, eventData);
332
+ return this;
333
+ }
334
+
335
+ /**
336
+ * Returns the current padding applied around the map viewport.
337
+ *
338
+ * @returns The current padding around the map viewport.
339
+ */
340
+ getPadding() {
341
+ return this.transform.padding;
342
+ }
343
+
344
+ /**
345
+ * Sets the padding in pixels around the viewport.
346
+ *
347
+ * Equivalent to `jumpTo({padding: padding})`.
348
+ *
349
+ * Triggers the following events: `movestart` and `moveend`.
350
+ *
351
+ * @param padding - The desired padding.
352
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
353
+ * @example
354
+ * Sets a left padding of 300px, and a top padding of 50px
355
+ * ```ts
356
+ * map.setPadding({ left: 300, top: 50 });
357
+ * ```
358
+ */
359
+ setPadding(padding, eventData) {
360
+ this.jumpTo({
361
+ padding
362
+ }, eventData);
363
+ return this;
364
+ }
365
+
366
+ /**
367
+ * Rotates the map to the specified bearing, with an animated transition. The bearing is the compass direction
368
+ * that is "up"; for example, a bearing of 90° orients the map so that east is up.
369
+ *
370
+ * Triggers the following events: `movestart`, `moveend`, and `rotate`.
371
+ *
372
+ * @param bearing - The desired bearing.
373
+ * @param options - Options object
374
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
375
+ */
376
+ rotateTo(bearing, options, eventData) {
377
+ return this.easeTo((0, _util.extend)({
378
+ bearing
379
+ }, options), eventData);
380
+ }
381
+
382
+ /**
383
+ * Rotates the map so that north is up (0° bearing), with an animated transition.
384
+ *
385
+ * Triggers the following events: `movestart`, `moveend`, and `rotate`.
386
+ *
387
+ * @param options - Options object
388
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
389
+ */
390
+ resetNorth(options, eventData) {
391
+ this.rotateTo(0, (0, _util.extend)({
392
+ duration: 1000
393
+ }, options), eventData);
394
+ return this;
395
+ }
396
+
397
+ /**
398
+ * Rotates and pitches the map so that north is up (0° bearing) and pitch is 0°, with an animated transition.
399
+ *
400
+ * Triggers the following events: `movestart`, `move`, `moveend`, `pitchstart`, `pitch`, `pitchend`, and `rotate`.
401
+ *
402
+ * @param options - Options object
403
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
404
+ */
405
+ resetNorthPitch(options, eventData) {
406
+ this.easeTo((0, _util.extend)({
407
+ bearing: 0,
408
+ pitch: 0,
409
+ duration: 1000
410
+ }, options), eventData);
411
+ return this;
412
+ }
413
+
414
+ /**
415
+ * Snaps the map so that north is up (0° bearing), if the current bearing is close enough to it (i.e. within the
416
+ * `bearingSnap` threshold).
417
+ *
418
+ * Triggers the following events: `movestart`, `moveend`, and `rotate`.
419
+ *
420
+ * @param options - Options object
421
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
422
+ */
423
+ snapToNorth(options, eventData) {
424
+ if (Math.abs(this.getBearing()) < this._bearingSnap) {
425
+ return this.resetNorth(options, eventData);
426
+ }
427
+ return this;
428
+ }
429
+
430
+ /**
431
+ * Returns the map's current pitch (tilt).
432
+ *
433
+ * @returns The map's current pitch, measured in degrees away from the plane of the screen.
434
+ */
435
+ getPitch() {
436
+ return this.transform.pitch;
437
+ }
438
+
439
+ /**
440
+ * Sets the map's pitch (tilt). Equivalent to `jumpTo({pitch: pitch})`.
441
+ *
442
+ * Triggers the following events: `movestart`, `moveend`, `pitchstart`, and `pitchend`.
443
+ *
444
+ * @param pitch - The pitch to set, measured in degrees away from the plane of the screen (0-60).
445
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
446
+ */
447
+ setPitch(pitch, eventData) {
448
+ this.jumpTo({
449
+ pitch
450
+ }, eventData);
451
+ return this;
452
+ }
453
+
454
+ /**
455
+ * @param bounds - Calculate the center for these bounds in the viewport and use
456
+ * the highest zoom level up to and including `Map#getMaxZoom()` that fits
457
+ * in the viewport. LngLatBounds represent a box that is always axis-aligned with bearing 0.
458
+ * @param options - Options object
459
+ * @returns If map is able to fit to provided bounds, returns `center`, `zoom`, and `bearing`.
460
+ * If map is unable to fit, method will warn and return undefined.
461
+ * @example
462
+ * ```ts
463
+ * let bbox = [[-79, 43], [-73, 45]];
464
+ * let newCameraTransform = map.cameraForBounds(bbox, {
465
+ * padding: {top: 10, bottom:25, left: 15, right: 5}
466
+ * });
467
+ * ```
468
+ */
469
+ cameraForBounds(bounds, options) {
470
+ bounds = _lng_lat_bounds.LngLatBounds.convert(bounds);
471
+ const bearing = options && options.bearing || 0;
472
+ return this._cameraForBoxAndBearing(bounds.getNorthWest(), bounds.getSouthEast(), bearing, options);
473
+ }
474
+
475
+ /**
476
+ * @internal
477
+ * Calculate the center of these two points in the viewport and use
478
+ * the highest zoom level up to and including `Map#getMaxZoom()` that fits
479
+ * the points in the viewport at the specified bearing.
480
+ * @param p0 - First point
481
+ * @param p1 - Second point
482
+ * @param bearing - Desired map bearing at end of animation, in degrees
483
+ * @param options - the camera options
484
+ * @returns If map is able to fit to provided bounds, returns `center`, `zoom`, and `bearing`.
485
+ * If map is unable to fit, method will warn and return undefined.
486
+ * @example
487
+ * ```ts
488
+ * let p0 = [-79, 43];
489
+ * let p1 = [-73, 45];
490
+ * let bearing = 90;
491
+ * let newCameraTransform = map._cameraForBoxAndBearing(p0, p1, bearing, {
492
+ * padding: {top: 10, bottom:25, left: 15, right: 5}
493
+ * });
494
+ * ```
495
+ */
496
+ _cameraForBoxAndBearing(p0, p1, bearing, options) {
497
+ const defaultPadding = {
498
+ top: 0,
499
+ bottom: 0,
500
+ right: 0,
501
+ left: 0
502
+ };
503
+ options = (0, _util.extend)({
504
+ padding: defaultPadding,
505
+ offset: [0, 0],
506
+ maxZoom: this.transform.maxZoom
507
+ }, options);
508
+ if (typeof options.padding === 'number') {
509
+ const p = options.padding;
510
+ options.padding = {
511
+ top: p,
512
+ bottom: p,
513
+ right: p,
514
+ left: p
515
+ };
516
+ }
517
+ options.padding = (0, _util.extend)(defaultPadding, options.padding);
518
+ const tr = this.transform;
519
+ const edgePadding = tr.padding;
520
+
521
+ // Consider all corners of the rotated bounding box derived from the given points
522
+ // when find the camera position that fits the given points.
523
+ const bounds = new _lng_lat_bounds.LngLatBounds(p0, p1);
524
+ const nwWorld = tr.project(bounds.getNorthWest());
525
+ const neWorld = tr.project(bounds.getNorthEast());
526
+ const seWorld = tr.project(bounds.getSouthEast());
527
+ const swWorld = tr.project(bounds.getSouthWest());
528
+ const bearingRadians = (0, _util.degreesToRadians)(-bearing);
529
+ const nwRotatedWorld = nwWorld.rotate(bearingRadians);
530
+ const neRotatedWorld = neWorld.rotate(bearingRadians);
531
+ const seRotatedWorld = seWorld.rotate(bearingRadians);
532
+ const swRotatedWorld = swWorld.rotate(bearingRadians);
533
+ const upperRight = new _pointGeometry.default(Math.max(nwRotatedWorld.x, neRotatedWorld.x, swRotatedWorld.x, seRotatedWorld.x), Math.max(nwRotatedWorld.y, neRotatedWorld.y, swRotatedWorld.y, seRotatedWorld.y));
534
+ const lowerLeft = new _pointGeometry.default(Math.min(nwRotatedWorld.x, neRotatedWorld.x, swRotatedWorld.x, seRotatedWorld.x), Math.min(nwRotatedWorld.y, neRotatedWorld.y, swRotatedWorld.y, seRotatedWorld.y));
535
+
536
+ // Calculate zoom: consider the original bbox and padding.
537
+ const size = upperRight.sub(lowerLeft);
538
+ const scaleX = (tr.width - (edgePadding.left + edgePadding.right + options.padding.left + options.padding.right)) / size.x;
539
+ const scaleY = (tr.height - (edgePadding.top + edgePadding.bottom + options.padding.top + options.padding.bottom)) / size.y;
540
+ if (scaleY < 0 || scaleX < 0) {
541
+ (0, _util.warnOnce)('Map cannot fit within canvas with the given bounds, padding, and/or offset.');
542
+ return undefined;
543
+ }
544
+ const zoom = Math.min(tr.scaleZoom(tr.scale * Math.min(scaleX, scaleY)), options.maxZoom);
545
+
546
+ // Calculate center: apply the zoom, the configured offset, as well as offset that exists as a result of padding.
547
+ const offset = _pointGeometry.default.convert(options.offset);
548
+ const paddingOffsetX = (options.padding.left - options.padding.right) / 2;
549
+ const paddingOffsetY = (options.padding.top - options.padding.bottom) / 2;
550
+ const paddingOffset = new _pointGeometry.default(paddingOffsetX, paddingOffsetY);
551
+ const rotatedPaddingOffset = paddingOffset.rotate((0, _util.degreesToRadians)(bearing));
552
+ const offsetAtInitialZoom = offset.add(rotatedPaddingOffset);
553
+ const offsetAtFinalZoom = offsetAtInitialZoom.mult(tr.scale / tr.zoomScale(zoom));
554
+ const center = tr.unproject(
555
+ // either world diagonal can be used (NW-SE or NE-SW)
556
+ nwWorld.add(seWorld).div(2).sub(offsetAtFinalZoom));
557
+ return {
558
+ center,
559
+ zoom,
560
+ bearing
561
+ };
562
+ }
563
+
564
+ /**
565
+ * Pans and zooms the map to contain its visible area within the specified geographical bounds.
566
+ * This function will also reset the map's bearing to 0 if bearing is nonzero.
567
+ *
568
+ * Triggers the following events: `movestart` and `moveend`.
569
+ *
570
+ * @param bounds - Center these bounds in the viewport and use the highest
571
+ * zoom level up to and including `Map#getMaxZoom()` that fits them in the viewport.
572
+ * @param options - Options supports all properties from {@link AnimationOptions} and {@link CameraOptions} in addition to the fields below.
573
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
574
+ * @example
575
+ * ```ts
576
+ * let bbox = [[-79, 43], [-73, 45]];
577
+ * map.fitBounds(bbox, {
578
+ * padding: {top: 10, bottom:25, left: 15, right: 5}
579
+ * });
580
+ * ```
581
+ * @see [Fit a map to a bounding box](https://maplibre.org/maplibre-gl-js/docs/examples/fitbounds/)
582
+ */
583
+ fitBounds(bounds, options, eventData) {
584
+ return this._fitInternal(this.cameraForBounds(bounds, options), options, eventData);
585
+ }
586
+
587
+ /**
588
+ * Pans, rotates and zooms the map to to fit the box made by points p0 and p1
589
+ * once the map is rotated to the specified bearing. To zoom without rotating,
590
+ * pass in the current map bearing.
591
+ *
592
+ * Triggers the following events: `movestart`, `move`, `moveend`, `zoomstart`, `zoom`, `zoomend` and `rotate`.
593
+ *
594
+ * @param p0 - First point on screen, in pixel coordinates
595
+ * @param p1 - Second point on screen, in pixel coordinates
596
+ * @param bearing - Desired map bearing at end of animation, in degrees
597
+ * @param options - Options object
598
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
599
+ * @example
600
+ * ```ts
601
+ * let p0 = [220, 400];
602
+ * let p1 = [500, 900];
603
+ * map.fitScreenCoordinates(p0, p1, map.getBearing(), {
604
+ * padding: {top: 10, bottom:25, left: 15, right: 5}
605
+ * });
606
+ * ```
607
+ * @see Used by {@link BoxZoomHandler}
608
+ */
609
+ fitScreenCoordinates(p0, p1, bearing, options, eventData) {
610
+ return this._fitInternal(this._cameraForBoxAndBearing(this.transform.pointLocation(_pointGeometry.default.convert(p0)), this.transform.pointLocation(_pointGeometry.default.convert(p1)), bearing, options), options, eventData);
611
+ }
612
+ _fitInternal(calculatedOptions, options, eventData) {
613
+ // cameraForBounds warns + returns undefined if unable to fit:
614
+ if (!calculatedOptions) return this;
615
+ options = (0, _util.extend)(calculatedOptions, options);
616
+ // Explicitly remove the padding field because, calculatedOptions already accounts for padding by setting zoom and center accordingly.
617
+ delete options.padding;
618
+ return options.linear ? this.easeTo(options, eventData) : this.flyTo(options, eventData);
619
+ }
620
+
621
+ /**
622
+ * Changes any combination of center, zoom, bearing, and pitch, without
623
+ * an animated transition. The map will retain its current values for any
624
+ * details not specified in `options`.
625
+ *
626
+ * Triggers the following events: `movestart`, `move`, `moveend`, `zoomstart`, `zoom`, `zoomend`, `pitchstart`,
627
+ * `pitch`, `pitchend`, and `rotate`.
628
+ *
629
+ * @param options - Options object
630
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
631
+ * @example
632
+ * ```ts
633
+ * // jump to coordinates at current zoom
634
+ * map.jumpTo({center: [0, 0]});
635
+ * // jump with zoom, pitch, and bearing options
636
+ * map.jumpTo({
637
+ * center: [0, 0],
638
+ * zoom: 8,
639
+ * pitch: 45,
640
+ * bearing: 90
641
+ * });
642
+ * ```
643
+ * @see [Jump to a series of locations](https://maplibre.org/maplibre-gl-js/docs/examples/jump-to/)
644
+ * @see [Update a feature in realtime](https://maplibre.org/maplibre-gl-js/docs/examples/live-update-feature/)
645
+ */
646
+ jumpTo(options, eventData) {
647
+ this.stop();
648
+ const tr = this._getTransformForUpdate();
649
+ let zoomChanged = false,
650
+ bearingChanged = false,
651
+ pitchChanged = false;
652
+ if ('zoom' in options && tr.zoom !== +options.zoom) {
653
+ zoomChanged = true;
654
+ tr.zoom = +options.zoom;
655
+ }
656
+ if (options.center !== undefined) {
657
+ tr.center = _lng_lat.LngLat.convert(options.center);
658
+ }
659
+ if ('bearing' in options && tr.bearing !== +options.bearing) {
660
+ bearingChanged = true;
661
+ tr.bearing = +options.bearing;
662
+ }
663
+ if ('pitch' in options && tr.pitch !== +options.pitch) {
664
+ pitchChanged = true;
665
+ tr.pitch = +options.pitch;
666
+ }
667
+ if (options.padding != null && !tr.isPaddingEqual(options.padding)) {
668
+ tr.padding = options.padding;
669
+ }
670
+ this._applyUpdatedTransform(tr);
671
+ this.fire(new _evented.Event('movestart', eventData)).fire(new _evented.Event('move', eventData));
672
+ if (zoomChanged) {
673
+ this.fire(new _evented.Event('zoomstart', eventData)).fire(new _evented.Event('zoom', eventData)).fire(new _evented.Event('zoomend', eventData));
674
+ }
675
+ if (bearingChanged) {
676
+ this.fire(new _evented.Event('rotatestart', eventData)).fire(new _evented.Event('rotate', eventData)).fire(new _evented.Event('rotateend', eventData));
677
+ }
678
+ if (pitchChanged) {
679
+ this.fire(new _evented.Event('pitchstart', eventData)).fire(new _evented.Event('pitch', eventData)).fire(new _evented.Event('pitchend', eventData));
680
+ }
681
+ return this.fire(new _evented.Event('moveend', eventData));
682
+ }
683
+
684
+ /**
685
+ * Calculates pitch, zoom and bearing for looking at `newCenter` with the camera position being `newCenter`
686
+ * and returns them as {@link CameraOptions}.
687
+ * @param from - The camera to look from
688
+ * @param altitudeFrom - The altitude of the camera to look from
689
+ * @param to - The center to look at
690
+ * @param altitudeTo - Optional altitude of the center to look at. If none given the ground height will be used.
691
+ * @returns the calculated camera options
692
+ */
693
+ calculateCameraOptionsFromTo(from, altitudeFrom, to, altitudeTo = 0) {
694
+ const fromMerc = _mercator_coordinate.MercatorCoordinate.fromLngLat(from, altitudeFrom);
695
+ const toMerc = _mercator_coordinate.MercatorCoordinate.fromLngLat(to, altitudeTo);
696
+ const dx = toMerc.x - fromMerc.x;
697
+ const dy = toMerc.y - fromMerc.y;
698
+ const dz = toMerc.z - fromMerc.z;
699
+ const distance3D = Math.hypot(dx, dy, dz);
700
+ if (distance3D === 0) throw new Error("Can't calculate camera options with same From and To");
701
+ const groundDistance = Math.hypot(dx, dy);
702
+ const zoom = this.transform.scaleZoom(this.transform.cameraToCenterDistance / distance3D / this.transform.tileSize);
703
+ const bearing = Math.atan2(dx, -dy) * 180 / Math.PI;
704
+ let pitch = Math.acos(groundDistance / distance3D) * 180 / Math.PI;
705
+ pitch = dz < 0 ? 90 - pitch : 90 + pitch;
706
+ return {
707
+ center: toMerc.toLngLat(),
708
+ zoom,
709
+ pitch,
710
+ bearing
711
+ };
712
+ }
713
+
714
+ /**
715
+ * Changes any combination of `center`, `zoom`, `bearing`, `pitch`, and `padding` with an animated transition
716
+ * between old and new values. The map will retain its current values for any
717
+ * details not specified in `options`.
718
+ *
719
+ * Note: The transition will happen instantly if the user has enabled
720
+ * the `reduced motion` accessibility feature enabled in their operating system,
721
+ * unless `options` includes `essential: true`.
722
+ *
723
+ * Triggers the following events: `movestart`, `move`, `moveend`, `zoomstart`, `zoom`, `zoomend`, `pitchstart`,
724
+ * `pitch`, `pitchend`, and `rotate`.
725
+ *
726
+ * @param options - Options describing the destination and animation of the transition.
727
+ * Accepts {@link CameraOptions} and {@link AnimationOptions}.
728
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
729
+ * @see [Navigate the map with game-like controls](https://maplibre.org/maplibre-gl-js/docs/examples/game-controls/)
730
+ */
731
+ easeTo(options, eventData) {
732
+ var _options$zoom;
733
+ this._stop(false, options.easeId);
734
+ options = (0, _util.extend)({
735
+ offset: [0, 0],
736
+ duration: 500,
737
+ easing: _util.defaultEasing
738
+ }, options);
739
+ if (options.animate === false || !options.essential && _browser.browser.prefersReducedMotion) options.duration = 0;
740
+ const tr = this._getTransformForUpdate(),
741
+ startZoom = this.getZoom(),
742
+ startBearing = this.getBearing(),
743
+ startPitch = this.getPitch(),
744
+ startPadding = this.getPadding(),
745
+ bearing = 'bearing' in options ? this._normalizeBearing(options.bearing, startBearing) : startBearing,
746
+ pitch = 'pitch' in options ? +options.pitch : startPitch,
747
+ padding = 'padding' in options ? options.padding : tr.padding;
748
+ const offsetAsPoint = _pointGeometry.default.convert(options.offset);
749
+ let pointAtOffset = tr.centerPoint.add(offsetAsPoint);
750
+ const locationAtOffset = tr.pointLocation(pointAtOffset);
751
+ const {
752
+ center,
753
+ zoom
754
+ } = tr.getConstrained(_lng_lat.LngLat.convert(options.center || locationAtOffset), (_options$zoom = options.zoom) !== null && _options$zoom !== void 0 ? _options$zoom : startZoom);
755
+ this._normalizeCenter(center);
756
+ const from = tr.project(locationAtOffset);
757
+ const delta = tr.project(center).sub(from);
758
+ const finalScale = tr.zoomScale(zoom - startZoom);
759
+ let around, aroundPoint;
760
+ if (options.around) {
761
+ around = _lng_lat.LngLat.convert(options.around);
762
+ aroundPoint = tr.locationPoint(around);
763
+ }
764
+ const currently = {
765
+ moving: this._moving,
766
+ zooming: this._zooming,
767
+ rotating: this._rotating,
768
+ pitching: this._pitching
769
+ };
770
+ this._zooming = this._zooming || zoom !== startZoom;
771
+ this._rotating = this._rotating || startBearing !== bearing;
772
+ this._pitching = this._pitching || pitch !== startPitch;
773
+ this._padding = !tr.isPaddingEqual(padding);
774
+ this._easeId = options.easeId;
775
+ this._prepareEase(eventData, options.noMoveStart, currently);
776
+ this._ease(k => {
777
+ if (this._zooming) {
778
+ tr.zoom = _util.interpolates.number(startZoom, zoom, k);
779
+ }
780
+ if (this._rotating) {
781
+ tr.bearing = _util.interpolates.number(startBearing, bearing, k);
782
+ }
783
+ if (this._pitching) {
784
+ tr.pitch = _util.interpolates.number(startPitch, pitch, k);
785
+ }
786
+ if (this._padding) {
787
+ tr.interpolatePadding(startPadding, padding, k);
788
+ // When padding is being applied, Transform#centerPoint is changing continuously,
789
+ // thus we need to recalculate offsetPoint every frame
790
+ pointAtOffset = tr.centerPoint.add(offsetAsPoint);
791
+ }
792
+ if (around) {
793
+ tr.setLocationAtPoint(around, aroundPoint);
794
+ } else {
795
+ const scale = tr.zoomScale(tr.zoom - startZoom);
796
+ const base = zoom > startZoom ? Math.min(2, finalScale) : Math.max(0.5, finalScale);
797
+ const speedup = Math.pow(base, 1 - k);
798
+ const newCenter = tr.unproject(from.add(delta.mult(k * speedup)).mult(scale));
799
+ tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
800
+ }
801
+ this._applyUpdatedTransform(tr);
802
+ this._fireMoveEvents(eventData);
803
+ }, interruptingEaseId => {
804
+ this._afterEase(eventData, interruptingEaseId);
805
+ }, options);
806
+ return this;
807
+ }
808
+ _prepareEase(eventData, noMoveStart, currently = {}) {
809
+ this._moving = true;
810
+ if (!noMoveStart && !currently.moving) {
811
+ this.fire(new _evented.Event('movestart', eventData));
812
+ }
813
+ if (this._zooming && !currently.zooming) {
814
+ this.fire(new _evented.Event('zoomstart', eventData));
815
+ }
816
+ if (this._rotating && !currently.rotating) {
817
+ this.fire(new _evented.Event('rotatestart', eventData));
818
+ }
819
+ if (this._pitching && !currently.pitching) {
820
+ this.fire(new _evented.Event('pitchstart', eventData));
821
+ }
822
+ }
823
+
824
+ /**
825
+ * @internal
826
+ * Called when the camera is about to be manipulated.
827
+ * If `transformCameraUpdate` is specified, a copy of the current transform is created to track the accumulated changes.
828
+ * This underlying transform represents the "desired state" proposed by input handlers / animations / UI controls.
829
+ * It may differ from the state used for rendering (`this.transform`).
830
+ * @returns Transform to apply changes to
831
+ */
832
+ _getTransformForUpdate() {
833
+ if (!this.transformCameraUpdate) return this.transform;
834
+ if (!this._requestedCameraState) {
835
+ this._requestedCameraState = this.transform.clone();
836
+ }
837
+ return this._requestedCameraState;
838
+ }
839
+
840
+ /**
841
+ * @internal
842
+ * Called after the camera is done being manipulated.
843
+ * @param tr - the requested camera end state
844
+ * Call `transformCameraUpdate` if present, and then apply the "approved" changes.
845
+ */
846
+ _applyUpdatedTransform(tr) {
847
+ if (!this.transformCameraUpdate) return;
848
+ const nextTransform = tr.clone();
849
+ const {
850
+ center,
851
+ zoom,
852
+ pitch,
853
+ bearing,
854
+ elevation
855
+ } = this.transformCameraUpdate(nextTransform);
856
+ if (center) nextTransform.center = center;
857
+ if (zoom !== undefined) nextTransform.zoom = zoom;
858
+ if (pitch !== undefined) nextTransform.pitch = pitch;
859
+ if (bearing !== undefined) nextTransform.bearing = bearing;
860
+ if (elevation !== undefined) nextTransform.elevation = elevation;
861
+ this.transform.apply(nextTransform);
862
+ }
863
+ _fireMoveEvents(eventData) {
864
+ this.fire(new _evented.Event('move', eventData));
865
+ if (this._zooming) {
866
+ this.fire(new _evented.Event('zoom', eventData));
867
+ }
868
+ if (this._rotating) {
869
+ this.fire(new _evented.Event('rotate', eventData));
870
+ }
871
+ if (this._pitching) {
872
+ this.fire(new _evented.Event('pitch', eventData));
873
+ }
874
+ }
875
+ _afterEase(eventData, easeId) {
876
+ // if this easing is being stopped to start another easing with
877
+ // the same id then don't fire any events to avoid extra start/stop events
878
+ if (this._easeId && easeId && this._easeId === easeId) {
879
+ return;
880
+ }
881
+ delete this._easeId;
882
+ const wasZooming = this._zooming;
883
+ const wasRotating = this._rotating;
884
+ const wasPitching = this._pitching;
885
+ this._moving = false;
886
+ this._zooming = false;
887
+ this._rotating = false;
888
+ this._pitching = false;
889
+ this._padding = false;
890
+ if (wasZooming) {
891
+ this.fire(new _evented.Event('zoomend', eventData));
892
+ }
893
+ if (wasRotating) {
894
+ this.fire(new _evented.Event('rotateend', eventData));
895
+ }
896
+ if (wasPitching) {
897
+ this.fire(new _evented.Event('pitchend', eventData));
898
+ }
899
+ this.fire(new _evented.Event('moveend', eventData));
900
+ }
901
+
902
+ /**
903
+ * Changes any combination of center, zoom, bearing, and pitch, animating the transition along a curve that
904
+ * evokes flight. The animation seamlessly incorporates zooming and panning to help
905
+ * the user maintain her bearings even after traversing a great distance.
906
+ *
907
+ * Note: The animation will be skipped, and this will behave equivalently to `jumpTo`
908
+ * if the user has the `reduced motion` accessibility feature enabled in their operating system,
909
+ * unless 'options' includes `essential: true`.
910
+ *
911
+ * Triggers the following events: `movestart`, `move`, `moveend`, `zoomstart`, `zoom`, `zoomend`, `pitchstart`,
912
+ * `pitch`, `pitchend`, and `rotate`.
913
+ *
914
+ * @param options - Options describing the destination and animation of the transition.
915
+ * Accepts {@link CameraOptions}, {@link AnimationOptions},
916
+ * and the following additional options.
917
+ * @param eventData - Additional properties to be added to event objects of events triggered by this method.
918
+ * @example
919
+ * ```ts
920
+ * // fly with default options to null island
921
+ * map.flyTo({center: [0, 0], zoom: 9});
922
+ * // using flyTo options
923
+ * map.flyTo({
924
+ * center: [0, 0],
925
+ * zoom: 9,
926
+ * speed: 0.2,
927
+ * curve: 1,
928
+ * easing(t) {
929
+ * return t;
930
+ * }
931
+ * });
932
+ * ```
933
+ * @see [Fly to a location](https://maplibre.org/maplibre-gl-js/docs/examples/flyto/)
934
+ * @see [Slowly fly to a location](https://maplibre.org/maplibre-gl-js/docs/examples/flyto-options/)
935
+ * @see [Fly to a location based on scroll position](https://maplibre.org/maplibre-gl-js/docs/examples/scroll-fly-to/)
936
+ */
937
+ flyTo(options, eventData) {
938
+ var _options$zoom2;
939
+ // Fall through to jumpTo if user has set prefers-reduced-motion
940
+ if (!options.essential && _browser.browser.prefersReducedMotion) {
941
+ const coercedOptions = (0, _util.pick)(options, ['center', 'zoom', 'bearing', 'pitch', 'around']);
942
+ return this.jumpTo(coercedOptions, eventData);
943
+ }
944
+
945
+ // This method implements an “optimal path” animation, as detailed in:
946
+ //
947
+ // Van Wijk, Jarke J.; Nuij, Wim A. A. “Smooth and efficient zooming and panning.” INFOVIS
948
+ // ’03. pp. 15–22. <https://www.win.tue.nl/~vanwijk/zoompan.pdf#page=5>.
949
+ //
950
+ // Where applicable, local variable documentation begins with the associated variable or
951
+ // function in van Wijk (2003).
952
+
953
+ this.stop();
954
+ options = (0, _util.extend)({
955
+ offset: [0, 0],
956
+ speed: 1.2,
957
+ curve: 1.42,
958
+ easing: _util.defaultEasing
959
+ }, options);
960
+ const tr = this._getTransformForUpdate(),
961
+ startZoom = this.getZoom(),
962
+ startBearing = this.getBearing(),
963
+ startPitch = this.getPitch(),
964
+ startPadding = this.getPadding();
965
+ const bearing = 'bearing' in options ? this._normalizeBearing(options.bearing, startBearing) : startBearing;
966
+ const pitch = 'pitch' in options ? +options.pitch : startPitch;
967
+ const padding = 'padding' in options ? options.padding : tr.padding;
968
+ const offsetAsPoint = _pointGeometry.default.convert(options.offset);
969
+ let pointAtOffset = tr.centerPoint.add(offsetAsPoint);
970
+ const locationAtOffset = tr.pointLocation(pointAtOffset);
971
+ const {
972
+ center,
973
+ zoom
974
+ } = tr.getConstrained(_lng_lat.LngLat.convert(options.center || locationAtOffset), (_options$zoom2 = options.zoom) !== null && _options$zoom2 !== void 0 ? _options$zoom2 : startZoom);
975
+ this._normalizeCenter(center);
976
+ const scale = tr.zoomScale(zoom - startZoom);
977
+ const from = tr.project(locationAtOffset);
978
+ const delta = tr.project(center).sub(from);
979
+ let rho = options.curve;
980
+
981
+ // w₀: Initial visible span, measured in pixels at the initial scale.
982
+ const w0 = Math.max(tr.width, tr.height),
983
+ // w₁: Final visible span, measured in pixels with respect to the initial scale.
984
+ w1 = w0 / scale,
985
+ // Length of the flight path as projected onto the ground plane, measured in pixels from
986
+ // the world image origin at the initial scale.
987
+ u1 = delta.mag();
988
+ if ('minZoom' in options) {
989
+ const minZoom = (0, _util.clamp)(Math.min(options.minZoom, startZoom, zoom), tr.minZoom, tr.maxZoom);
990
+ // w<sub>m</sub>: Maximum visible span, measured in pixels with respect to the initial
991
+ // scale.
992
+ const wMax = w0 / tr.zoomScale(minZoom - startZoom);
993
+ rho = Math.sqrt(wMax / u1 * 2);
994
+ }
995
+
996
+ // ρ²
997
+ const rho2 = rho * rho;
998
+
999
+ /**
1000
+ * rᵢ: Returns the zoom-out factor at one end of the animation.
1001
+ *
1002
+ * @param descent - `true` for the descent, `false` for the ascent
1003
+ */
1004
+ function zoomOutFactor(descent) {
1005
+ const b = (w1 * w1 - w0 * w0 + (descent ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (descent ? w1 : w0) * rho2 * u1);
1006
+ return Math.log(Math.sqrt(b * b + 1) - b);
1007
+ }
1008
+ function sinh(n) {
1009
+ return (Math.exp(n) - Math.exp(-n)) / 2;
1010
+ }
1011
+ function cosh(n) {
1012
+ return (Math.exp(n) + Math.exp(-n)) / 2;
1013
+ }
1014
+ function tanh(n) {
1015
+ return sinh(n) / cosh(n);
1016
+ }
1017
+
1018
+ // r₀: Zoom-out factor during ascent.
1019
+ const r0 = zoomOutFactor(false);
1020
+
1021
+ // w(s): Returns the visible span on the ground, measured in pixels with respect to the
1022
+ // initial scale. Assumes an angular field of view of 2 arctan ½ ≈ 53°.
1023
+ let w = function (s) {
1024
+ return cosh(r0) / cosh(r0 + rho * s);
1025
+ };
1026
+
1027
+ // u(s): Returns the distance along the flight path as projected onto the ground plane,
1028
+ // measured in pixels from the world image origin at the initial scale.
1029
+ let u = function (s) {
1030
+ return w0 * ((cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2) / u1;
1031
+ };
1032
+
1033
+ // S: Total length of the flight path, measured in ρ-screenfuls.
1034
+ let S = (zoomOutFactor(true) - r0) / rho;
1035
+
1036
+ // When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
1037
+ if (Math.abs(u1) < 0.000001 || !isFinite(S)) {
1038
+ // Perform a more or less instantaneous transition if the path is too short.
1039
+ if (Math.abs(w0 - w1) < 0.000001) return this.easeTo(options, eventData);
1040
+ const k = w1 < w0 ? -1 : 1;
1041
+ S = Math.abs(Math.log(w1 / w0)) / rho;
1042
+ u = () => 0;
1043
+ w = s => Math.exp(k * rho * s);
1044
+ }
1045
+ if ('duration' in options) {
1046
+ options.duration = +options.duration;
1047
+ } else {
1048
+ const V = 'screenSpeed' in options ? +options.screenSpeed / rho : +options.speed;
1049
+ options.duration = 1000 * S / V;
1050
+ }
1051
+ if (options.maxDuration && options.duration > options.maxDuration) {
1052
+ options.duration = 0;
1053
+ }
1054
+ this._zooming = true;
1055
+ this._rotating = startBearing !== bearing;
1056
+ this._pitching = pitch !== startPitch;
1057
+ this._padding = !tr.isPaddingEqual(padding);
1058
+ this._prepareEase(eventData, false);
1059
+ this._ease(k => {
1060
+ // s: The distance traveled along the flight path, measured in ρ-screenfuls.
1061
+ const s = k * S;
1062
+ const scale = 1 / w(s);
1063
+ tr.zoom = k === 1 ? zoom : startZoom + tr.scaleZoom(scale);
1064
+ if (this._rotating) {
1065
+ tr.bearing = _util.interpolates.number(startBearing, bearing, k);
1066
+ }
1067
+ if (this._pitching) {
1068
+ tr.pitch = _util.interpolates.number(startPitch, pitch, k);
1069
+ }
1070
+ if (this._padding) {
1071
+ tr.interpolatePadding(startPadding, padding, k);
1072
+ // When padding is being applied, Transform#centerPoint is changing continuously,
1073
+ // thus we need to recalculate offsetPoint every frame
1074
+ pointAtOffset = tr.centerPoint.add(offsetAsPoint);
1075
+ }
1076
+ const newCenter = k === 1 ? center : tr.unproject(from.add(delta.mult(u(s))).mult(scale));
1077
+ tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
1078
+ this._applyUpdatedTransform(tr);
1079
+ this._fireMoveEvents(eventData);
1080
+ }, () => {
1081
+ this._afterEase(eventData);
1082
+ }, options);
1083
+ return this;
1084
+ }
1085
+ isEasing() {
1086
+ return !!this._easeFrameId;
1087
+ }
1088
+
1089
+ /**
1090
+ * Stops any animated transition underway.
1091
+ */
1092
+ stop() {
1093
+ return this._stop();
1094
+ }
1095
+ _stop(allowGestures, easeId) {
1096
+ if (this._easeFrameId) {
1097
+ this._cancelRenderFrame(this._easeFrameId);
1098
+ delete this._easeFrameId;
1099
+ delete this._onEaseFrame;
1100
+ }
1101
+ if (this._onEaseEnd) {
1102
+ // The _onEaseEnd function might emit events which trigger new
1103
+ // animation, which sets a new _onEaseEnd. Ensure we don't delete
1104
+ // it unintentionally.
1105
+ const onEaseEnd = this._onEaseEnd;
1106
+ delete this._onEaseEnd;
1107
+ onEaseEnd.call(this, easeId);
1108
+ }
1109
+ if (!allowGestures) {
1110
+ var _this$handlers;
1111
+ (_this$handlers = this.handlers) === null || _this$handlers === void 0 || _this$handlers.stop(false);
1112
+ }
1113
+ return this;
1114
+ }
1115
+ _ease(frame, finish, options) {
1116
+ if (options.animate === false || options.duration === 0) {
1117
+ frame(1);
1118
+ finish();
1119
+ } else {
1120
+ this._easeStart = _browser.browser.now();
1121
+ this._easeOptions = options;
1122
+ this._onEaseFrame = frame;
1123
+ this._onEaseEnd = finish;
1124
+ this._easeFrameId = this._requestRenderFrame(this._renderFrameCallback);
1125
+ }
1126
+ }
1127
+ // convert bearing so that it's numerically close to the current one so that it interpolates properly
1128
+ _normalizeBearing(bearing, currentBearing) {
1129
+ bearing = (0, _util.wrap)(bearing, -180, 180);
1130
+ const diff = Math.abs(bearing - currentBearing);
1131
+ if (Math.abs(bearing - 360 - currentBearing) < diff) bearing -= 360;
1132
+ if (Math.abs(bearing + 360 - currentBearing) < diff) bearing += 360;
1133
+ return bearing;
1134
+ }
1135
+
1136
+ // If a path crossing the antimeridian would be shorter, extend the final coordinate so that
1137
+ // interpolating between the two endpoints will cross it.
1138
+ _normalizeCenter(center) {
1139
+ const tr = this.transform;
1140
+ if (!tr.renderWorldCopies || tr.lngRange) return;
1141
+ const delta = center.lng - tr.center.lng;
1142
+ center.lng += delta > 180 ? -360 : delta < -180 ? 360 : 0;
1143
+ }
1144
+ }
1145
+ exports.Camera = Camera;