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