@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.
Files changed (158) hide show
  1. package/es/camera.js +595 -674
  2. package/es/earthmap.js +313 -276
  3. package/es/geo/edge_insets.js +57 -72
  4. package/es/geo/lng_lat.js +50 -64
  5. package/es/geo/lng_lat_bounds.js +101 -137
  6. package/es/geo/mercator.js +23 -35
  7. package/es/geo/point.js +150 -221
  8. package/es/geo/simple.js +22 -34
  9. package/es/geo/transform.js +839 -905
  10. package/es/handler/blockable_map_event.js +46 -66
  11. package/es/handler/box_zoom.js +125 -143
  12. package/es/handler/click_zoom.js +37 -51
  13. package/es/handler/events/event.js +11 -9
  14. package/es/handler/events/map_mouse_event.js +39 -54
  15. package/es/handler/events/map_touch_event.js +54 -73
  16. package/es/handler/events/map_wheel_event.js +22 -38
  17. package/es/handler/events/render_event.js +6 -23
  18. package/es/handler/handler_inertia.js +98 -113
  19. package/es/handler/handler_manager.js +349 -437
  20. package/es/handler/handler_util.js +2 -2
  21. package/es/handler/keyboard.js +98 -110
  22. package/es/handler/map_event.js +81 -117
  23. package/es/handler/mouse/mouse_handler.js +81 -100
  24. package/es/handler/mouse/mousepan_handler.js +16 -39
  25. package/es/handler/mouse/mousepitch_hander.js +18 -40
  26. package/es/handler/mouse/mouserotate_hander.js +18 -40
  27. package/es/handler/mouse/util.js +7 -6
  28. package/es/handler/scroll_zoom.js +221 -231
  29. package/es/handler/shim/dblclick_zoom.js +36 -47
  30. package/es/handler/shim/drag_pan.js +41 -50
  31. package/es/handler/shim/drag_rotate.js +38 -48
  32. package/es/handler/shim/touch_zoom_rotate.js +68 -79
  33. package/es/handler/tap/single_tap_recognizer.js +60 -80
  34. package/es/handler/tap/tap_drag_zoom.js +72 -89
  35. package/es/handler/tap/tap_recognizer.js +37 -45
  36. package/es/handler/tap/tap_zoom.js +67 -95
  37. package/es/handler/touch/touch_pan.js +77 -96
  38. package/es/handler/touch/touch_pitch.js +61 -79
  39. package/es/handler/touch/touch_rotate.js +47 -67
  40. package/es/handler/touch/touch_zoom.js +29 -46
  41. package/es/handler/touch/two_touch.js +79 -104
  42. package/es/hash.js +75 -88
  43. package/es/map.js +318 -284
  44. package/es/util.js +18 -37
  45. package/es/utils/Aabb.js +60 -100
  46. package/es/utils/dom.js +32 -55
  47. package/es/utils/performance.js +25 -29
  48. package/es/utils/primitives.js +33 -43
  49. package/es/utils/task_queue.js +47 -76
  50. package/lib/camera.d.ts +86 -0
  51. package/lib/camera.js +597 -672
  52. package/lib/earthmap.d.ts +69 -0
  53. package/lib/earthmap.js +314 -276
  54. package/lib/geo/edge_insets.d.ts +54 -0
  55. package/lib/geo/edge_insets.js +58 -70
  56. package/lib/geo/lng_lat.d.ts +18 -0
  57. package/lib/geo/lng_lat.js +50 -62
  58. package/lib/geo/lng_lat_bounds.d.ts +25 -0
  59. package/lib/geo/lng_lat_bounds.js +102 -136
  60. package/lib/geo/mercator.d.ts +30 -0
  61. package/lib/geo/mercator.js +26 -37
  62. package/lib/geo/point.d.ts +40 -0
  63. package/lib/geo/point.js +151 -220
  64. package/lib/geo/simple.d.ts +30 -0
  65. package/lib/geo/simple.js +25 -36
  66. package/lib/geo/transform.d.ts +198 -0
  67. package/lib/geo/transform.js +844 -907
  68. package/lib/handler/IHandler.d.ts +34 -0
  69. package/lib/handler/blockable_map_event.d.ts +17 -0
  70. package/lib/handler/blockable_map_event.js +48 -65
  71. package/lib/handler/box_zoom.d.ts +59 -0
  72. package/lib/handler/box_zoom.js +126 -143
  73. package/lib/handler/click_zoom.d.ts +16 -0
  74. package/lib/handler/click_zoom.js +38 -50
  75. package/lib/handler/events/event.d.ts +4 -0
  76. package/lib/handler/events/event.js +12 -9
  77. package/lib/handler/events/index.d.ts +4 -0
  78. package/lib/handler/events/index.js +3 -3
  79. package/lib/handler/events/map_mouse_event.d.ts +34 -0
  80. package/lib/handler/events/map_mouse_event.js +41 -52
  81. package/lib/handler/events/map_touch_event.d.ts +57 -0
  82. package/lib/handler/events/map_touch_event.js +56 -71
  83. package/lib/handler/events/map_wheel_event.d.ts +33 -0
  84. package/lib/handler/events/map_wheel_event.js +23 -37
  85. package/lib/handler/events/render_event.d.ts +5 -0
  86. package/lib/handler/events/render_event.js +7 -22
  87. package/lib/handler/handler_inertia.d.ts +23 -0
  88. package/lib/handler/handler_inertia.js +102 -112
  89. package/lib/handler/handler_manager.d.ts +61 -0
  90. package/lib/handler/handler_manager.js +351 -437
  91. package/lib/handler/handler_util.d.ts +4 -0
  92. package/lib/handler/handler_util.js +2 -2
  93. package/lib/handler/keyboard.d.ts +36 -0
  94. package/lib/handler/keyboard.js +98 -110
  95. package/lib/handler/map_event.d.ts +29 -0
  96. package/lib/handler/map_event.js +83 -116
  97. package/lib/handler/mouse/index.d.ts +4 -0
  98. package/lib/handler/mouse/index.js +3 -3
  99. package/lib/handler/mouse/mouse_handler.d.ts +22 -0
  100. package/lib/handler/mouse/mouse_handler.js +83 -99
  101. package/lib/handler/mouse/mousepan_handler.d.ts +10 -0
  102. package/lib/handler/mouse/mousepan_handler.js +19 -38
  103. package/lib/handler/mouse/mousepitch_hander.d.ts +9 -0
  104. package/lib/handler/mouse/mousepitch_hander.js +21 -39
  105. package/lib/handler/mouse/mouserotate_hander.d.ts +9 -0
  106. package/lib/handler/mouse/mouserotate_hander.js +21 -39
  107. package/lib/handler/mouse/util.d.ts +6 -0
  108. package/lib/handler/mouse/util.js +7 -7
  109. package/lib/handler/scroll_zoom.d.ts +93 -0
  110. package/lib/handler/scroll_zoom.js +221 -231
  111. package/lib/handler/shim/dblclick_zoom.d.ts +40 -0
  112. package/lib/handler/shim/dblclick_zoom.js +37 -46
  113. package/lib/handler/shim/drag_pan.d.ts +61 -0
  114. package/lib/handler/shim/drag_pan.js +42 -49
  115. package/lib/handler/shim/drag_rotate.d.ts +46 -0
  116. package/lib/handler/shim/drag_rotate.js +39 -47
  117. package/lib/handler/shim/touch_zoom_rotate.d.ts +70 -0
  118. package/lib/handler/shim/touch_zoom_rotate.js +69 -78
  119. package/lib/handler/tap/single_tap_recognizer.d.ts +20 -0
  120. package/lib/handler/tap/single_tap_recognizer.js +63 -79
  121. package/lib/handler/tap/tap_drag_zoom.d.ts +22 -0
  122. package/lib/handler/tap/tap_drag_zoom.js +74 -88
  123. package/lib/handler/tap/tap_recognizer.d.ts +17 -0
  124. package/lib/handler/tap/tap_recognizer.js +41 -47
  125. package/lib/handler/tap/tap_zoom.d.ts +22 -0
  126. package/lib/handler/tap/tap_zoom.js +69 -94
  127. package/lib/handler/touch/index.d.ts +5 -0
  128. package/lib/handler/touch/index.js +4 -4
  129. package/lib/handler/touch/touch_pan.d.ts +30 -0
  130. package/lib/handler/touch/touch_pan.js +79 -95
  131. package/lib/handler/touch/touch_pitch.d.ts +13 -0
  132. package/lib/handler/touch/touch_pitch.js +64 -78
  133. package/lib/handler/touch/touch_rotate.d.ts +12 -0
  134. package/lib/handler/touch/touch_rotate.js +50 -66
  135. package/lib/handler/touch/touch_zoom.d.ts +12 -0
  136. package/lib/handler/touch/touch_zoom.js +32 -45
  137. package/lib/handler/touch/two_touch.d.ts +23 -0
  138. package/lib/handler/touch/two_touch.js +81 -103
  139. package/lib/hash.d.ts +14 -0
  140. package/lib/hash.js +75 -88
  141. package/lib/index.d.ts +4 -0
  142. package/lib/index.js +4 -4
  143. package/lib/interface.d.ts +34 -0
  144. package/lib/map.d.ts +70 -0
  145. package/lib/map.js +319 -284
  146. package/lib/util.d.ts +25 -0
  147. package/lib/util.js +20 -36
  148. package/lib/utils/Aabb.d.ts +12 -0
  149. package/lib/utils/Aabb.js +61 -99
  150. package/lib/utils/dom.d.ts +4 -0
  151. package/lib/utils/dom.js +34 -55
  152. package/lib/utils/performance.d.ts +17 -0
  153. package/lib/utils/performance.js +25 -29
  154. package/lib/utils/primitives.d.ts +6 -0
  155. package/lib/utils/primitives.js +34 -42
  156. package/lib/utils/task_queue.d.ts +13 -0
  157. package/lib/utils/task_queue.js +47 -76
  158. 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
