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