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