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