@antv/l7-map 2.21.1 → 2.21.3

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 (158) hide show
  1. package/es/camera.js +595 -674
  2. package/es/earthmap.js +313 -276
  3. package/es/geo/edge_insets.js +57 -72
  4. package/es/geo/lng_lat.js +50 -64
  5. package/es/geo/lng_lat_bounds.js +101 -137
  6. package/es/geo/mercator.js +23 -35
  7. package/es/geo/point.js +150 -221
  8. package/es/geo/simple.js +22 -34
  9. package/es/geo/transform.js +839 -905
  10. package/es/handler/blockable_map_event.js +46 -66
  11. package/es/handler/box_zoom.js +125 -143
  12. package/es/handler/click_zoom.js +37 -51
  13. package/es/handler/events/event.js +11 -9
  14. package/es/handler/events/map_mouse_event.js +39 -54
  15. package/es/handler/events/map_touch_event.js +54 -73
  16. package/es/handler/events/map_wheel_event.js +22 -38
  17. package/es/handler/events/render_event.js +6 -23
  18. package/es/handler/handler_inertia.js +98 -113
  19. package/es/handler/handler_manager.js +349 -437
  20. package/es/handler/handler_util.js +2 -2
  21. package/es/handler/keyboard.js +98 -110
  22. package/es/handler/map_event.js +81 -117
  23. package/es/handler/mouse/mouse_handler.js +81 -100
  24. package/es/handler/mouse/mousepan_handler.js +16 -39
  25. package/es/handler/mouse/mousepitch_hander.js +18 -40
  26. package/es/handler/mouse/mouserotate_hander.js +18 -40
  27. package/es/handler/mouse/util.js +7 -5
  28. package/es/handler/scroll_zoom.js +221 -231
  29. package/es/handler/shim/dblclick_zoom.js +36 -47
  30. package/es/handler/shim/drag_pan.js +41 -50
  31. package/es/handler/shim/drag_rotate.js +38 -48
  32. package/es/handler/shim/touch_zoom_rotate.js +68 -79
  33. package/es/handler/tap/single_tap_recognizer.js +60 -80
  34. package/es/handler/tap/tap_drag_zoom.js +72 -89
  35. package/es/handler/tap/tap_recognizer.js +37 -45
  36. package/es/handler/tap/tap_zoom.js +67 -95
  37. package/es/handler/touch/touch_pan.js +77 -96
  38. package/es/handler/touch/touch_pitch.js +61 -79
  39. package/es/handler/touch/touch_rotate.js +47 -67
  40. package/es/handler/touch/touch_zoom.js +29 -46
  41. package/es/handler/touch/two_touch.js +79 -104
  42. package/es/hash.js +75 -88
  43. package/es/map.js +318 -284
  44. package/es/util.js +18 -37
  45. package/es/utils/Aabb.js +60 -100
  46. package/es/utils/dom.js +32 -55
  47. package/es/utils/performance.js +25 -29
  48. package/es/utils/primitives.js +33 -42
  49. package/es/utils/task_queue.js +47 -76
  50. package/lib/camera.d.ts +86 -0
  51. package/lib/camera.js +597 -672
  52. package/lib/earthmap.d.ts +69 -0
  53. package/lib/earthmap.js +314 -276
  54. package/lib/geo/edge_insets.d.ts +54 -0
  55. package/lib/geo/edge_insets.js +58 -70
  56. package/lib/geo/lng_lat.d.ts +18 -0
  57. package/lib/geo/lng_lat.js +50 -62
  58. package/lib/geo/lng_lat_bounds.d.ts +25 -0
  59. package/lib/geo/lng_lat_bounds.js +102 -136
  60. package/lib/geo/mercator.d.ts +30 -0
  61. package/lib/geo/mercator.js +26 -37
  62. package/lib/geo/point.d.ts +40 -0
  63. package/lib/geo/point.js +151 -220
  64. package/lib/geo/simple.d.ts +30 -0
  65. package/lib/geo/simple.js +25 -36
  66. package/lib/geo/transform.d.ts +198 -0
  67. package/lib/geo/transform.js +844 -907
  68. package/lib/handler/IHandler.d.ts +34 -0
  69. package/lib/handler/blockable_map_event.d.ts +17 -0
  70. package/lib/handler/blockable_map_event.js +48 -65
  71. package/lib/handler/box_zoom.d.ts +59 -0
  72. package/lib/handler/box_zoom.js +126 -143
  73. package/lib/handler/click_zoom.d.ts +16 -0
  74. package/lib/handler/click_zoom.js +38 -50
  75. package/lib/handler/events/event.d.ts +4 -0
  76. package/lib/handler/events/event.js +12 -9
  77. package/lib/handler/events/index.d.ts +4 -0
  78. package/lib/handler/events/index.js +3 -3
  79. package/lib/handler/events/map_mouse_event.d.ts +34 -0
  80. package/lib/handler/events/map_mouse_event.js +41 -52
  81. package/lib/handler/events/map_touch_event.d.ts +57 -0
  82. package/lib/handler/events/map_touch_event.js +56 -71
  83. package/lib/handler/events/map_wheel_event.d.ts +33 -0
  84. package/lib/handler/events/map_wheel_event.js +23 -37
  85. package/lib/handler/events/render_event.d.ts +5 -0
  86. package/lib/handler/events/render_event.js +7 -22
  87. package/lib/handler/handler_inertia.d.ts +23 -0
  88. package/lib/handler/handler_inertia.js +102 -112
  89. package/lib/handler/handler_manager.d.ts +61 -0
  90. package/lib/handler/handler_manager.js +351 -437
  91. package/lib/handler/handler_util.d.ts +4 -0
  92. package/lib/handler/handler_util.js +2 -2
  93. package/lib/handler/keyboard.d.ts +36 -0
  94. package/lib/handler/keyboard.js +98 -110
  95. package/lib/handler/map_event.d.ts +29 -0
  96. package/lib/handler/map_event.js +83 -116
  97. package/lib/handler/mouse/index.d.ts +4 -0
  98. package/lib/handler/mouse/index.js +3 -3
  99. package/lib/handler/mouse/mouse_handler.d.ts +22 -0
  100. package/lib/handler/mouse/mouse_handler.js +83 -99
  101. package/lib/handler/mouse/mousepan_handler.d.ts +10 -0
  102. package/lib/handler/mouse/mousepan_handler.js +19 -38
  103. package/lib/handler/mouse/mousepitch_hander.d.ts +9 -0
  104. package/lib/handler/mouse/mousepitch_hander.js +21 -39
  105. package/lib/handler/mouse/mouserotate_hander.d.ts +9 -0
  106. package/lib/handler/mouse/mouserotate_hander.js +21 -39
  107. package/lib/handler/mouse/util.d.ts +6 -0
  108. package/lib/handler/mouse/util.js +7 -6
  109. package/lib/handler/scroll_zoom.d.ts +93 -0
  110. package/lib/handler/scroll_zoom.js +221 -231
  111. package/lib/handler/shim/dblclick_zoom.d.ts +40 -0
  112. package/lib/handler/shim/dblclick_zoom.js +37 -46
  113. package/lib/handler/shim/drag_pan.d.ts +61 -0
  114. package/lib/handler/shim/drag_pan.js +42 -49
  115. package/lib/handler/shim/drag_rotate.d.ts +46 -0
  116. package/lib/handler/shim/drag_rotate.js +39 -47
  117. package/lib/handler/shim/touch_zoom_rotate.d.ts +70 -0
  118. package/lib/handler/shim/touch_zoom_rotate.js +69 -78
  119. package/lib/handler/tap/single_tap_recognizer.d.ts +20 -0
  120. package/lib/handler/tap/single_tap_recognizer.js +63 -79
  121. package/lib/handler/tap/tap_drag_zoom.d.ts +22 -0
  122. package/lib/handler/tap/tap_drag_zoom.js +74 -88
  123. package/lib/handler/tap/tap_recognizer.d.ts +17 -0
  124. package/lib/handler/tap/tap_recognizer.js +41 -47
  125. package/lib/handler/tap/tap_zoom.d.ts +22 -0
  126. package/lib/handler/tap/tap_zoom.js +69 -94
  127. package/lib/handler/touch/index.d.ts +5 -0
  128. package/lib/handler/touch/index.js +4 -4
  129. package/lib/handler/touch/touch_pan.d.ts +30 -0
  130. package/lib/handler/touch/touch_pan.js +79 -95
  131. package/lib/handler/touch/touch_pitch.d.ts +13 -0
  132. package/lib/handler/touch/touch_pitch.js +64 -78
  133. package/lib/handler/touch/touch_rotate.d.ts +12 -0
  134. package/lib/handler/touch/touch_rotate.js +50 -66
  135. package/lib/handler/touch/touch_zoom.d.ts +12 -0
  136. package/lib/handler/touch/touch_zoom.js +32 -45
  137. package/lib/handler/touch/two_touch.d.ts +23 -0
  138. package/lib/handler/touch/two_touch.js +81 -103
  139. package/lib/hash.d.ts +14 -0
  140. package/lib/hash.js +75 -88
  141. package/lib/index.d.ts +4 -0
  142. package/lib/index.js +4 -4
  143. package/lib/interface.d.ts +34 -0
  144. package/lib/map.d.ts +70 -0
  145. package/lib/map.js +319 -284
  146. package/lib/util.d.ts +25 -0
  147. package/lib/util.js +20 -36
  148. package/lib/utils/Aabb.d.ts +12 -0
  149. package/lib/utils/Aabb.js +61 -99
  150. package/lib/utils/dom.d.ts +4 -0
  151. package/lib/utils/dom.js +34 -55
  152. package/lib/utils/performance.d.ts +17 -0
  153. package/lib/utils/performance.js +25 -29
  154. package/lib/utils/primitives.d.ts +6 -0
  155. package/lib/utils/primitives.js +34 -41
  156. package/lib/utils/task_queue.d.ts +13 -0
  157. package/lib/utils/task_queue.js +47 -76
  158. package/package.json +25 -32
