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