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