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