@antv/l7-map 2.21.1 → 2.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 -5
  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 -42
  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 -6
  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 -41
  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
@@ -1,78 +1,64 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
- 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; } }
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
2
  // @ts-ignore
9
3
 
10
4
  import Point from "../../geo/point";
11
5
  import DOM from "../../utils/dom";
12
6
  import { Event } from "./event";
13
- var MapTouchEvent = /*#__PURE__*/function (_Event) {
14
- _inherits(MapTouchEvent, _Event);
15
- var _super = _createSuper(MapTouchEvent);
7
+ export default class MapTouchEvent extends Event {
16
8
  /**
17
- * The event type.
18
- */
19
-
20
- /**
21
- * The `Map` object that fired the event.
22
- */
23
-
24
- /**
25
- * The DOM event which caused the map event.
26
- */
27
-
28
- /**
29
- * The geographic location on the map of the center of the touch event points.
30
- */
31
-
32
- /**
33
- * The pixel coordinates of the center of the touch event points, relative to the map and measured from the top left
34
- * corner.
35
- */
36
-
37
- /**
38
- * The array of pixel coordinates corresponding to a
39
- * [touch event's `touches`](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/touches) property.
40
- */
41
-
42
- /**
43
- * The geographical locations on the map corresponding to a
44
- * [touch event's `touches`](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/touches) property.
45
- */
46
-
47
- /**
48
- * `true` if `preventDefault` has been called.
49
9
  * @private
50
10
  */
51
-
52
- /**
53
- * @private
54
- */
55
- function MapTouchEvent(type, map, originalEvent) {
56
- var _this;
57
- _classCallCheck(this, MapTouchEvent);
58
- var touches = type === 'touchend' ? originalEvent.changedTouches : originalEvent.touches;
59
- var points = DOM.touchPos(map.getCanvasContainer(), touches);
60
- var lngLats = points.map(function (t) {
61
- return map.unproject(t);
62
- });
63
- var point = points.reduce(function (prev, curr, i, arr) {
11
+ constructor(type, map, originalEvent) {
12
+ const touches = type === 'touchend' ? originalEvent.changedTouches : originalEvent.touches;
13
+ const points = DOM.touchPos(map.getCanvasContainer(), touches);
14
+ const lngLats = points.map(t => map.unproject(t));
15
+ const point = points.reduce((prev, curr, i, arr) => {
64
16
  return prev.add(curr.div(arr.length));
65
17
  }, new Point(0, 0));
66
- var lngLat = map.unproject(point);
67
- _this = _super.call(this, type, {
68
- points: points,
69
- point: point,
70
- lngLats: lngLats,
71
- lngLat: lngLat,
72
- originalEvent: originalEvent
18
+ const lngLat = map.unproject(point);
19
+ super(type, {
20
+ points,
21
+ point,
22
+ lngLats,
23
+ lngLat,
24
+ originalEvent
73
25
  });
74
- _this.defaultPrevented = false;
75
- return _this;
26
+ /**
27
+ * The event type.
28
+ */
29
+ /**
30
+ * The `Map` object that fired the event.
31
+ */
32
+ _defineProperty(this, "target", void 0);
33
+ /**
34
+ * The DOM event which caused the map event.
35
+ */
36
+ _defineProperty(this, "originalEvent", void 0);
37
+ /**
38
+ * The geographic location on the map of the center of the touch event points.
39
+ */
40
+ _defineProperty(this, "lngLat", void 0);
41
+ /**
42
+ * The pixel coordinates of the center of the touch event points, relative to the map and measured from the top left
43
+ * corner.
44
+ */
45
+ _defineProperty(this, "point", void 0);
46
+ /**
47
+ * The array of pixel coordinates corresponding to a
48
+ * [touch event's `touches`](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/touches) property.
49
+ */
50
+ _defineProperty(this, "points", void 0);
51
+ /**
52
+ * The geographical locations on the map corresponding to a
53
+ * [touch event's `touches`](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/touches) property.
54
+ */
55
+ _defineProperty(this, "lngLats", void 0);
56
+ /**
57
+ * `true` if `preventDefault` has been called.
58
+ * @private
59
+ */
60
+ _defineProperty(this, "defaultPrevented", void 0);
61
+ this.defaultPrevented = false;
76
62
  }
77
63
 
78
64
  /**
@@ -84,12 +70,7 @@ var MapTouchEvent = /*#__PURE__*/function (_Event) {
84
70
  * * On `touchstart` events, the behavior of {@link TouchZoomRotateHandler}
85
71
  *
86
72
  */
87
- _createClass(MapTouchEvent, [{
88
- key: "preventDefault",
89
- value: function preventDefault() {
90
- this.defaultPrevented = true;
91
- }
92
- }]);
93
- return MapTouchEvent;
94
- }(Event);
95
- export { MapTouchEvent as default };
73
+ preventDefault() {
74
+ this.defaultPrevented = true;
75
+ }
76
+ }
@@ -1,37 +1,26 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
- 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; } }
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
2
  import { Event } from "./event";
9
- var MapWheelEvent = /*#__PURE__*/function (_Event) {
10
- _inherits(MapWheelEvent, _Event);
11
- var _super = _createSuper(MapWheelEvent);
12
- /**
13
- * The event type.
14
- */
15
-
16
- /**
17
- * The DOM event which caused the map event.
18
- */
19
-
20
- /**
21
- * The `Map` object that fired the event.
22
- */
23
-
3
+ export default class MapWheelEvent extends Event {
24
4
  /**
25
5
  * @private
26
6
  */
27
- function MapWheelEvent(type, map, originalEvent) {
28
- var _this;
29
- _classCallCheck(this, MapWheelEvent);
30
- _this = _super.call(this, type, {
31
- originalEvent: originalEvent
7
+ constructor(type, map, originalEvent) {
8
+ super(type, {
9
+ originalEvent
32
10
  });
33
- _this.defaultPrevented = false;
34
- return _this;
11
+ /**
12
+ * The event type.
13
+ */
14
+ /**
15
+ * The DOM event which caused the map event.
16
+ */
17
+ _defineProperty(this, "originalEvent", void 0);
18
+ _defineProperty(this, "defaultPrevented", void 0);
19
+ /**
20
+ * The `Map` object that fired the event.
21
+ */
22
+ _defineProperty(this, "target", void 0);
23
+ this.defaultPrevented = false;
35
24
  }
36
25
 
37
26
  /**
@@ -39,12 +28,7 @@ var MapWheelEvent = /*#__PURE__*/function (_Event) {
39
28
  *
40
29
  * Calling this method will prevent the the behavior of {@link ScrollZoomHandler}.
41
30
  */
42
- _createClass(MapWheelEvent, [{
43
- key: "preventDefault",
44
- value: function preventDefault() {
45
- this.defaultPrevented = true;
46
- }
47
- }]);
48
- return MapWheelEvent;
49
- }(Event);
50
- export { MapWheelEvent as default };
31
+ preventDefault() {
32
+ this.defaultPrevented = true;
33
+ }
34
+ }
@@ -1,26 +1,9 @@
1
- import _createClass from "@babel/runtime/helpers/esm/createClass";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/esm/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
7
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
2
  import { Event } from "./event";
11
- var RenderFrameEvent = /*#__PURE__*/function (_Event) {
12
- _inherits(RenderFrameEvent, _Event);
13
- var _super = _createSuper(RenderFrameEvent);
14
- function RenderFrameEvent() {
15
- var _this;
16
- _classCallCheck(this, RenderFrameEvent);
17
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
18
- args[_key] = arguments[_key];
19
- }
20
- _this = _super.call.apply(_super, [this].concat(args));
21
- _defineProperty(_assertThisInitialized(_this), "type", 'renderFrame');
22
- return _this;
3
+ export default class RenderFrameEvent extends Event {
4
+ constructor(...args) {
5
+ super(...args);
6
+ _defineProperty(this, "type", 'renderFrame');
7
+ _defineProperty(this, "timeStamp", void 0);
23
8
  }
24
- return _createClass(RenderFrameEvent);
25
- }(Event);
26
- export { RenderFrameEvent as default };
9
+ }
@@ -1,142 +1,125 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
2
  // @ts-ignore
7
3
  import Point from "../geo/point";
8
4
 
9
5
  // tslint:disable-next-line:no-submodule-imports
10
6
  import { lodashUtil } from '@antv/l7-utils';
11
7
  import { bezier, clamp, now } from "../util";
12
- var merge = lodashUtil.merge;
13
- var defaultInertiaOptions = {
8
+ const {
9
+ merge
10
+ } = lodashUtil;
11
+ const defaultInertiaOptions = {
14
12
  linearity: 0.3,
15
13
  easing: bezier(0, 0, 0.3, 1)
16
14
  };
17
- var defaultPanInertiaOptions = merge({
15
+ const defaultPanInertiaOptions = merge({
18
16
  deceleration: 2500,
19
17
  maxSpeed: 1400
20
18
  }, defaultInertiaOptions);
21
- var defaultZoomInertiaOptions = merge({
19
+ const defaultZoomInertiaOptions = merge({
22
20
  deceleration: 20,
23
21
  maxSpeed: 1400
24
22
  }, defaultInertiaOptions);
25
- var defaultBearingInertiaOptions = merge({
23
+ const defaultBearingInertiaOptions = merge({
26
24
  deceleration: 1000,
27
25
  maxSpeed: 360
28
26
  }, defaultInertiaOptions);
29
- var defaultPitchInertiaOptions = merge({
27
+ const defaultPitchInertiaOptions = merge({
30
28
  deceleration: 1000,
31
29
  maxSpeed: 90
32
30
  }, defaultInertiaOptions);
33
- var HandlerInertia = /*#__PURE__*/function () {
34
- function HandlerInertia(map) {
35
- _classCallCheck(this, HandlerInertia);
31
+ export default class HandlerInertia {
32
+ constructor(map) {
33
+ _defineProperty(this, "map", void 0);
34
+ _defineProperty(this, "inertiaBuffer", void 0);
36
35
  this.map = map;
37
36
  this.clear();
38
37
  }
39
- _createClass(HandlerInertia, [{
40
- key: "clear",
41
- value: function clear() {
42
- this.inertiaBuffer = [];
43
- }
44
- }, {
45
- key: "record",
46
- value: function record(settings) {
47
- this.drainInertiaBuffer();
48
- this.inertiaBuffer.push({
49
- time: now(),
50
- settings: settings
51
- });
52
- }
53
- }, {
54
- key: "drainInertiaBuffer",
55
- value: function drainInertiaBuffer() {
56
- var inertia = this.inertiaBuffer;
57
- var nowTime = now();
58
- var cutoff = 160; // msec
38
+ clear() {
39
+ this.inertiaBuffer = [];
40
+ }
41
+ record(settings) {
42
+ this.drainInertiaBuffer();
43
+ this.inertiaBuffer.push({
44
+ time: now(),
45
+ settings
46
+ });
47
+ }
48
+ drainInertiaBuffer() {
49
+ const inertia = this.inertiaBuffer;
50
+ const nowTime = now();
51
+ const cutoff = 160; // msec
59
52
 
60
- while (inertia.length > 0 && nowTime - inertia[0].time > cutoff) {
61
- inertia.shift();
62
- }
53
+ while (inertia.length > 0 && nowTime - inertia[0].time > cutoff) {
54
+ inertia.shift();
63
55
  }
64
- }, {
65
- key: "onMoveEnd",
66
- value: function onMoveEnd(panInertiaOptions) {
67
- this.drainInertiaBuffer();
68
- if (this.inertiaBuffer.length < 2) {
69
- return;
70
- }
71
- var deltas = {
72
- zoom: 0,
73
- bearing: 0,
74
- pitch: 0,
75
- pan: new Point(0, 0),
76
- pinchAround: undefined,
77
- around: undefined
78
- };
79
- var _iterator = _createForOfIteratorHelper(this.inertiaBuffer),
80
- _step;
81
- try {
82
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
83
- var settings = _step.value.settings;
84
- deltas.zoom += settings.zoomDelta || 0;
85
- deltas.bearing += settings.bearingDelta || 0;
86
- deltas.pitch += settings.pitchDelta || 0;
87
- if (settings.panDelta) {
88
- deltas.pan._add(settings.panDelta);
89
- }
90
- if (settings.around) {
91
- deltas.around = settings.around;
92
- }
93
- if (settings.pinchAround) {
94
- deltas.pinchAround = settings.pinchAround;
95
- }
96
- }
97
- } catch (err) {
98
- _iterator.e(err);
99
- } finally {
100
- _iterator.f();
101
- }
102
- var lastEntry = this.inertiaBuffer[this.inertiaBuffer.length - 1];
103
- var duration = lastEntry.time - this.inertiaBuffer[0].time;
104
- var easeOptions = {};
105
- if (deltas.pan.mag()) {
106
- var result = calculateEasing(deltas.pan.mag(), duration, merge({}, defaultPanInertiaOptions, panInertiaOptions || {}));
107
- easeOptions.offset = deltas.pan.mult(result.amount / deltas.pan.mag());
108
- easeOptions.center = this.map.transform.center;
109
- extendDuration(easeOptions, result);
110
- }
111
- if (deltas.zoom) {
112
- var _result = calculateEasing(deltas.zoom, duration, defaultZoomInertiaOptions);
113
- easeOptions.zoom = this.map.transform.zoom + _result.amount;
114
- extendDuration(easeOptions, _result);
115
- }
116
- if (deltas.bearing) {
117
- var _result2 = calculateEasing(deltas.bearing, duration, defaultBearingInertiaOptions);
118
- easeOptions.bearing = this.map.transform.bearing + clamp(_result2.amount, -179, 179);
119
- extendDuration(easeOptions, _result2);
56
+ }
57
+ onMoveEnd(panInertiaOptions) {
58
+ this.drainInertiaBuffer();
59
+ if (this.inertiaBuffer.length < 2) {
60
+ return;
61
+ }
62
+ const deltas = {
63
+ zoom: 0,
64
+ bearing: 0,
65
+ pitch: 0,
66
+ pan: new Point(0, 0),
67
+ pinchAround: undefined,
68
+ around: undefined
69
+ };
70
+ for (const {
71
+ settings
72
+ } of this.inertiaBuffer) {
73
+ deltas.zoom += settings.zoomDelta || 0;
74
+ deltas.bearing += settings.bearingDelta || 0;
75
+ deltas.pitch += settings.pitchDelta || 0;
76
+ if (settings.panDelta) {
77
+ deltas.pan._add(settings.panDelta);
120
78
  }
121
- if (deltas.pitch) {
122
- var _result3 = calculateEasing(deltas.pitch, duration, defaultPitchInertiaOptions);
123
- easeOptions.pitch = this.map.transform.pitch + _result3.amount;
124
- extendDuration(easeOptions, _result3);
79
+ if (settings.around) {
80
+ deltas.around = settings.around;
125
81
  }
126
- if (easeOptions.zoom || easeOptions.bearing) {
127
- var last = deltas.pinchAround === undefined ? deltas.around : deltas.pinchAround;
128
- easeOptions.around = last ? this.map.unproject(last) : this.map.getCenter();
82
+ if (settings.pinchAround) {
83
+ deltas.pinchAround = settings.pinchAround;
129
84
  }
130
- this.clear();
131
- return merge(easeOptions, {
132
- noMoveStart: true
133
- });
134
85
  }
135
- }]);
136
- return HandlerInertia;
137
- }(); // Unfortunately zoom, bearing, etc can't have different durations and easings so
86
+ const lastEntry = this.inertiaBuffer[this.inertiaBuffer.length - 1];
87
+ const duration = lastEntry.time - this.inertiaBuffer[0].time;
88
+ const easeOptions = {};
89
+ if (deltas.pan.mag()) {
90
+ const result = calculateEasing(deltas.pan.mag(), duration, merge({}, defaultPanInertiaOptions, panInertiaOptions || {}));
91
+ easeOptions.offset = deltas.pan.mult(result.amount / deltas.pan.mag());
92
+ easeOptions.center = this.map.transform.center;
93
+ extendDuration(easeOptions, result);
94
+ }
95
+ if (deltas.zoom) {
96
+ const result = calculateEasing(deltas.zoom, duration, defaultZoomInertiaOptions);
97
+ easeOptions.zoom = this.map.transform.zoom + result.amount;
98
+ extendDuration(easeOptions, result);
99
+ }
100
+ if (deltas.bearing) {
101
+ const result = calculateEasing(deltas.bearing, duration, defaultBearingInertiaOptions);
102
+ easeOptions.bearing = this.map.transform.bearing + clamp(result.amount, -179, 179);
103
+ extendDuration(easeOptions, result);
104
+ }
105
+ if (deltas.pitch) {
106
+ const result = calculateEasing(deltas.pitch, duration, defaultPitchInertiaOptions);
107
+ easeOptions.pitch = this.map.transform.pitch + result.amount;
108
+ extendDuration(easeOptions, result);
109
+ }
110
+ if (easeOptions.zoom || easeOptions.bearing) {
111
+ const last = deltas.pinchAround === undefined ? deltas.around : deltas.pinchAround;
112
+ easeOptions.around = last ? this.map.unproject(last) : this.map.getCenter();
113
+ }
114
+ this.clear();
115
+ return merge(easeOptions, {
116
+ noMoveStart: true
117
+ });
118
+ }
119
+ }
120
+
121
+ // Unfortunately zoom, bearing, etc can't have different durations and easings so
138
122
  // we need to choose one. We use the longest duration and it's corresponding easing.
139
- export { HandlerInertia as default };
140
123
  function extendDuration(easeOptions, result) {
141
124
  if (!easeOptions.duration || easeOptions.duration < result.duration) {
142
125
  easeOptions.duration = result.duration;
@@ -144,11 +127,13 @@ function extendDuration(easeOptions, result) {
144
127
  }
145
128
  }
146
129
  function calculateEasing(amount, inertiaDuration, inertiaOptions) {
147
- var maxSpeed = inertiaOptions.maxSpeed,
148
- linearity = inertiaOptions.linearity,
149
- deceleration = inertiaOptions.deceleration;
150
- var speed = clamp(amount * linearity / (inertiaDuration / 1000), -maxSpeed, maxSpeed);
151
- var duration = Math.abs(speed) / (deceleration * linearity);
130
+ const {
131
+ maxSpeed,
132
+ linearity,
133
+ deceleration
134
+ } = inertiaOptions;
135
+ const speed = clamp(amount * linearity / (inertiaDuration / 1000), -maxSpeed, maxSpeed);
136
+ const duration = Math.abs(speed) / (deceleration * linearity);
152
137
  return {
153
138
  easing: inertiaOptions.easing,
154
139
  duration: duration * 1000,