@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
@@ -1,5 +1,3 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
2
  // @ts-ignore
5
3
 
@@ -7,74 +5,94 @@ import LngLat from "../geo/lng_lat";
7
5
  import { bezier, ease, interpolate, now } from "../util";
8
6
  import DOM from "../utils/dom";
9
7
  // deltaY value for mouse scroll wheel identification
10
- var wheelZoomDelta = 4.000244140625;
8
+ const wheelZoomDelta = 4.000244140625;
11
9
 
12
10
  // These magic numbers control the rate of zoom. Trackpad events fire at a greater
13
11
  // frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick
14
- var defaultZoomRate = 1 / 100;
15
- var wheelZoomRate = 1 / 450;
12
+ const defaultZoomRate = 1 / 100;
13
+ const wheelZoomRate = 1 / 450;
16
14
 
17
15
  // upper bound on how much we scale the map in any single render frame; this
18
16
  // is used to limit zoom rate in the case of very fast scrolling
19
- var maxScalePerFrame = 2;
17
+ const maxScalePerFrame = 2;
20
18
 
21
19
  /**
22
20
  * The `ScrollZoomHandler` allows the user to zoom the map by scrolling.
23
21
  */
24
- var ScrollZoomHandler = /*#__PURE__*/function () {
25
- // used for delayed-handling of a single wheel movement
26
- // used to delay final '{move,zoom}end' events
27
-
22
+ class ScrollZoomHandler {
28
23
  /**
29
24
  * @private
30
25
  */
31
- function ScrollZoomHandler(map, handler) {
32
- var _this = this;
33
- _classCallCheck(this, ScrollZoomHandler);
34
- _defineProperty(this, "onScrollFrame", function () {
35
- if (!_this.frameId) {
26
+ constructor(map, handler) {
27
+ _defineProperty(this, "map", void 0);
28
+ _defineProperty(this, "el", void 0);
29
+ _defineProperty(this, "enabled", void 0);
30
+ _defineProperty(this, "active", void 0);
31
+ _defineProperty(this, "zooming", void 0);
32
+ _defineProperty(this, "aroundCenter", void 0);
33
+ _defineProperty(this, "around", void 0);
34
+ _defineProperty(this, "aroundPoint", void 0);
35
+ _defineProperty(this, "type", void 0);
36
+ _defineProperty(this, "lastValue", void 0);
37
+ _defineProperty(this, "timeout", void 0);
38
+ // used for delayed-handling of a single wheel movement
39
+ _defineProperty(this, "finishTimeout", void 0);
40
+ // used to delay final '{move,zoom}end' events
41
+ _defineProperty(this, "lastWheelEvent", void 0);
42
+ _defineProperty(this, "lastWheelEventTime", void 0);
43
+ _defineProperty(this, "startZoom", void 0);
44
+ _defineProperty(this, "targetZoom", void 0);
45
+ _defineProperty(this, "delta", void 0);
46
+ _defineProperty(this, "easing", void 0);
47
+ _defineProperty(this, "prevEase", void 0);
48
+ _defineProperty(this, "frameId", void 0);
49
+ _defineProperty(this, "handler", void 0);
50
+ _defineProperty(this, "defaultZoomRate", void 0);
51
+ _defineProperty(this, "wheelZoomRate", void 0);
52
+ _defineProperty(this, "onScrollFrame", () => {
53
+ if (!this.frameId) {
36
54
  return;
37
55
  }
38
- _this.frameId = null;
39
- if (!_this.isActive()) {
56
+ this.frameId = null;
57
+ if (!this.isActive()) {
40
58
  return;
41
59
  }
42
- var tr = _this.map.transform;
60
+ const tr = this.map.transform;
43
61
 
44
62
  // if we've had scroll events since the last render frame, consume the
45
63
  // accumulated delta, and update the target zoom level accordingly
46
- if (_this.delta !== 0) {
64
+ if (this.delta !== 0) {
47
65
  // For trackpad events and single mouse wheel ticks, use the default zoom rate
48
- var zoomRate = _this.type === 'wheel' && Math.abs(_this.delta) > wheelZoomDelta ? _this.wheelZoomRate : _this.defaultZoomRate;
66
+ const zoomRate = this.type === 'wheel' && Math.abs(this.delta) > wheelZoomDelta ? this.wheelZoomRate : this.defaultZoomRate;
49
67
  // Scale by sigmoid of scroll wheel delta.
50
- var scale = maxScalePerFrame / (1 + Math.exp(-Math.abs(_this.delta * zoomRate)));
51
- if (_this.delta < 0 && scale !== 0) {
68
+ let scale = maxScalePerFrame / (1 + Math.exp(-Math.abs(this.delta * zoomRate)));
69
+ if (this.delta < 0 && scale !== 0) {
52
70
  scale = 1 / scale;
53
71
  }
54
- var fromScale = typeof _this.targetZoom === 'number' ? tr.zoomScale(_this.targetZoom) : tr.scale;
55
- _this.targetZoom = Math.min(tr.maxZoom, Math.max(tr.minZoom, tr.scaleZoom(fromScale * scale)));
72
+ const fromScale = typeof this.targetZoom === 'number' ? tr.zoomScale(this.targetZoom) : tr.scale;
73
+ this.targetZoom = Math.min(tr.maxZoom, Math.max(tr.minZoom, tr.scaleZoom(fromScale * scale)));
56
74
 
57
75
  // if this is a mouse wheel, refresh the starting zoom and easing
58
76
  // function we're using to smooth out the zooming between wheel
59
77
  // events
60
- if (_this.type === 'wheel') {
61
- _this.startZoom = tr.zoom;
62
- _this.easing = _this.smoothOutEasing(200);
78
+ if (this.type === 'wheel') {
79
+ this.startZoom = tr.zoom;
80
+ this.easing = this.smoothOutEasing(200);
63
81
  }
64
- _this.delta = 0;
82
+ this.delta = 0;
65
83
  }
66
- var targetZoom = typeof _this.targetZoom === 'number' ? _this.targetZoom : tr.zoom;
67
- var startZoom = _this.startZoom;
68
- var easing = _this.easing;
69
- var finished = false;
70
- var zoom;
71
- if (_this.type === 'wheel' && startZoom && easing) {
72
- var t = Math.min((now() - _this.lastWheelEventTime) / 200, 1);
73
- var k = easing(t);
84
+ const targetZoom = typeof this.targetZoom === 'number' ? this.targetZoom : tr.zoom;
85
+ const startZoom = this.startZoom;
86
+ const easing = this.easing;
87
+ let finished = false;
88
+ let zoom;
89
+ if (this.type === 'wheel' && startZoom && easing) {
90
+ const t = Math.min((now() - this.lastWheelEventTime) / 200, 1);
91
+ const k = easing(t);
74
92
  zoom = interpolate(startZoom, targetZoom, k);
75
93
  if (t < 1) {
76
- if (!_this.frameId) {
77
- _this.frameId = true;
94
+ if (!this.frameId) {
95
+ this.frameId = true;
78
96
  }
79
97
  } else {
80
98
  finished = true;
@@ -83,25 +101,25 @@ var ScrollZoomHandler = /*#__PURE__*/function () {
83
101
  zoom = targetZoom;
84
102
  finished = true;
85
103
  }
86
- _this.active = true;
104
+ this.active = true;
87
105
  if (finished) {
88
- _this.active = false;
106
+ this.active = false;
89
107
  // @ts-ignore
90
- _this.finishTimeout = setTimeout(function () {
91
- _this.zooming = false;
92
- _this.handler.triggerRenderFrame();
108
+ this.finishTimeout = setTimeout(() => {
109
+ this.zooming = false;
110
+ this.handler.triggerRenderFrame();
93
111
  // @ts-ignore
94
- delete _this.targetZoom;
112
+ delete this.targetZoom;
95
113
  // @ts-ignore
96
- delete _this.finishTimeout;
114
+ delete this.finishTimeout;
97
115
  }, 200);
98
116
  }
99
117
  return {
100
118
  noInertia: true,
101
119
  needsRenderFrame: !finished,
102
120
  zoomDelta: zoom - tr.zoom,
103
- around: _this.aroundPoint,
104
- originalEvent: _this.lastWheelEvent
121
+ around: this.aroundPoint,
122
+ originalEvent: this.lastWheelEvent
105
123
  };
106
124
  });
107
125
  this.map = map;
@@ -119,207 +137,179 @@ var ScrollZoomHandler = /*#__PURE__*/function () {
119
137
  * // Speed up trackpad zoom
120
138
  * map.scrollZoom.setZoomRate(1/25);
121
139
  */
122
- _createClass(ScrollZoomHandler, [{
123
- key: "setZoomRate",
124
- value: function setZoomRate(zoomRate) {
125
- this.defaultZoomRate = zoomRate;
126
- }
140
+ setZoomRate(zoomRate) {
141
+ this.defaultZoomRate = zoomRate;
142
+ }
127
143
 
128
- /**
129
- * Set the zoom rate of a mouse wheel
130
- * @param {number} [wheelZoomRate=1/450] The rate used to scale mouse wheel movement to a zoom value.
131
- * @example
132
- * // Slow down zoom of mouse wheel
133
- * map.scrollZoom.setWheelZoomRate(1/600);
134
- */
135
- }, {
136
- key: "setWheelZoomRate",
137
- value: function setWheelZoomRate(zoomRate) {
138
- this.wheelZoomRate = zoomRate;
139
- }
144
+ /**
145
+ * Set the zoom rate of a mouse wheel
146
+ * @param {number} [wheelZoomRate=1/450] The rate used to scale mouse wheel movement to a zoom value.
147
+ * @example
148
+ * // Slow down zoom of mouse wheel
149
+ * map.scrollZoom.setWheelZoomRate(1/600);
150
+ */
151
+ setWheelZoomRate(zoomRate) {
152
+ this.wheelZoomRate = zoomRate;
153
+ }
140
154
 
141
- /**
142
- * Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
143
- *
144
- * @returns {boolean} `true` if the "scroll to zoom" interaction is enabled.
145
- */
146
- }, {
147
- key: "isEnabled",
148
- value: function isEnabled() {
149
- return !!this.enabled;
150
- }
155
+ /**
156
+ * Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
157
+ *
158
+ * @returns {boolean} `true` if the "scroll to zoom" interaction is enabled.
159
+ */
160
+ isEnabled() {
161
+ return !!this.enabled;
162
+ }
151
163
 
152
- /*
153
- * Active state is turned on and off with every scroll wheel event and is set back to false before the map
154
- * render is called, so _active is not a good candidate for determining if a scroll zoom animation is in
155
- * progress.
156
- */
157
- }, {
158
- key: "isActive",
159
- value: function isActive() {
160
- return !!this.active || this.finishTimeout !== undefined;
161
- }
162
- }, {
163
- key: "isZooming",
164
- value: function isZooming() {
165
- return !!this.zooming;
166
- }
164
+ /*
165
+ * Active state is turned on and off with every scroll wheel event and is set back to false before the map
166
+ * render is called, so _active is not a good candidate for determining if a scroll zoom animation is in
167
+ * progress.
168
+ */
169
+ isActive() {
170
+ return !!this.active || this.finishTimeout !== undefined;
171
+ }
172
+ isZooming() {
173
+ return !!this.zooming;
174
+ }
167
175
 
168
- /**
169
- * Enables the "scroll to zoom" interaction.
170
- *
171
- * @param {Object} [options] Options object.
172
- * @param {string} [options.around] If "center" is passed, map will zoom around center of map
173
- *
174
- * @example
175
- * map.scrollZoom.enable();
176
- * @example
177
- * map.scrollZoom.enable({ around: 'center' })
178
- */
179
- }, {
180
- key: "enable",
181
- value: function enable(options) {
182
- if (this.isEnabled()) {
183
- return;
184
- }
185
- this.enabled = true;
186
- this.aroundCenter = options && options.around === 'center';
176
+ /**
177
+ * Enables the "scroll to zoom" interaction.
178
+ *
179
+ * @param {Object} [options] Options object.
180
+ * @param {string} [options.around] If "center" is passed, map will zoom around center of map
181
+ *
182
+ * @example
183
+ * map.scrollZoom.enable();
184
+ * @example
185
+ * map.scrollZoom.enable({ around: 'center' })
186
+ */
187
+ enable(options) {
188
+ if (this.isEnabled()) {
189
+ return;
187
190
  }
191
+ this.enabled = true;
192
+ this.aroundCenter = options && options.around === 'center';
193
+ }
188
194
 
189
- /**
190
- * Disables the "scroll to zoom" interaction.
191
- *
192
- * @example
193
- * map.scrollZoom.disable();
194
- */
195
- }, {
196
- key: "disable",
197
- value: function disable() {
198
- if (!this.isEnabled()) {
199
- return;
200
- }
201
- this.enabled = false;
195
+ /**
196
+ * Disables the "scroll to zoom" interaction.
197
+ *
198
+ * @example
199
+ * map.scrollZoom.disable();
200
+ */
201
+ disable() {
202
+ if (!this.isEnabled()) {
203
+ return;
202
204
  }
203
- }, {
204
- key: "wheel",
205
- value: function wheel(e) {
206
- if (!this.isEnabled()) {
207
- return;
208
- }
209
- // Remove `any` cast when https://github.com/facebook/flow/issues/4879 is fixed.
210
- var value = e.deltaMode === window.WheelEvent.DOM_DELTA_LINE ? e.deltaY * 40 : e.deltaY;
211
- var nowTime = now();
212
- var timeDelta = nowTime - (this.lastWheelEventTime || 0);
213
- this.lastWheelEventTime = nowTime;
214
- if (value !== 0 && value % wheelZoomDelta === 0) {
215
- // This one is definitely a mouse wheel event.
216
- this.type = 'wheel';
217
- } else if (value !== 0 && Math.abs(value) < 4) {
218
- // This one is definitely a trackpad event because it is so small.
219
- this.type = 'trackpad';
220
- } else if (timeDelta > 400) {
221
- // This is likely a new scroll action.
222
- this.type = null;
223
- this.lastValue = value;
205
+ this.enabled = false;
206
+ }
207
+ wheel(e) {
208
+ if (!this.isEnabled()) {
209
+ return;
210
+ }
211
+ // Remove `any` cast when https://github.com/facebook/flow/issues/4879 is fixed.
212
+ let value = e.deltaMode === window.WheelEvent.DOM_DELTA_LINE ? e.deltaY * 40 : e.deltaY;
213
+ const nowTime = now();
214
+ const timeDelta = nowTime - (this.lastWheelEventTime || 0);
215
+ this.lastWheelEventTime = nowTime;
216
+ if (value !== 0 && value % wheelZoomDelta === 0) {
217
+ // This one is definitely a mouse wheel event.
218
+ this.type = 'wheel';
219
+ } else if (value !== 0 && Math.abs(value) < 4) {
220
+ // This one is definitely a trackpad event because it is so small.
221
+ this.type = 'trackpad';
222
+ } else if (timeDelta > 400) {
223
+ // This is likely a new scroll action.
224
+ this.type = null;
225
+ this.lastValue = value;
224
226
 
225
- // Start a timeout in case this was a singular event, and dely it by up to 40ms.
226
- // @ts-ignore
227
- this.timeout = setTimeout(this.onTimeout, 40, e);
228
- } else if (!this.type) {
229
- // This is a repeating event, but we don't know the type of event just yet.
230
- // If the delta per time is small, we assume it's a fast trackpad; otherwise we switch into wheel mode.
231
- this.type = Math.abs(timeDelta * value) < 200 ? 'trackpad' : 'wheel';
227
+ // Start a timeout in case this was a singular event, and dely it by up to 40ms.
228
+ // @ts-ignore
229
+ this.timeout = setTimeout(this.onTimeout, 40, e);
230
+ } else if (!this.type) {
231
+ // This is a repeating event, but we don't know the type of event just yet.
232
+ // If the delta per time is small, we assume it's a fast trackpad; otherwise we switch into wheel mode.
233
+ this.type = Math.abs(timeDelta * value) < 200 ? 'trackpad' : 'wheel';
232
234
 
233
- // Make sure our delayed event isn't fired again, because we accumulate
234
- // the previous event (which was less than 40ms ago) into this event.
235
- if (this.timeout) {
236
- clearTimeout(this.timeout);
237
- this.timeout = null;
238
- value += this.lastValue;
239
- }
235
+ // Make sure our delayed event isn't fired again, because we accumulate
236
+ // the previous event (which was less than 40ms ago) into this event.
237
+ if (this.timeout) {
238
+ clearTimeout(this.timeout);
239
+ this.timeout = null;
240
+ value += this.lastValue;
240
241
  }
242
+ }
241
243
 
242
- // Slow down zoom if shift key is held for more precise zooming
243
- if (e.shiftKey && value) {
244
- value = value / 4;
245
- }
246
- // Only fire the callback if we actually know what type of scrolling device the user uses.
247
- if (this.type) {
248
- this.lastWheelEvent = e;
249
- this.delta -= value;
250
- if (!this.active) {
251
- this.start(e);
252
- }
244
+ // Slow down zoom if shift key is held for more precise zooming
245
+ if (e.shiftKey && value) {
246
+ value = value / 4;
247
+ }
248
+ // Only fire the callback if we actually know what type of scrolling device the user uses.
249
+ if (this.type) {
250
+ this.lastWheelEvent = e;
251
+ this.delta -= value;
252
+ if (!this.active) {
253
+ this.start(e);
253
254
  }
254
- e.preventDefault();
255
255
  }
256
- }, {
257
- key: "renderFrame",
258
- value: function renderFrame() {
259
- return this.onScrollFrame();
256
+ e.preventDefault();
257
+ }
258
+ renderFrame() {
259
+ return this.onScrollFrame();
260
+ }
261
+ reset() {
262
+ this.active = false;
263
+ }
264
+ onTimeout(initialEvent) {
265
+ this.type = 'wheel';
266
+ this.delta -= this.lastValue;
267
+ if (!this.active && this.start) {
268
+ this.start(initialEvent);
260
269
  }
261
- }, {
262
- key: "reset",
263
- value: function reset() {
264
- this.active = false;
270
+ }
271
+ start(e) {
272
+ if (!this.delta) {
273
+ return;
265
274
  }
266
- }, {
267
- key: "onTimeout",
268
- value: function onTimeout(initialEvent) {
269
- this.type = 'wheel';
270
- this.delta -= this.lastValue;
271
- if (!this.active && this.start) {
272
- this.start(initialEvent);
273
- }
275
+ if (this.frameId) {
276
+ this.frameId = null;
274
277
  }
275
- }, {
276
- key: "start",
277
- value: function start(e) {
278
- if (!this.delta) {
279
- return;
280
- }
281
- if (this.frameId) {
282
- this.frameId = null;
283
- }
284
- this.active = true;
285
- if (!this.isZooming()) {
286
- this.zooming = true;
287
- }
288
- if (this.finishTimeout) {
289
- clearTimeout(this.finishTimeout);
290
- // @ts-ignore
291
- delete this.finishTimeout;
292
- }
293
- var pos = DOM.mousePos(this.el, e);
294
- this.around = LngLat.convert(this.aroundCenter ? this.map.getCenter() : this.map.unproject(pos));
295
- this.aroundPoint = this.map.transform.locationPoint(this.around);
296
- if (!this.frameId) {
297
- this.frameId = true;
298
- this.handler.triggerRenderFrame();
299
- }
278
+ this.active = true;
279
+ if (!this.isZooming()) {
280
+ this.zooming = true;
281
+ }
282
+ if (this.finishTimeout) {
283
+ clearTimeout(this.finishTimeout);
284
+ // @ts-ignore
285
+ delete this.finishTimeout;
300
286
  }
301
- }, {
302
- key: "smoothOutEasing",
303
- value: function smoothOutEasing(duration) {
304
- var easing = ease;
305
- if (this.prevEase) {
306
- var preEase = this.prevEase;
307
- var t = (now() - preEase.start) / preEase.duration;
308
- var speed = preEase.easing(t + 0.01) - preEase.easing(t);
287
+ const pos = DOM.mousePos(this.el, e);
288
+ this.around = LngLat.convert(this.aroundCenter ? this.map.getCenter() : this.map.unproject(pos));
289
+ this.aroundPoint = this.map.transform.locationPoint(this.around);
290
+ if (!this.frameId) {
291
+ this.frameId = true;
292
+ this.handler.triggerRenderFrame();
293
+ }
294
+ }
295
+ smoothOutEasing(duration) {
296
+ let easing = ease;
297
+ if (this.prevEase) {
298
+ const preEase = this.prevEase;
299
+ const t = (now() - preEase.start) / preEase.duration;
300
+ const speed = preEase.easing(t + 0.01) - preEase.easing(t);
309
301
 
310
- // Quick hack to make new bezier that is continuous with last
311
- var x = 0.27 / Math.sqrt(speed * speed + 0.0001) * 0.01;
312
- var y = Math.sqrt(0.27 * 0.27 - x * x);
313
- easing = bezier(x, y, 0.25, 1);
314
- }
315
- this.prevEase = {
316
- start: now(),
317
- duration: duration,
318
- easing: easing
319
- };
320
- return easing;
302
+ // Quick hack to make new bezier that is continuous with last
303
+ const x = 0.27 / Math.sqrt(speed * speed + 0.0001) * 0.01;
304
+ const y = Math.sqrt(0.27 * 0.27 - x * x);
305
+ easing = bezier(x, y, 0.25, 1);
321
306
  }
322
- }]);
323
- return ScrollZoomHandler;
324
- }();
307
+ this.prevEase = {
308
+ start: now(),
309
+ duration,
310
+ easing
311
+ };
312
+ return easing;
313
+ }
314
+ }
325
315
  export default ScrollZoomHandler;
@@ -1,15 +1,15 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
2
  /**
4
3
  * The `DoubleClickZoomHandler` allows the user to zoom the map at a point by
5
4
  * double clicking or double tapping.
6
5
  */
7
- var DoubleClickZoomHandler = /*#__PURE__*/function () {
6
+ export default class DoubleClickZoomHandler {
8
7
  /**
9
8
  * @private
10
9
  */
11
- function DoubleClickZoomHandler(clickZoom, TapZoom) {
12
- _classCallCheck(this, DoubleClickZoomHandler);
10
+ constructor(clickZoom, TapZoom) {
11
+ _defineProperty(this, "clickZoom", void 0);
12
+ _defineProperty(this, "tapZoom", void 0);
13
13
  this.clickZoom = clickZoom;
14
14
  this.tapZoom = TapZoom;
15
15
  }
@@ -20,48 +20,37 @@ var DoubleClickZoomHandler = /*#__PURE__*/function () {
20
20
  * @example
21
21
  * map.doubleClickZoom.enable();
22
22
  */
23
- _createClass(DoubleClickZoomHandler, [{
24
- key: "enable",
25
- value: function enable() {
26
- this.clickZoom.enable();
27
- this.tapZoom.enable();
28
- }
23
+ enable() {
24
+ this.clickZoom.enable();
25
+ this.tapZoom.enable();
26
+ }
29
27
 
30
- /**
31
- * Disables the "double click to zoom" interaction.
32
- *
33
- * @example
34
- * map.doubleClickZoom.disable();
35
- */
36
- }, {
37
- key: "disable",
38
- value: function disable() {
39
- this.clickZoom.disable();
40
- this.tapZoom.disable();
41
- }
28
+ /**
29
+ * Disables the "double click to zoom" interaction.
30
+ *
31
+ * @example
32
+ * map.doubleClickZoom.disable();
33
+ */
34
+ disable() {
35
+ this.clickZoom.disable();
36
+ this.tapZoom.disable();
37
+ }
42
38
 
43
- /**
44
- * Returns a Boolean indicating whether the "double click to zoom" interaction is enabled.
45
- *
46
- * @returns {boolean} `true` if the "double click to zoom" interaction is enabled.
47
- */
48
- }, {
49
- key: "isEnabled",
50
- value: function isEnabled() {
51
- return this.clickZoom.isEnabled() && this.tapZoom.isEnabled();
52
- }
39
+ /**
40
+ * Returns a Boolean indicating whether the "double click to zoom" interaction is enabled.
41
+ *
42
+ * @returns {boolean} `true` if the "double click to zoom" interaction is enabled.
43
+ */
44
+ isEnabled() {
45
+ return this.clickZoom.isEnabled() && this.tapZoom.isEnabled();
46
+ }
53
47
 
54
- /**
55
- * Returns a Boolean indicating whether the "double click to zoom" interaction is active, i.e. currently being used.
56
- *
57
- * @returns {boolean} `true` if the "double click to zoom" interaction is active.
58
- */
59
- }, {
60
- key: "isActive",
61
- value: function isActive() {
62
- return this.clickZoom.isActive() || this.tapZoom.isActive();
63
- }
64
- }]);
65
- return DoubleClickZoomHandler;
66
- }();
67
- export { DoubleClickZoomHandler as default };
48
+ /**
49
+ * Returns a Boolean indicating whether the "double click to zoom" interaction is active, i.e. currently being used.
50
+ *
51
+ * @returns {boolean} `true` if the "double click to zoom" interaction is active.
52
+ */
53
+ isActive() {
54
+ return this.clickZoom.isActive() || this.tapZoom.isActive();
55
+ }
56
+ }