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