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