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