- 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); }; }
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
- function Camera(options) {
33
- var _this;
34
- (0, _classCallCheck2.default)(this, Camera);
35
- _this = _super.call(this);
36
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderFrameCallback", function () {
37
- var t = Math.min(((0, _util.now)() - _this.easeStart) / _this.easeOptions.duration, 1);
38
- _this.onEaseFrame(_this.easeOptions.easing(t));
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
- _this.easeFrameId = _this.requestRenderFrame(_this.renderFrameCallback);
49
+ this.easeFrameId = this.requestRenderFrame(this.renderFrameCallback);
42
50
  } else {
43
- _this.stop();
51
+ this.stop();
44
52
  }
45
53
  });
46
- _this.options = options;
47
- var minZoom = options.minZoom,
48
- maxZoom = options.maxZoom,
49
- minPitch = options.minPitch,
50
- maxPitch = options.maxPitch,
51
- renderWorldCopies = options.renderWorldCopies;
52
- _this.moving = false;
53
- _this.zooming = false;
54
- _this.bearingSnap = options.bearingSnap;
55
- _this.pitchEnabled = options.pitchEnabled;
56
- _this.rotateEnabled = options.rotateEnabled;
57
- _this.transform = new _transform.default(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies);
58
- return _this;
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
- (0, _createClass2.default)(Camera, [{
62
- key: "requestRenderFrame",
63
- value: function requestRenderFrame(cb) {
64
- return 0;
65
- }
66
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
- }, {
68
- key: "cancelRenderFrame",
69
- value: function cancelRenderFrame(_) {
70
- return;
71
- }
72
- }, {
73
- key: "getCenter",
74
- value: function getCenter() {
75
- var _this$transform$cente = this.transform.center,
76
- lng = _this$transform$cente.lng,
77
- lat = _this$transform$cente.lat;
78
- return new _lng_lat.default(lng, lat);
79
- }
80
- }, {
81
- key: "getZoom",
82
- value: function getZoom() {
83
- return this.transform.zoom;
84
- }
85
- }, {
86
- key: "getPitch",
87
- value: function getPitch() {
88
- return this.transform.pitch;
89
- }
90
- }, {
91
- key: "setCenter",
92
- value: function setCenter(center, eventData) {
93
- return this.jumpTo({
94
- center: center
95
- }, eventData);
96
- }
97
- }, {
98
- key: "setPitch",
99
- value: function setPitch(pitch, eventData) {
100
- this.jumpTo({
101
- pitch: pitch
102
- }, eventData);
103
- return this;
104
- }
105
- }, {
106
- key: "getBearing",
107
- value: function getBearing() {
108
- return this.transform.bearing;
109
- }
110
- }, {
111
- key: "panTo",
112
- value: function panTo(lnglat, options, eventData) {
113
- return this.easeTo(merge({
114
- center: lnglat
115
- }, options), eventData);
116
- }
117
- }, {
118
- key: "panBy",
119
- value: function panBy(offset, options, eventData) {
120
- offset = _point.default.convert(offset).mult(-1);
121
- return this.panTo(this.transform.center, (0, _util.extend)({
122
- offset: offset
123
- }, options || {}), eventData);
124
- }
125
- }, {
126
- key: "zoomOut",
127
- value: function zoomOut(options, eventData) {
128
- this.zoomTo(this.getZoom() - 1, options, eventData);
129
- return this;
130
- }
131
- }, {
132
- key: "setBearing",
133
- value: function setBearing(bearing, eventData) {
134
- this.jumpTo({
135
- bearing: bearing
136
- }, eventData);
137
- return this;
138
- }
139
- }, {
140
- key: "setZoom",
141
- value: function setZoom(zoom, eventData) {
142
- this.jumpTo({
143
- zoom: zoom
144
- }, eventData);
145
- return this;
146
- }
147
- }, {
148
- key: "zoomIn",
149
- value: function zoomIn(options, eventData) {
150
- this.zoomTo(this.getZoom() + 1, options, eventData);
151
- return this;
152
- }
153
- }, {
154
- key: "zoomTo",
155
- value: function zoomTo(zoom, options, eventData) {
156
- return this.easeTo(merge({
157
- zoom: zoom
158
- }, options), eventData);
159
- }
160
- }, {
161
- key: "getPadding",
162
- value: function getPadding() {
163
- return this.transform.padding;
164
- }
165
- }, {
166
- key: "setPadding",
167
- value: function setPadding(padding, eventData) {
168
- this.jumpTo({
169
- padding: padding
170
- }, eventData);
171
- return this;
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
- key: "jumpTo",
223
- value: function jumpTo() {
224
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
225
- var eventData = arguments.length > 1 ? arguments[1] : undefined;
226
- this.stop();
227
- var tr = this.transform;
228
- var zoomChanged = false;
229
- var bearingChanged = false;
230
- var pitchChanged = false;
231
- if (options.zoom !== undefined && tr.zoom !== +options.zoom) {
232
- zoomChanged = true;
233
- tr.zoom = +options.zoom;
234
- }
235
- if (options.center !== undefined) {
236
- tr.center = _lng_lat.default.convert(options.center);
237
- }
238
- if (options.bearing !== undefined && tr.bearing !== +options.bearing) {
239
- bearingChanged = true;
240
- tr.bearing = +options.bearing;
241
- }
242
- if (options.pitch !== undefined && tr.pitch !== +options.pitch) {
243
- pitchChanged = true;
244
- tr.pitch = +options.pitch;
245
- }
246
- if (options.padding !== undefined && !tr.isPaddingEqual(options.padding)) {
247
- tr.padding = options.padding;
248
- }
249
- this.emit('movestart', new _event.Event('movestart', eventData));
250
- this.emit('move', new _event.Event('move', eventData));
251
- if (zoomChanged) {
252
- this.emit('zoomstart', new _event.Event('zoomstart', eventData));
253
- this.emit('zoom', new _event.Event('zoom', eventData));
254
- this.emit('zoomend', new _event.Event('zoomend', eventData));
255
- }
256
- if (bearingChanged) {
257
- this.emit('rotatestart', new _event.Event('rotatestart', eventData));
258
- this.emit('rotate', new _event.Event('rotate', eventData));
259
- this.emit('rotateend', new _event.Event('rotateend', eventData));
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 (pitchChanged) {
262
- this.emit('pitchstart', new _event.Event('pitchstart', eventData));
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
- return this.emit('moveend', new _event.Event('moveend', eventData));
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
- var tr = this.transform;
283
- var startZoom = this.getZoom();
284
- var startBearing = this.getBearing();
285
- var startPitch = this.getPitch();
286
- var startPadding = this.getPadding();
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
- var currently = {
306
- moving: this.moving,
307
- zooming: this.zooming,
308
- rotating: this.rotating,
309
- pitching: this.pitching
310
- };
311
- this.zooming = this.zooming || zoom !== startZoom;
312
- this.rotating = this.rotating || startBearing !== bearing;
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.stop();
363
- options = merge({
364
- offset: [0, 0],
365
- speed: 1.2,
366
- curve: 1.42,
367
- easing: _util.ease
368
- }, options);
369
- var tr = this.transform;
370
- var startZoom = this.getZoom();
371
- var startBearing = this.getBearing();
372
- var startPitch = this.getPitch();
373
- var startPadding = this.getPadding();
374
- var zoom = options.zoom ? (0, _util.clamp)(+options.zoom, tr.minZoom, tr.maxZoom) : startZoom;
375
- var bearing = options.bearing ? this.normalizeBearing(options.bearing, startBearing) : startBearing;
376
- var pitch = options.pitch ? +options.pitch : startPitch;
377
- var padding = 'padding' in options ? options.padding : tr.padding;
378
- var scale = tr.zoomScale(zoom - startZoom);
379
- var offsetAsPoint = _point.default.convert(options.offset);
380
- var pointAtOffset = tr.centerPoint.add(offsetAsPoint);
381
- var locationAtOffset = tr.pointLocation(pointAtOffset);
382
- var center = _lng_lat.default.convert(options.center || locationAtOffset);
383
- this.normalizeCenter(center);
384
- var from = tr.project(locationAtOffset);
385
- var delta = tr.project(center).sub(from);
386
- var rho = options.curve;
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
- // w₀: Initial visible span, measured in pixels at the initial scale.
389
- var w0 = Math.max(tr.width, tr.height);
390
- // w₁: Final visible span, measured in pixels with respect to the initial scale.
391
- var w1 = w0 / scale;
392
- // Length of the flight path as projected onto the ground plane, measured in pixels from
393
- // the world image origin at the initial scale.
394
- var u1 = delta.mag();
395
- if ('minZoom' in options) {
396
- var minZoom = (0, _util.clamp)(Math.min(options.minZoom, startZoom, zoom), tr.minZoom, tr.maxZoom);
397
- // w<sub>m</sub>: Maximum visible span, measured in pixels with respect to the initial
398
- // scale.
399
- var wMax = w0 / tr.zoomScale(minZoom - startZoom);
400
- rho = Math.sqrt(wMax / u1 * 2);
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
- var rho2 = rho * rho;
353
+ // ρ²
354
+ const rho2 = rho * rho;
405
355
 
406
- /**
407
- * rᵢ: Returns the zoom-out factor at one end of the animation.
408
- *
409
- * @param i 0 for the ascent or 1 for the descent.
410
- * @private
411
- */
412
- function r(i) {
413
- var b = (w1 * w1 - w0 * w0 + (i ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (i ? w1 : w0) * rho2 * u1);
414
- return Math.log(Math.sqrt(b * b + 1) - b);
415
- }
416
- function sinh(n) {
417
- return (Math.exp(n) - Math.exp(-n)) / 2;
418
- }
419
- function cosh(n) {
420
- return (Math.exp(n) + Math.exp(-n)) / 2;
421
- }
422
- function tanh(n) {
423
- return sinh(n) / cosh(n);
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
- // r₀: Zoom-out factor during ascent.
427
- var r0 = r(0);
376
+ // r₀: Zoom-out factor during ascent.
377
+ const r0 = r(0);
428
378
 
429
- // w(s): Returns the visible span on the ground, measured in pixels with respect to the
430
- // initial scale. Assumes an angular field of view of 2 arctan ½ ≈ 53°.
431
- var w = function w(s) {
432
- return cosh(r0) / cosh(r0 + rho * s);
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
- // u(s): Returns the distance along the flight path as projected onto the ground plane,
436
- // measured in pixels from the world image origin at the initial scale.
437
- var u = function u(s) {
438
- return w0 * ((cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2) / u1;
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
- // S: Total length of the flight path, measured in ρ-screenfuls.
442
- var S = (r(1) - r0) / rho;
391
+ // S: Total length of the flight path, measured in ρ-screenfuls.
392
+ let S = (r(1) - r0) / rho;
443
393
 
444
- // When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
445
- if (Math.abs(u1) < 0.000001 || !isFinite(S)) {
446
- // Perform a more or less instantaneous transition if the path is too short.
447
- if (Math.abs(w0 - w1) < 0.000001) {
448
- return this.easeTo(options, eventData);
449
- }
450
- var k = w1 < w0 ? -1 : 1;
451
- S = Math.abs(Math.log(w1 / w0)) / rho;
452
- u = function u() {
453
- return 0;
454
- };
455
- w = function w(s) {
456
- return Math.exp(k * rho * s);
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
- key: "fitScreenCoordinates",
501
- value: function fitScreenCoordinates(p0, p1, bearing, options, eventData) {
502
- return this.fitInternal(
503
- // @ts-ignore
504
- this.cameraForBoxAndBearing(this.transform.pointLocation(_point.default.convert(p0)), this.transform.pointLocation(_point.default.convert(p1)), bearing,
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
- options), options, eventData);
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
- this.emit('rotate', new _event.Event('rotate', eventData));
430
+ tr.bearing = (0, _util.interpolate)(startBearing, bearing, k);
565
431
  }
566
432
  if (this.pitching) {
567
- this.emit('rotate', new _event.Event('pitch', eventData));
568
- }
569
- }
570
- }, {
571
- key: "prepareEase",
572
- value: function prepareEase(eventData) {
573
- var noMoveStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
574
- var currently = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
575
- this.moving = true;
576
- if (!noMoveStart && !currently.moving) {
577
- this.emit('movestart', new _event.Event('movestart', eventData));
578
- }
579
- if (this.zooming && !currently.zooming) {
580
- this.emit('zoomstart', new _event.Event('zoomstart', eventData));
581
- }
582
- if (this.rotating && !currently.rotating) {
583
- this.emit('rotatestart', new _event.Event('rotatestart', eventData));
584
- }
585
- if (this.pitching && !currently.pitching) {
586
- this.emit('pitchstart', new _event.Event('pitchstart', eventData));
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
- key: "afterEase",
591
- value: function afterEase(eventData, easeId) {
592
- // if this easing is being stopped to start another easing with
593
- // the same id then don't fire any events to avoid extra start/stop events
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.easeId;
599
- var wasZooming = this.zooming;
600
- var wasRotating = this.rotating;
601
- var wasPitching = this.pitching;
602
- this.moving = false;
603
- this.zooming = false;
604
- this.rotating = false;
605
- this.pitching = false;
606
- this.padding = false;
607
- if (wasZooming) {
608
- this.emit('zoomend', new _event.Event('zoomend', eventData));
609
- }
610
- if (wasRotating) {
611
- this.emit('rotateend', new _event.Event('rotateend', eventData));
612
- }
613
- if (wasPitching) {
614
- this.emit('pitchend', new _event.Event('pitchend', eventData));
615
- }
616
- this.emit('moveend', new _event.Event('moveend', eventData));
617
- }
618
- }, {
619
- key: "ease",
620
- value: function ease(frame, finish, options) {
621
- if (options.animate === false || options.duration === 0) {
622
- frame(1);
623
- finish();
624
- } else {
625
- this.easeStart = (0, _util.now)();
626
- this.easeOptions = options;
627
- this.onEaseFrame = frame;
628
- this.onEaseEnd = finish;
629
- this.easeFrameId = this.requestRenderFrame(this.renderFrameCallback);
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
- key: "cameraForBoxAndBearing",
634
- value: function cameraForBoxAndBearing(p0, p1, bearing, options) {
635
- var defaultPadding = {
636
- top: 0,
637
- bottom: 0,
638
- right: 0,
639
- left: 0
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
- options = merge({
642
- padding: defaultPadding,
643
- offset: [0, 0],
644
- maxZoom: this.transform.maxZoom
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
- // We want to calculate the upper right and lower left of the box defined by p0 and p1
660
- // in a coordinate system rotate to match the destination bearing.
661
- var p0world = tr.project(_lng_lat.default.convert(p0));
662
- var p1world = tr.project(_lng_lat.default.convert(p1));
663
- var p0rotated = p0world.rotate(-bearing * Math.PI / 180);
664
- var p1rotated = p1world.rotate(-bearing * Math.PI / 180);
665
- var upperRight = new _point.default(Math.max(p0rotated.x, p1rotated.x), Math.max(p0rotated.y, p1rotated.y));
666
- var lowerLeft = new _point.default(Math.min(p0rotated.x, p1rotated.x), Math.min(p0rotated.y, p1rotated.y));
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
- // Calculate zoom: consider the original bbox and padding.
669
- var size = upperRight.sub(lowerLeft);
670
- var scaleX = (tr.width - (
671
- // @ts-ignore
672
- edgePadding.left +
673
- // @ts-ignore
674
- edgePadding.right +
675
- // @ts-ignore
676
- options.padding.left +
677
- // @ts-ignore
678
- options.padding.right)) / size.x;
679
- var scaleY = (tr.height - (
680
- // @ts-ignore
681
- edgePadding.top +
682
- // @ts-ignore
683
- edgePadding.bottom +
684
- // @ts-ignore
685
- options.padding.top +
686
- // @ts-ignore
687
- options.padding.bottom)) / size.y;
688
- if (scaleY < 0 || scaleX < 0) {
689
- return;
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
- key: "fitInternal",
710
- value: function fitInternal(calculatedOptions, options, eventData) {
711
- // cameraForBounds warns + returns undefined if unable to fit:
712
- if (!calculatedOptions) {
713
- return this;
714
- }
715
- options = merge(calculatedOptions, options);
716
- // Explictly remove the padding field because, calculatedOptions already accounts for padding by setting zoom and center accordingly.
717
- delete options.padding;
718
- // @ts-ignore
719
- return options.linear ? this.easeTo(options, eventData) : this.flyTo(options, eventData);
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
- return Camera;
723
- }(_eventemitter.EventEmitter);
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;