package/es/camera.js CHANGED
@@ -1,12 +1,4 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/esm/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
7
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
2
  // @ts-ignore
11
3
  import { lodashUtil } from '@antv/l7-utils';
12
4
  import { EventEmitter } from 'eventemitter3';
@@ -16,703 +8,632 @@ import Point from "./geo/point";
16
8
  import Transform from "./geo/transform";
17
9
  import { Event } from "./handler/events/event";
18
10
  import { clamp, ease as defaultEasing, extend, interpolate, now, pick, prefersReducedMotion, wrap } from "./util";
19
- var merge = lodashUtil.merge;
20
- var Camera = /*#__PURE__*/function (_EventEmitter) {
21
- _inherits(Camera, _EventEmitter);
22
- var _super = _createSuper(Camera);
23
- // public requestRenderFrame: (_: any) => number;
24
- // public cancelRenderFrame: (_: number) => void;
25
-
26
- function Camera(options) {
27
- var _this;
28
- _classCallCheck(this, Camera);
29
- _this = _super.call(this);
30
- _defineProperty(_assertThisInitialized(_this), "renderFrameCallback", function () {
31
- var t = Math.min((now() - _this.easeStart) / _this.easeOptions.duration, 1);
32
- _this.onEaseFrame(_this.easeOptions.easing(t));
11
+ const {
12
+ merge
13
+ } = lodashUtil;
14
+ export default class Camera extends EventEmitter {
15
+ constructor(options) {
16
+ super();
17
+ _defineProperty(this, "transform", void 0);
18
+ // public requestRenderFrame: (_: any) => number;
19
+ // public cancelRenderFrame: (_: number) => void;
20
+ _defineProperty(this, "options", void 0);
21
+ _defineProperty(this, "moving", void 0);
22
+ _defineProperty(this, "zooming", void 0);
23
+ _defineProperty(this, "rotating", void 0);
24
+ _defineProperty(this, "pitching", void 0);
25
+ _defineProperty(this, "padding", void 0);
26
+ _defineProperty(this, "bearingSnap", void 0);
27
+ _defineProperty(this, "easeEndTimeoutID", void 0);
28
+ _defineProperty(this, "easeStart", void 0);
29
+ _defineProperty(this, "easeOptions", void 0);
30
+ _defineProperty(this, "easeId", void 0);
31
+ _defineProperty(this, "onEaseFrame", void 0);
32
+ _defineProperty(this, "onEaseEnd", void 0);
33
+ _defineProperty(this, "easeFrameId", void 0);
34
+ _defineProperty(this, "pitchEnabled", void 0);
35
+ _defineProperty(this, "rotateEnabled", void 0);
36
+ _defineProperty(this, "renderFrameCallback", () => {
37
+ const t = Math.min((now() - this.easeStart) / this.easeOptions.duration, 1);
38
+ this.onEaseFrame(this.easeOptions.easing(t));
33
39
  if (t < 1) {
34
40
  // this.easeFrameId = window.requestAnimationFrame(this.renderFrameCallback);
35
- _this.easeFrameId = _this.requestRenderFrame(_this.renderFrameCallback);
41
+ this.easeFrameId = this.requestRenderFrame(this.renderFrameCallback);
36
42
  } else {
37
- _this.stop();
43
+ this.stop();
38
44
  }
39
45
  });
40
- _this.options = options;
41
- var minZoom = options.minZoom,
42
- maxZoom = options.maxZoom,
43
- minPitch = options.minPitch,
44
- maxPitch = options.maxPitch,
45
- renderWorldCopies = options.renderWorldCopies;
46
- _this.moving = false;
47
- _this.zooming = false;
48
- _this.bearingSnap = options.bearingSnap;
49
- _this.pitchEnabled = options.pitchEnabled;
50
- _this.rotateEnabled = options.rotateEnabled;
51
- _this.transform = new Transform(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies);
52
- return _this;
46
+ this.options = options;
47
+ const {
48
+ minZoom,
49
+ maxZoom,
50
+ minPitch,
51
+ maxPitch,
52
+ renderWorldCopies
53
+ } = options;
54
+ this.moving = false;
55
+ this.zooming = false;
56
+ this.bearingSnap = options.bearingSnap;
57
+ this.pitchEnabled = options.pitchEnabled;
58
+ this.rotateEnabled = options.rotateEnabled;
59
+ this.transform = new Transform(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies);
53
60
  }
54
61
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
55
- _createClass(Camera, [{
56
- key: "requestRenderFrame",
57
- value: function requestRenderFrame(cb) {
58
- return 0;
59
- }
60
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
61
- }, {
62
- key: "cancelRenderFrame",
63
- value: function cancelRenderFrame(_) {
64
- return;
65
- }
66
- }, {
67
- key: "getCenter",
68
- value: function getCenter() {
69
- var _this$transform$cente = this.transform.center,
70
- lng = _this$transform$cente.lng,
71
- lat = _this$transform$cente.lat;
72
- return new LngLat(lng, lat);
73
- }
74
- }, {
75
- key: "getZoom",
76
- value: function getZoom() {
77
- return this.transform.zoom;
78
- }
79
- }, {
80
- key: "getPitch",
81
- value: function getPitch() {
82
- return this.transform.pitch;
83
- }
84
- }, {
85
- key: "setCenter",
86
- value: function setCenter(center, eventData) {
87
- return this.jumpTo({
88
- center: center
89
- }, eventData);
90
- }
91
- }, {
92
- key: "setPitch",
93
- value: function setPitch(pitch, eventData) {
94
- this.jumpTo({
95
- pitch: pitch
96
- }, eventData);
97
- return this;
98
- }
99
- }, {
100
- key: "getBearing",
101
- value: function getBearing() {
102
- return this.transform.bearing;
103
- }
104
- }, {
105
- key: "panTo",
106
- value: function panTo(lnglat, options, eventData) {
107
- return this.easeTo(merge({
108
- center: lnglat
109
- }, options), eventData);
110
- }
111
- }, {
112
- key: "panBy",
113
- value: function panBy(offset, options, eventData) {
114
- offset = Point.convert(offset).mult(-1);
115
- return this.panTo(this.transform.center, extend({
116
- offset: offset
117
- }, options || {}), eventData);
118
- }
119
- }, {
120
- key: "zoomOut",
121
- value: function zoomOut(options, eventData) {
122
- this.zoomTo(this.getZoom() - 1, options, eventData);
123
- return this;
124
- }
125
- }, {
126
- key: "setBearing",
127
- value: function setBearing(bearing, eventData) {
128
- this.jumpTo({
129
- bearing: bearing
130
- }, eventData);
131
- return this;
132
- }
133
- }, {
134
- key: "setZoom",
135
- value: function setZoom(zoom, eventData) {
136
- this.jumpTo({
137
- zoom: zoom
138
- }, eventData);
139
- return this;
140
- }
141
- }, {
142
- key: "zoomIn",
143
- value: function zoomIn(options, eventData) {
144
- this.zoomTo(this.getZoom() + 1, options, eventData);
145
- return this;
146
- }
147
- }, {
148
- key: "zoomTo",
149
- value: function zoomTo(zoom, options, eventData) {
150
- return this.easeTo(merge({
151
- zoom: zoom
152
- }, options), eventData);
153
- }
154
- }, {
155
- key: "getPadding",
156
- value: function getPadding() {
157
- return this.transform.padding;
158
- }
159
- }, {
160
- key: "setPadding",
161
- value: function setPadding(padding, eventData) {
162
- this.jumpTo({
163
- padding: padding
164
- }, eventData);
165
- return this;
166
- }
167
- }, {
168
- key: "rotateTo",
169
- value: function rotateTo(bearing, options, eventData) {
170
- return this.easeTo(merge({
171
- bearing: bearing
172
- }, options), eventData);
173
- }
174
- }, {
175
- key: "resetNorth",
176
- value: function resetNorth(options, eventData) {
177
- this.rotateTo(0, merge({
178
- duration: 1000
179
- }, options), eventData);
180
- return this;
181
- }
182
- }, {
183
- key: "resetNorthPitch",
184
- value: function resetNorthPitch(options, eventData) {
185
- this.easeTo(merge({
186
- bearing: 0,
187
- pitch: 0,
188
- duration: 1000
189
- }, options), eventData);
190
- return this;
191
- }
192
- }, {
193
- key: "fitBounds",
194
- value: function fitBounds(bounds, options, eventData) {
195
- return this.fitInternal(
196
- // @ts-ignore
197
- this.cameraForBounds(bounds, options), options, eventData);
198
- }
199
- }, {
200
- key: "cameraForBounds",
201
- value: function cameraForBounds(bounds, options) {
202
- bounds = LngLatBounds.convert(bounds);
203
- return this.cameraForBoxAndBearing(bounds.getNorthWest(), bounds.getSouthEast(), 0,
204
- // @ts-ignore
205
- options);
206
- }
207
- }, {
208
- key: "snapToNorth",
209
- value: function snapToNorth(options, eventData) {
210
- if (Math.abs(this.getBearing()) < this.bearingSnap) {
211
- return this.resetNorth(options, eventData);
212
- }
213
- return this;
62
+ requestRenderFrame(cb) {
63
+ return 0;
64
+ }
65
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
66
+ cancelRenderFrame(_) {
67
+ return;
68
+ }
69
+ getCenter() {
70
+ const {
71
+ lng,
72
+ lat
73
+ } = this.transform.center;
74
+ return new LngLat(lng, lat);
75
+ }
76
+ getZoom() {
77
+ return this.transform.zoom;
78
+ }
79
+ getPitch() {
80
+ return this.transform.pitch;
81
+ }
82
+ setCenter(center, eventData) {
83
+ return this.jumpTo({
84
+ center
85
+ }, eventData);
86
+ }
87
+ setPitch(pitch, eventData) {
88
+ this.jumpTo({
89
+ pitch
90
+ }, eventData);
91
+ return this;
92
+ }
93
+ getBearing() {
94
+ return this.transform.bearing;
95
+ }
96
+ panTo(lnglat, options, eventData) {
97
+ return this.easeTo(merge({
98
+ center: lnglat
99
+ }, options), eventData);
100
+ }
101
+ panBy(offset, options, eventData) {
102
+ offset = Point.convert(offset).mult(-1);
103
+ return this.panTo(this.transform.center, extend({
104
+ offset
105
+ }, options || {}), eventData);
106
+ }
107
+ zoomOut(options, eventData) {
108
+ this.zoomTo(this.getZoom() - 1, options, eventData);
109
+ return this;
110
+ }
111
+ setBearing(bearing, eventData) {
112
+ this.jumpTo({
113
+ bearing
114
+ }, eventData);
115
+ return this;
116
+ }
117
+ setZoom(zoom, eventData) {
118
+ this.jumpTo({
119
+ zoom
120
+ }, eventData);
121
+ return this;
122
+ }
123
+ zoomIn(options, eventData) {
124
+ this.zoomTo(this.getZoom() + 1, options, eventData);
125
+ return this;
126
+ }
127
+ zoomTo(zoom, options, eventData) {
128
+ return this.easeTo(merge({
129
+ zoom
130
+ }, options), eventData);
131
+ }
132
+ getPadding() {
133
+ return this.transform.padding;
134
+ }
135
+ setPadding(padding, eventData) {
136
+ this.jumpTo({
137
+ padding
138
+ }, eventData);
139
+ return this;
140
+ }
141
+ rotateTo(bearing, options, eventData) {
142
+ return this.easeTo(merge({
143
+ bearing
144
+ }, options), eventData);
145
+ }
146
+ resetNorth(options, eventData) {
147
+ this.rotateTo(0, merge({
148
+ duration: 1000
149
+ }, options), eventData);
150
+ return this;
151
+ }
152
+ resetNorthPitch(options, eventData) {
153
+ this.easeTo(merge({
154
+ bearing: 0,
155
+ pitch: 0,
156
+ duration: 1000
157
+ }, options), eventData);
158
+ return this;
159
+ }
160
+ fitBounds(bounds, options, eventData) {
161
+ return this.fitInternal(
162
+ // @ts-ignore
163
+ this.cameraForBounds(bounds, options), options, eventData);
164
+ }
165
+ cameraForBounds(bounds, options) {
166
+ bounds = LngLatBounds.convert(bounds);
167
+ return this.cameraForBoxAndBearing(bounds.getNorthWest(), bounds.getSouthEast(), 0,
168
+ // @ts-ignore
169
+ options);
170
+ }
171
+ snapToNorth(options, eventData) {
172
+ if (Math.abs(this.getBearing()) < this.bearingSnap) {
173
+ return this.resetNorth(options, eventData);
214
174
  }
215
- }, {
216
- key: "jumpTo",
217
- value: function jumpTo() {
218
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
219
- var eventData = arguments.length > 1 ? arguments[1] : undefined;
220
- this.stop();
221
- var tr = this.transform;
222
- var zoomChanged = false;
223
- var bearingChanged = false;
224
- var pitchChanged = false;
225
- if (options.zoom !== undefined && tr.zoom !== +options.zoom) {
226
- zoomChanged = true;
227
- tr.zoom = +options.zoom;
228
- }
229
- if (options.center !== undefined) {
230
- tr.center = LngLat.convert(options.center);
231
- }
232
- if (options.bearing !== undefined && tr.bearing !== +options.bearing) {
233
- bearingChanged = true;
234
- tr.bearing = +options.bearing;
235
- }
236
- if (options.pitch !== undefined && tr.pitch !== +options.pitch) {
237
- pitchChanged = true;
238
- tr.pitch = +options.pitch;
239
- }
240
- if (options.padding !== undefined && !tr.isPaddingEqual(options.padding)) {
241
- tr.padding = options.padding;
242
- }
243
- this.emit('movestart', new Event('movestart', eventData));
244
- this.emit('move', new Event('move', eventData));
245
- if (zoomChanged) {
246
- this.emit('zoomstart', new Event('zoomstart', eventData));
247
- this.emit('zoom', new Event('zoom', eventData));
248
- this.emit('zoomend', new Event('zoomend', eventData));
249
- }
250
- if (bearingChanged) {
251
- this.emit('rotatestart', new Event('rotatestart', eventData));
252
- this.emit('rotate', new Event('rotate', eventData));
253
- this.emit('rotateend', new Event('rotateend', eventData));
175
+ return this;
176
+ }
177
+ jumpTo(options = {}, eventData) {
178
+ this.stop();
179
+ const tr = this.transform;
180
+ let zoomChanged = false;
181
+ let bearingChanged = false;
182
+ let pitchChanged = false;
183
+ if (options.zoom !== undefined && tr.zoom !== +options.zoom) {
184
+ zoomChanged = true;
185
+ tr.zoom = +options.zoom;
186
+ }
187
+ if (options.center !== undefined) {
188
+ tr.center = LngLat.convert(options.center);
189
+ }
190
+ if (options.bearing !== undefined && tr.bearing !== +options.bearing) {
191
+ bearingChanged = true;
192
+ tr.bearing = +options.bearing;
193
+ }
194
+ if (options.pitch !== undefined && tr.pitch !== +options.pitch) {
195
+ pitchChanged = true;
196
+ tr.pitch = +options.pitch;
197
+ }
198
+ if (options.padding !== undefined && !tr.isPaddingEqual(options.padding)) {
199
+ tr.padding = options.padding;
200
+ }
201
+ this.emit('movestart', new Event('movestart', eventData));
202
+ this.emit('move', new Event('move', eventData));
203
+ if (zoomChanged) {
204
+ this.emit('zoomstart', new Event('zoomstart', eventData));
205
+ this.emit('zoom', new Event('zoom', eventData));
206
+ this.emit('zoomend', new Event('zoomend', eventData));
207
+ }
208
+ if (bearingChanged) {
209
+ this.emit('rotatestart', new Event('rotatestart', eventData));
210
+ this.emit('rotate', new Event('rotate', eventData));
211
+ this.emit('rotateend', new Event('rotateend', eventData));
212
+ }
213
+ if (pitchChanged) {
214
+ this.emit('pitchstart', new Event('pitchstart', eventData));
215
+ this.emit('pitch', new Event('pitch', eventData));
216
+ this.emit('pitchend', new Event('pitchend', eventData));
217
+ }
218
+ return this.emit('moveend', new Event('moveend', eventData));
219
+ }
220
+ easeTo(options = {}, eventData) {
221
+ options = merge({
222
+ offset: [0, 0],
223
+ duration: 500,
224
+ easing: defaultEasing
225
+ }, options);
226
+ if (options.animate === false || !options.essential && prefersReducedMotion()) {
227
+ options.duration = 0;
228
+ }
229
+ const tr = this.transform;
230
+ const startZoom = this.getZoom();
231
+ const startBearing = this.getBearing();
232
+ const startPitch = this.getPitch();
233
+ const startPadding = this.getPadding();
234
+ const zoom = options.zoom ? +options.zoom : startZoom;
235
+ const bearing = options.bearing ? this.normalizeBearing(options.bearing, startBearing) : startBearing;
236
+ const pitch = options.pitch ? +options.pitch : startPitch;
237
+ const padding = options.padding ? options.padding : tr.padding;
238
+ const offsetAsPoint = Point.convert(options.offset);
239
+ let pointAtOffset = tr.centerPoint.add(offsetAsPoint);
240
+ const locationAtOffset = tr.pointLocation(pointAtOffset);
241
+ const center = LngLat.convert(options.center || locationAtOffset);
242
+ this.normalizeCenter(center);
243
+ const from = tr.project(locationAtOffset);
244
+ const delta = tr.project(center).sub(from);
245
+ const finalScale = tr.zoomScale(zoom - startZoom);
246
+ let around;
247
+ let aroundPoint;
248
+ if (options.around) {
249
+ around = LngLat.convert(options.around);
250
+ aroundPoint = tr.locationPoint(around);
251
+ }
252
+ const currently = {
253
+ moving: this.moving,
254
+ zooming: this.zooming,
255
+ rotating: this.rotating,
256
+ pitching: this.pitching
257
+ };
258
+ this.zooming = this.zooming || zoom !== startZoom;
259
+ this.rotating = this.rotating || startBearing !== bearing;
260
+ this.pitching = this.pitching || pitch !== startPitch;
261
+ this.padding = !tr.isPaddingEqual(padding);
262
+ this.easeId = options.easeId;
263
+ this.prepareEase(eventData, options.noMoveStart, currently);
264
+ clearTimeout(this.easeEndTimeoutID);
265
+ this.ease(k => {
266
+ if (this.zooming) {
267
+ tr.zoom = interpolate(startZoom, zoom, k);
254
268
  }
255
- if (pitchChanged) {
256
- this.emit('pitchstart', new Event('pitchstart', eventData));
257
- this.emit('pitch', new Event('pitch', eventData));
258
- this.emit('pitchend', new Event('pitchend', eventData));
269
+ if (this.rotating && this.rotateEnabled) {
270
+ tr.bearing = interpolate(startBearing, bearing, k);
259
271
  }
260
- return this.emit('moveend', new Event('moveend', eventData));
261
- }
262
- }, {
263
- key: "easeTo",
264
- value: function easeTo() {
265
- var _this2 = this;
266
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
267
- var eventData = arguments.length > 1 ? arguments[1] : undefined;
268
- options = merge({
269
- offset: [0, 0],
270
- duration: 500,
271
- easing: defaultEasing
272
- }, options);
273
- if (options.animate === false || !options.essential && prefersReducedMotion()) {
274
- options.duration = 0;
272
+ if (this.pitching && this.pitchEnabled) {
273
+ tr.pitch = interpolate(startPitch, pitch, k);
275
274
  }
276
- var tr = this.transform;
277
- var startZoom = this.getZoom();
278
- var startBearing = this.getBearing();
279
- var startPitch = this.getPitch();
280
- var startPadding = this.getPadding();
281
- var zoom = options.zoom ? +options.zoom : startZoom;
282
- var bearing = options.bearing ? this.normalizeBearing(options.bearing, startBearing) : startBearing;
283
- var pitch = options.pitch ? +options.pitch : startPitch;
284
- var padding = options.padding ? options.padding : tr.padding;
285
- var offsetAsPoint = Point.convert(options.offset);
286
- var pointAtOffset = tr.centerPoint.add(offsetAsPoint);
287
- var locationAtOffset = tr.pointLocation(pointAtOffset);
288
- var center = LngLat.convert(options.center || locationAtOffset);
289
- this.normalizeCenter(center);
290
- var from = tr.project(locationAtOffset);
291
- var delta = tr.project(center).sub(from);
292
- var finalScale = tr.zoomScale(zoom - startZoom);
293
- var around;
294
- var aroundPoint;
295
- if (options.around) {
296
- around = LngLat.convert(options.around);
297
- aroundPoint = tr.locationPoint(around);
275
+ if (this.padding) {
276
+ tr.interpolatePadding(startPadding, padding, k);
277
+ // When padding is being applied, Transform#centerPoint is changing continously,
278
+ // thus we need to recalculate offsetPoint every fra,e
279
+ pointAtOffset = tr.centerPoint.add(offsetAsPoint);
298
280
  }
299
- var currently = {
300
- moving: this.moving,
301
- zooming: this.zooming,
302
- rotating: this.rotating,
303
- pitching: this.pitching
304
- };
305
- this.zooming = this.zooming || zoom !== startZoom;
306
- this.rotating = this.rotating || startBearing !== bearing;
307
- this.pitching = this.pitching || pitch !== startPitch;
308
- this.padding = !tr.isPaddingEqual(padding);
309
- this.easeId = options.easeId;
310
- this.prepareEase(eventData, options.noMoveStart, currently);
311
- clearTimeout(this.easeEndTimeoutID);
312
- this.ease(function (k) {
313
- if (_this2.zooming) {
314
- tr.zoom = interpolate(startZoom, zoom, k);
315
- }
316
- if (_this2.rotating && _this2.rotateEnabled) {
317
- tr.bearing = interpolate(startBearing, bearing, k);
318
- }
319
- if (_this2.pitching && _this2.pitchEnabled) {
320
- tr.pitch = interpolate(startPitch, pitch, k);
321
- }
322
- if (_this2.padding) {
323
- tr.interpolatePadding(startPadding, padding, k);
324
- // When padding is being applied, Transform#centerPoint is changing continously,
325
- // thus we need to recalculate offsetPoint every fra,e
326
- pointAtOffset = tr.centerPoint.add(offsetAsPoint);
327
- }
328
- if (around) {
329
- tr.setLocationAtPoint(around, aroundPoint);
330
- } else {
331
- var scale = tr.zoomScale(tr.zoom - startZoom);
332
- var base = zoom > startZoom ? Math.min(2, finalScale) : Math.max(0.5, finalScale);
333
- var speedup = Math.pow(base, 1 - k);
334
- var newCenter = tr.unproject(from.add(delta.mult(k * speedup)).mult(scale));
335
- tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
336
- }
337
- _this2.fireMoveEvents(eventData);
338
- }, function (interruptingEaseId) {
339
- _this2.afterEase(eventData, interruptingEaseId);
340
- },
341
- // @ts-ignore
342
- options);
343
- return this;
344
- }
345
- }, {
346
- key: "flyTo",
347
- value: function flyTo() {
348
- var _this3 = this;
349
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
350
- var eventData = arguments.length > 1 ? arguments[1] : undefined;
351
- // Fall through to jumpTo if user has set prefers-reduced-motion
352
- if (!options.essential && prefersReducedMotion()) {
353
- var coercedOptions = pick(options, ['center', 'zoom', 'bearing', 'pitch', 'around']);
354
- return this.jumpTo(coercedOptions, eventData);
281
+ if (around) {
282
+ tr.setLocationAtPoint(around, aroundPoint);
283
+ } else {
284
+ const scale = tr.zoomScale(tr.zoom - startZoom);
285
+ const base = zoom > startZoom ? Math.min(2, finalScale) : Math.max(0.5, finalScale);
286
+ const speedup = Math.pow(base, 1 - k);
287
+ const newCenter = tr.unproject(from.add(delta.mult(k * speedup)).mult(scale));
288
+ tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
355
289
  }
356
- this.stop();
357
- options = merge({
358
- offset: [0, 0],
359
- speed: 1.2,
360
- curve: 1.42,
361
- easing: defaultEasing
362
- }, options);
363
- var tr = this.transform;
364
- var startZoom = this.getZoom();
365
- var startBearing = this.getBearing();
366
- var startPitch = this.getPitch();
367
- var startPadding = this.getPadding();
368
- var zoom = options.zoom ? clamp(+options.zoom, tr.minZoom, tr.maxZoom) : startZoom;
369
- var bearing = options.bearing ? this.normalizeBearing(options.bearing, startBearing) : startBearing;
370
- var pitch = options.pitch ? +options.pitch : startPitch;
371
- var padding = 'padding' in options ? options.padding : tr.padding;
372
- var scale = tr.zoomScale(zoom - startZoom);
373
- var offsetAsPoint = Point.convert(options.offset);
374
- var pointAtOffset = tr.centerPoint.add(offsetAsPoint);
375
- var locationAtOffset = tr.pointLocation(pointAtOffset);
376
- var center = LngLat.convert(options.center || locationAtOffset);
377
- this.normalizeCenter(center);
378
- var from = tr.project(locationAtOffset);
379
- var delta = tr.project(center).sub(from);
380
- var rho = options.curve;
290
+ this.fireMoveEvents(eventData);
291
+ }, interruptingEaseId => {
292
+ this.afterEase(eventData, interruptingEaseId);
293
+ },
294
+ // @ts-ignore
295
+ options);
296
+ return this;
297
+ }
298
+ flyTo(options = {}, eventData) {
299
+ // Fall through to jumpTo if user has set prefers-reduced-motion
300
+ if (!options.essential && prefersReducedMotion()) {
301
+ const coercedOptions = pick(options, ['center', 'zoom', 'bearing', 'pitch', 'around']);
302
+ return this.jumpTo(coercedOptions, eventData);
303
+ }
304
+ this.stop();
305
+ options = merge({
306
+ offset: [0, 0],
307
+ speed: 1.2,
308
+ curve: 1.42,
309
+ easing: defaultEasing
310
+ }, options);
311
+ const tr = this.transform;
312
+ const startZoom = this.getZoom();
313
+ const startBearing = this.getBearing();
314
+ const startPitch = this.getPitch();
315
+ const startPadding = this.getPadding();
316
+ const zoom = options.zoom ? clamp(+options.zoom, tr.minZoom, tr.maxZoom) : startZoom;
317
+ const bearing = options.bearing ? this.normalizeBearing(options.bearing, startBearing) : startBearing;
318
+ const pitch = options.pitch ? +options.pitch : startPitch;
319
+ const padding = 'padding' in options ? options.padding : tr.padding;
320
+ const scale = tr.zoomScale(zoom - startZoom);
321
+ const offsetAsPoint = Point.convert(options.offset);
322
+ let pointAtOffset = tr.centerPoint.add(offsetAsPoint);
323
+ const locationAtOffset = tr.pointLocation(pointAtOffset);
324
+ const center = LngLat.convert(options.center || locationAtOffset);
325
+ this.normalizeCenter(center);
326
+ const from = tr.project(locationAtOffset);
327
+ const delta = tr.project(center).sub(from);
328
+ let rho = options.curve;
381
329
 
382
- // w₀: Initial visible span, measured in pixels at the initial scale.
383
- var w0 = Math.max(tr.width, tr.height);
384
- // w₁: Final visible span, measured in pixels with respect to the initial scale.
385
- var w1 = w0 / scale;
386
- // Length of the flight path as projected onto the ground plane, measured in pixels from
387
- // the world image origin at the initial scale.
388
- var u1 = delta.mag();
389
- if ('minZoom' in options) {
390
- var minZoom = clamp(Math.min(options.minZoom, startZoom, zoom), tr.minZoom, tr.maxZoom);
391
- // w<sub>m</sub>: Maximum visible span, measured in pixels with respect to the initial
392
- // scale.
393
- var wMax = w0 / tr.zoomScale(minZoom - startZoom);
394
- rho = Math.sqrt(wMax / u1 * 2);
395
- }
330
+ // w₀: Initial visible span, measured in pixels at the initial scale.
331
+ const w0 = Math.max(tr.width, tr.height);
332
+ // w₁: Final visible span, measured in pixels with respect to the initial scale.
333
+ const w1 = w0 / scale;
334
+ // Length of the flight path as projected onto the ground plane, measured in pixels from
335
+ // the world image origin at the initial scale.
336
+ const u1 = delta.mag();
337
+ if ('minZoom' in options) {
338
+ const minZoom = clamp(Math.min(options.minZoom, startZoom, zoom), tr.minZoom, tr.maxZoom);
339
+ // w<sub>m</sub>: Maximum visible span, measured in pixels with respect to the initial
340
+ // scale.
341
+ const wMax = w0 / tr.zoomScale(minZoom - startZoom);
342
+ rho = Math.sqrt(wMax / u1 * 2);
343
+ }
396
344
 
397
- // ρ²
398
- var rho2 = rho * rho;
345
+ // ρ²
346
+ const rho2 = rho * rho;
399
347
 
400
- /**
401
- * rᵢ: Returns the zoom-out factor at one end of the animation.
402
- *
403
- * @param i 0 for the ascent or 1 for the descent.
404
- * @private
405
- */
406
- function r(i) {
407
- var b = (w1 * w1 - w0 * w0 + (i ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (i ? w1 : w0) * rho2 * u1);
408
- return Math.log(Math.sqrt(b * b + 1) - b);
409
- }
410
- function sinh(n) {
411
- return (Math.exp(n) - Math.exp(-n)) / 2;
412
- }
413
- function cosh(n) {
414
- return (Math.exp(n) + Math.exp(-n)) / 2;
415
- }
416
- function tanh(n) {
417
- return sinh(n) / cosh(n);
418
- }
348
+ /**
349
+ * rᵢ: Returns the zoom-out factor at one end of the animation.
350
+ *
351
+ * @param i 0 for the ascent or 1 for the descent.
352
+ * @private
353
+ */
354
+ function r(i) {
355
+ const b = (w1 * w1 - w0 * w0 + (i ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (i ? w1 : w0) * rho2 * u1);
356
+ return Math.log(Math.sqrt(b * b + 1) - b);
357
+ }
358
+ function sinh(n) {
359
+ return (Math.exp(n) - Math.exp(-n)) / 2;
360
+ }
361
+ function cosh(n) {
362
+ return (Math.exp(n) + Math.exp(-n)) / 2;
363
+ }
364
+ function tanh(n) {
365
+ return sinh(n) / cosh(n);
366
+ }
419
367
 
420
- // r₀: Zoom-out factor during ascent.
421
- var r0 = r(0);
368
+ // r₀: Zoom-out factor during ascent.
369
+ const r0 = r(0);
422
370
 
423
- // w(s): Returns the visible span on the ground, measured in pixels with respect to the
424
- // initial scale. Assumes an angular field of view of 2 arctan ½ ≈ 53°.
425
- var w = function w(s) {
426
- return cosh(r0) / cosh(r0 + rho * s);
427
- };
371
+ // w(s): Returns the visible span on the ground, measured in pixels with respect to the
372
+ // initial scale. Assumes an angular field of view of 2 arctan ½ ≈ 53°.
373
+ let w = s => {
374
+ return cosh(r0) / cosh(r0 + rho * s);
375
+ };
428
376
 
429
- // u(s): Returns the distance along the flight path as projected onto the ground plane,
430
- // measured in pixels from the world image origin at the initial scale.
431
- var u = function u(s) {
432
- return w0 * ((cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2) / u1;
433
- };
377
+ // u(s): Returns the distance along the flight path as projected onto the ground plane,
378
+ // measured in pixels from the world image origin at the initial scale.
379
+ let u = s => {
380
+ return w0 * ((cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2) / u1;
381
+ };
434
382
 
435
- // S: Total length of the flight path, measured in ρ-screenfuls.
436
- var S = (r(1) - r0) / rho;
383
+ // S: Total length of the flight path, measured in ρ-screenfuls.
384
+ let S = (r(1) - r0) / rho;
437
385
 
438
- // When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
439
- if (Math.abs(u1) < 0.000001 || !isFinite(S)) {
440
- // Perform a more or less instantaneous transition if the path is too short.
441
- if (Math.abs(w0 - w1) < 0.000001) {
442
- return this.easeTo(options, eventData);
443
- }
444
- var k = w1 < w0 ? -1 : 1;
445
- S = Math.abs(Math.log(w1 / w0)) / rho;
446
- u = function u() {
447
- return 0;
448
- };
449
- w = function w(s) {
450
- return Math.exp(k * rho * s);
451
- };
452
- }
453
- if ('duration' in options) {
454
- options.duration = +options.duration;
455
- } else {
456
- var V = 'screenSpeed' in options ? +options.screenSpeed / rho : +options.speed;
457
- options.duration = 1000 * S / V;
458
- }
459
- if (options.maxDuration && options.duration > options.maxDuration) {
460
- options.duration = 0;
461
- }
462
- this.zooming = true;
463
- this.rotating = startBearing !== bearing;
464
- this.pitching = pitch !== startPitch;
465
- this.padding = !tr.isPaddingEqual(padding);
466
- this.prepareEase(eventData, false);
467
- this.ease(function (k) {
468
- // s: The distance traveled along the flight path, measured in ρ-screenfuls.
469
- var s = k * S;
470
- // @ts-ignore
471
- var easeScale = 1 / w(s);
472
- tr.zoom = k === 1 ? zoom : startZoom + tr.scaleZoom(easeScale);
473
- if (_this3.rotating) {
474
- tr.bearing = interpolate(startBearing, bearing, k);
475
- }
476
- if (_this3.pitching) {
477
- tr.pitch = interpolate(startPitch, pitch, k);
478
- }
479
- if (_this3.padding) {
480
- tr.interpolatePadding(startPadding, padding, k);
481
- // When padding is being applied, Transform#centerPoint is changing continously,
482
- // thus we need to recalculate offsetPoint every frame
483
- pointAtOffset = tr.centerPoint.add(offsetAsPoint);
484
- }
485
- var newCenter = k === 1 ? center : tr.unproject(from.add(delta.mult(u(s))).mult(easeScale));
486
- tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
487
- _this3.fireMoveEvents(eventData);
488
- }, function () {
489
- return _this3.afterEase(eventData);
490
- }, options);
491
- return this;
386
+ // When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
387
+ if (Math.abs(u1) < 0.000001 || !isFinite(S)) {
388
+ // Perform a more or less instantaneous transition if the path is too short.
389
+ if (Math.abs(w0 - w1) < 0.000001) {
390
+ return this.easeTo(options, eventData);
391
+ }
392
+ const k = w1 < w0 ? -1 : 1;
393
+ S = Math.abs(Math.log(w1 / w0)) / rho;
394
+ u = () => {
395
+ return 0;
396
+ };
397
+ w = s => {
398
+ return Math.exp(k * rho * s);
399
+ };
492
400
  }
493
- }, {
494
- key: "fitScreenCoordinates",
495
- value: function fitScreenCoordinates(p0, p1, bearing, options, eventData) {
496
- return this.fitInternal(
497
- // @ts-ignore
498
- this.cameraForBoxAndBearing(this.transform.pointLocation(Point.convert(p0)), this.transform.pointLocation(Point.convert(p1)), bearing,
401
+ if ('duration' in options) {
402
+ options.duration = +options.duration;
403
+ } else {
404
+ const V = 'screenSpeed' in options ? +options.screenSpeed / rho : +options.speed;
405
+ options.duration = 1000 * S / V;
406
+ }
407
+ if (options.maxDuration && options.duration > options.maxDuration) {
408
+ options.duration = 0;
409
+ }
410
+ this.zooming = true;
411
+ this.rotating = startBearing !== bearing;
412
+ this.pitching = pitch !== startPitch;
413
+ this.padding = !tr.isPaddingEqual(padding);
414
+ this.prepareEase(eventData, false);
415
+ this.ease(k => {
416
+ // s: The distance traveled along the flight path, measured in ρ-screenfuls.
417
+ const s = k * S;
499
418
  // @ts-ignore
500
- options), options, eventData);
501
- }
502
- }, {
503
- key: "stop",
504
- value: function stop(allowGestures, easeId) {
505
- if (this.easeFrameId) {
506
- this.cancelRenderFrame(this.easeFrameId);
507
- // @ts-ignore
508
- delete this.easeFrameId;
509
- // @ts-ignore
510
- delete this.onEaseFrame;
511
- }
512
- if (this.onEaseEnd) {
513
- // The _onEaseEnd function might emit events which trigger new
514
- // animation, which sets a new _onEaseEnd. Ensure we don't delete
515
- // it unintentionally.
516
- var onEaseEnd = this.onEaseEnd;
517
- // @ts-ignore
518
- delete this.onEaseEnd;
519
- onEaseEnd.call(this, easeId);
520
- }
521
- // if (!allowGestures) {
522
- // const handlers = (this: any).handlers;
523
- // if (handlers) handlers.stop();
524
- // }
525
- return this;
526
- }
527
- }, {
528
- key: "normalizeBearing",
529
- value: function normalizeBearing(bearing, currentBearing) {
530
- bearing = wrap(bearing, -180, 180);
531
- var diff = Math.abs(bearing - currentBearing);
532
- if (Math.abs(bearing - 360 - currentBearing) < diff) {
533
- bearing -= 360;
534
- }
535
- if (Math.abs(bearing + 360 - currentBearing) < diff) {
536
- bearing += 360;
537
- }
538
- return bearing;
539
- }
540
- }, {
541
- key: "normalizeCenter",
542
- value: function normalizeCenter(center) {
543
- var tr = this.transform;
544
- if (!tr.renderWorldCopies || tr.lngRange) {
545
- return;
546
- }
547
- var delta = center.lng - tr.center.lng;
548
- center.lng += delta > 180 ? -360 : delta < -180 ? 360 : 0;
549
- }
550
- }, {
551
- key: "fireMoveEvents",
552
- value: function fireMoveEvents(eventData) {
553
- this.emit('move', new Event('move', eventData));
554
- if (this.zooming) {
555
- this.emit('zoom', new Event('zoom', eventData));
556
- }
419
+ const easeScale = 1 / w(s);
420
+ tr.zoom = k === 1 ? zoom : startZoom + tr.scaleZoom(easeScale);
557
421
  if (this.rotating) {
558
- this.emit('rotate', new Event('rotate', eventData));
422
+ tr.bearing = interpolate(startBearing, bearing, k);
559
423
  }
560
424
  if (this.pitching) {
561
- this.emit('rotate', new Event('pitch', eventData));
562
- }
563
- }
564
- }, {
565
- key: "prepareEase",
566
- value: function prepareEase(eventData) {
567
- var noMoveStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
568
- var currently = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
569
- this.moving = true;
570
- if (!noMoveStart && !currently.moving) {
571
- this.emit('movestart', new Event('movestart', eventData));
572
- }
573
- if (this.zooming && !currently.zooming) {
574
- this.emit('zoomstart', new Event('zoomstart', eventData));
575
- }
576
- if (this.rotating && !currently.rotating) {
577
- this.emit('rotatestart', new Event('rotatestart', eventData));
578
- }
579
- if (this.pitching && !currently.pitching) {
580
- this.emit('pitchstart', new Event('pitchstart', eventData));
581
- }
425
+ tr.pitch = interpolate(startPitch, pitch, k);
426
+ }
427
+ if (this.padding) {
428
+ tr.interpolatePadding(startPadding, padding, k);
429
+ // When padding is being applied, Transform#centerPoint is changing continously,
430
+ // thus we need to recalculate offsetPoint every frame
431
+ pointAtOffset = tr.centerPoint.add(offsetAsPoint);
432
+ }
433
+ const newCenter = k === 1 ? center : tr.unproject(from.add(delta.mult(u(s))).mult(easeScale));
434
+ tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
435
+ this.fireMoveEvents(eventData);
436
+ }, () => this.afterEase(eventData), options);
437
+ return this;
438
+ }
439
+ fitScreenCoordinates(p0, p1, bearing, options, eventData) {
440
+ return this.fitInternal(
441
+ // @ts-ignore
442
+ this.cameraForBoxAndBearing(this.transform.pointLocation(Point.convert(p0)), this.transform.pointLocation(Point.convert(p1)), bearing,
443
+ // @ts-ignore
444
+ options), options, eventData);
445
+ }
446
+ stop(allowGestures, easeId) {
447
+ if (this.easeFrameId) {
448
+ this.cancelRenderFrame(this.easeFrameId);
449
+ // @ts-ignore
450
+ delete this.easeFrameId;
451
+ // @ts-ignore
452
+ delete this.onEaseFrame;
582
453
  }
583
- }, {
584
- key: "afterEase",
585
- value: function afterEase(eventData, easeId) {
586
- // if this easing is being stopped to start another easing with
587
- // the same id then don't fire any events to avoid extra start/stop events
588
- if (this.easeId && easeId && this.easeId === easeId) {
589
- return;
590
- }
454
+ if (this.onEaseEnd) {
455
+ // The _onEaseEnd function might emit events which trigger new
456
+ // animation, which sets a new _onEaseEnd. Ensure we don't delete
457
+ // it unintentionally.
458
+ const onEaseEnd = this.onEaseEnd;
591
459
  // @ts-ignore
592
- delete this.easeId;
593
- var wasZooming = this.zooming;
594
- var wasRotating = this.rotating;
595
- var wasPitching = this.pitching;
596
- this.moving = false;
597
- this.zooming = false;
598
- this.rotating = false;
599
- this.pitching = false;
600
- this.padding = false;
601
- if (wasZooming) {
602
- this.emit('zoomend', new Event('zoomend', eventData));
603
- }
604
- if (wasRotating) {
605
- this.emit('rotateend', new Event('rotateend', eventData));
606
- }
607
- if (wasPitching) {
608
- this.emit('pitchend', new Event('pitchend', eventData));
609
- }
610
- this.emit('moveend', new Event('moveend', eventData));
611
- }
612
- }, {
613
- key: "ease",
614
- value: function ease(frame, finish, options) {
615
- if (options.animate === false || options.duration === 0) {
616
- frame(1);
617
- finish();
618
- } else {
619
- this.easeStart = now();
620
- this.easeOptions = options;
621
- this.onEaseFrame = frame;
622
- this.onEaseEnd = finish;
623
- this.easeFrameId = this.requestRenderFrame(this.renderFrameCallback);
624
- }
460
+ delete this.onEaseEnd;
461
+ onEaseEnd.call(this, easeId);
462
+ }
463
+ // if (!allowGestures) {
464
+ // const handlers = (this: any).handlers;
465
+ // if (handlers) handlers.stop();
466
+ // }
467
+ return this;
468
+ }
469
+ normalizeBearing(bearing, currentBearing) {
470
+ bearing = wrap(bearing, -180, 180);
471
+ const diff = Math.abs(bearing - currentBearing);
472
+ if (Math.abs(bearing - 360 - currentBearing) < diff) {
473
+ bearing -= 360;
474
+ }
475
+ if (Math.abs(bearing + 360 - currentBearing) < diff) {
476
+ bearing += 360;
477
+ }
478
+ return bearing;
479
+ }
480
+ normalizeCenter(center) {
481
+ const tr = this.transform;
482
+ if (!tr.renderWorldCopies || tr.lngRange) {
483
+ return;
484
+ }
485
+ const delta = center.lng - tr.center.lng;
486
+ center.lng += delta > 180 ? -360 : delta < -180 ? 360 : 0;
487
+ }
488
+ fireMoveEvents(eventData) {
489
+ this.emit('move', new Event('move', eventData));
490
+ if (this.zooming) {
491
+ this.emit('zoom', new Event('zoom', eventData));
492
+ }
493
+ if (this.rotating) {
494
+ this.emit('rotate', new Event('rotate', eventData));
495
+ }
496
+ if (this.pitching) {
497
+ this.emit('rotate', new Event('pitch', eventData));
498
+ }
499
+ }
500
+ prepareEase(eventData, noMoveStart = false, currently = {}) {
501
+ this.moving = true;
502
+ if (!noMoveStart && !currently.moving) {
503
+ this.emit('movestart', new Event('movestart', eventData));
504
+ }
505
+ if (this.zooming && !currently.zooming) {
506
+ this.emit('zoomstart', new Event('zoomstart', eventData));
507
+ }
508
+ if (this.rotating && !currently.rotating) {
509
+ this.emit('rotatestart', new Event('rotatestart', eventData));
625
510
  }
626
- }, {
627
- key: "cameraForBoxAndBearing",
628
- value: function cameraForBoxAndBearing(p0, p1, bearing, options) {
629
- var defaultPadding = {
630
- top: 0,
631
- bottom: 0,
632
- right: 0,
633
- left: 0
511
+ if (this.pitching && !currently.pitching) {
512
+ this.emit('pitchstart', new Event('pitchstart', eventData));
513
+ }
514
+ }
515
+ afterEase(eventData, easeId) {
516
+ // if this easing is being stopped to start another easing with
517
+ // the same id then don't fire any events to avoid extra start/stop events
518
+ if (this.easeId && easeId && this.easeId === easeId) {
519
+ return;
520
+ }
521
+ // @ts-ignore
522
+ delete this.easeId;
523
+ const wasZooming = this.zooming;
524
+ const wasRotating = this.rotating;
525
+ const wasPitching = this.pitching;
526
+ this.moving = false;
527
+ this.zooming = false;
528
+ this.rotating = false;
529
+ this.pitching = false;
530
+ this.padding = false;
531
+ if (wasZooming) {
532
+ this.emit('zoomend', new Event('zoomend', eventData));
533
+ }
534
+ if (wasRotating) {
535
+ this.emit('rotateend', new Event('rotateend', eventData));
536
+ }
537
+ if (wasPitching) {
538
+ this.emit('pitchend', new Event('pitchend', eventData));
539
+ }
540
+ this.emit('moveend', new Event('moveend', eventData));
541
+ }
542
+ ease(frame, finish, options) {
543
+ if (options.animate === false || options.duration === 0) {
544
+ frame(1);
545
+ finish();
546
+ } else {
547
+ this.easeStart = now();
548
+ this.easeOptions = options;
549
+ this.onEaseFrame = frame;
550
+ this.onEaseEnd = finish;
551
+ this.easeFrameId = this.requestRenderFrame(this.renderFrameCallback);
552
+ }
553
+ }
554
+ cameraForBoxAndBearing(p0, p1, bearing, options) {
555
+ const defaultPadding = {
556
+ top: 0,
557
+ bottom: 0,
558
+ right: 0,
559
+ left: 0
560
+ };
561
+ options = merge({
562
+ padding: defaultPadding,
563
+ offset: [0, 0],
564
+ maxZoom: this.transform.maxZoom
565
+ }, options);
566
+ if (typeof options.padding === 'number') {
567
+ const p = options.padding;
568
+ options.padding = {
569
+ top: p,
570
+ bottom: p,
571
+ right: p,
572
+ left: p
634
573
  };
635
- options = merge({
636
- padding: defaultPadding,
637
- offset: [0, 0],
638
- maxZoom: this.transform.maxZoom
639
- }, options);
640
- if (typeof options.padding === 'number') {
641
- var p = options.padding;
642
- options.padding = {
643
- top: p,
644
- bottom: p,
645
- right: p,
646
- left: p
647
- };
648
- }
649
- options.padding = merge(defaultPadding, options.padding);
650
- var tr = this.transform;
651
- var edgePadding = tr.padding;
574
+ }
575
+ options.padding = merge(defaultPadding, options.padding);
576
+ const tr = this.transform;
577
+ const edgePadding = tr.padding;
652
578
 
653
- // We want to calculate the upper right and lower left of the box defined by p0 and p1
654
- // in a coordinate system rotate to match the destination bearing.
655
- var p0world = tr.project(LngLat.convert(p0));
656
- var p1world = tr.project(LngLat.convert(p1));
657
- var p0rotated = p0world.rotate(-bearing * Math.PI / 180);
658
- var p1rotated = p1world.rotate(-bearing * Math.PI / 180);
659
- var upperRight = new Point(Math.max(p0rotated.x, p1rotated.x), Math.max(p0rotated.y, p1rotated.y));
660
- var lowerLeft = new Point(Math.min(p0rotated.x, p1rotated.x), Math.min(p0rotated.y, p1rotated.y));
579
+ // We want to calculate the upper right and lower left of the box defined by p0 and p1
580
+ // in a coordinate system rotate to match the destination bearing.
581
+ const p0world = tr.project(LngLat.convert(p0));
582
+ const p1world = tr.project(LngLat.convert(p1));
583
+ const p0rotated = p0world.rotate(-bearing * Math.PI / 180);
584
+ const p1rotated = p1world.rotate(-bearing * Math.PI / 180);
585
+ const upperRight = new Point(Math.max(p0rotated.x, p1rotated.x), Math.max(p0rotated.y, p1rotated.y));
586
+ const lowerLeft = new Point(Math.min(p0rotated.x, p1rotated.x), Math.min(p0rotated.y, p1rotated.y));
661
587
 
662
- // Calculate zoom: consider the original bbox and padding.
663
- var size = upperRight.sub(lowerLeft);
664
- var scaleX = (tr.width - (
665
- // @ts-ignore
666
- edgePadding.left +
667
- // @ts-ignore
668
- edgePadding.right +
669
- // @ts-ignore
670
- options.padding.left +
671
- // @ts-ignore
672
- options.padding.right)) / size.x;
673
- var scaleY = (tr.height - (
674
- // @ts-ignore
675
- edgePadding.top +
676
- // @ts-ignore
677
- edgePadding.bottom +
678
- // @ts-ignore
679
- options.padding.top +
680
- // @ts-ignore
681
- options.padding.bottom)) / size.y;
682
- if (scaleY < 0 || scaleX < 0) {
683
- return;
684
- }
685
- var zoom = Math.min(tr.scaleZoom(tr.scale * Math.min(scaleX, scaleY)), options.maxZoom);
686
-
687
- // Calculate center: apply the zoom, the configured offset, as well as offset that exists as a result of padding.
688
- var offset = Point.convert(options.offset);
689
- // @ts-ignore
690
- var paddingOffsetX = (options.padding.left - options.padding.right) / 2;
691
- // @ts-ignore
692
- var paddingOffsetY = (options.padding.top - options.padding.bottom) / 2;
693
- var offsetAtInitialZoom = new Point(offset.x + paddingOffsetX, offset.y + paddingOffsetY);
694
- var offsetAtFinalZoom = offsetAtInitialZoom.mult(tr.scale / tr.zoomScale(zoom));
695
- var center = tr.unproject(p0world.add(p1world).div(2).sub(offsetAtFinalZoom));
696
- return {
697
- center: center,
698
- zoom: zoom,
699
- bearing: bearing
700
- };
588
+ // Calculate zoom: consider the original bbox and padding.
589
+ const size = upperRight.sub(lowerLeft);
590
+ const scaleX = (tr.width - (
591
+ // @ts-ignore
592
+ edgePadding.left +
593
+ // @ts-ignore
594
+ edgePadding.right +
595
+ // @ts-ignore
596
+ options.padding.left +
597
+ // @ts-ignore
598
+ options.padding.right)) / size.x;
599
+ const scaleY = (tr.height - (
600
+ // @ts-ignore
601
+ edgePadding.top +
602
+ // @ts-ignore
603
+ edgePadding.bottom +
604
+ // @ts-ignore
605
+ options.padding.top +
606
+ // @ts-ignore
607
+ options.padding.bottom)) / size.y;
608
+ if (scaleY < 0 || scaleX < 0) {
609
+ return;
701
610
  }
702
- }, {
703
- key: "fitInternal",
704
- value: function fitInternal(calculatedOptions, options, eventData) {
705
- // cameraForBounds warns + returns undefined if unable to fit:
706
- if (!calculatedOptions) {
707
- return this;
708
- }
709
- options = merge(calculatedOptions, options);
710
- // Explictly remove the padding field because, calculatedOptions already accounts for padding by setting zoom and center accordingly.
711
- delete options.padding;
712
- // @ts-ignore
713
- return options.linear ? this.easeTo(options, eventData) : this.flyTo(options, eventData);
611
+ const zoom = Math.min(tr.scaleZoom(tr.scale * Math.min(scaleX, scaleY)), options.maxZoom);
612
+
613
+ // Calculate center: apply the zoom, the configured offset, as well as offset that exists as a result of padding.
614
+ const offset = Point.convert(options.offset);
615
+ // @ts-ignore
616
+ const paddingOffsetX = (options.padding.left - options.padding.right) / 2;
617
+ // @ts-ignore
618
+ const paddingOffsetY = (options.padding.top - options.padding.bottom) / 2;
619
+ const offsetAtInitialZoom = new Point(offset.x + paddingOffsetX, offset.y + paddingOffsetY);
620
+ const offsetAtFinalZoom = offsetAtInitialZoom.mult(tr.scale / tr.zoomScale(zoom));
621
+ const center = tr.unproject(p0world.add(p1world).div(2).sub(offsetAtFinalZoom));
622
+ return {
623
+ center,
624
+ zoom,
625
+ bearing
626
+ };
627
+ }
628
+ fitInternal(calculatedOptions, options, eventData) {
629
+ // cameraForBounds warns + returns undefined if unable to fit:
630
+ if (!calculatedOptions) {
631
+ return this;
714
632
  }
715
- }]);
716
- return Camera;
717
- }(EventEmitter);
718
- export { Camera as default };
633
+ options = merge(calculatedOptions, options);
634
+ // Explictly remove the padding field because, calculatedOptions already accounts for padding by setting zoom and center accordingly.
635
+ delete options.padding;
636
+ // @ts-ignore
637
+ return options.linear ? this.easeTo(options, eventData) : this.flyTo(options, eventData);
638
+ }
639
+ }