@antv/l7-map 2.18.0 → 2.18.2

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