@antv/l7-map 2.25.7 → 2.25.10

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 (159) hide show
  1. package/es/index.d.ts +5 -0
  2. package/es/index.js +4 -0
  3. package/es/map/camera.d.ts +690 -0
  4. package/es/map/camera.js +1138 -0
  5. package/es/map/css/l7.css +171 -0
  6. package/es/map/events.d.ts +384 -0
  7. package/es/map/events.js +231 -0
  8. package/es/map/geo/edge_insets.d.ts +97 -0
  9. package/es/map/geo/edge_insets.js +115 -0
  10. package/es/map/geo/lng_lat.d.ts +116 -0
  11. package/es/map/geo/lng_lat.js +159 -0
  12. package/es/map/geo/lng_lat_bounds.d.ts +217 -0
  13. package/es/map/geo/lng_lat_bounds.js +334 -0
  14. package/es/map/geo/mercator_coordinate.d.ts +113 -0
  15. package/es/map/geo/mercator_coordinate.js +142 -0
  16. package/es/map/geo/transform.d.ts +262 -0
  17. package/es/map/geo/transform.js +736 -0
  18. package/es/map/handler/box_zoom.d.ts +65 -0
  19. package/es/map/handler/box_zoom.js +145 -0
  20. package/es/map/handler/click_zoom.d.ts +24 -0
  21. package/es/map/handler/click_zoom.js +47 -0
  22. package/es/map/handler/cooperative_gestures.d.ts +40 -0
  23. package/es/map/handler/cooperative_gestures.js +94 -0
  24. package/es/map/handler/drag_handler.d.ts +88 -0
  25. package/es/map/handler/drag_handler.js +89 -0
  26. package/es/map/handler/drag_move_state_manager.d.ts +30 -0
  27. package/es/map/handler/drag_move_state_manager.js +94 -0
  28. package/es/map/handler/handler_util.d.ts +3 -0
  29. package/es/map/handler/handler_util.js +8 -0
  30. package/es/map/handler/keyboard.d.ts +88 -0
  31. package/es/map/handler/keyboard.js +197 -0
  32. package/es/map/handler/map_event.d.ts +46 -0
  33. package/es/map/handler/map_event.js +131 -0
  34. package/es/map/handler/mouse.d.ts +30 -0
  35. package/es/map/handler/mouse.js +85 -0
  36. package/es/map/handler/one_finger_touch_drag.d.ts +15 -0
  37. package/es/map/handler/one_finger_touch_drag.js +39 -0
  38. package/es/map/handler/scroll_zoom.d.ts +102 -0
  39. package/es/map/handler/scroll_zoom.js +312 -0
  40. package/es/map/handler/shim/dblclick_zoom.d.ts +44 -0
  41. package/es/map/handler/shim/dblclick_zoom.js +60 -0
  42. package/es/map/handler/shim/drag_pan.d.ts +79 -0
  43. package/es/map/handler/shim/drag_pan.js +77 -0
  44. package/es/map/handler/shim/drag_rotate.d.ts +54 -0
  45. package/es/map/handler/shim/drag_rotate.js +66 -0
  46. package/es/map/handler/shim/two_fingers_touch.d.ts +74 -0
  47. package/es/map/handler/shim/two_fingers_touch.js +106 -0
  48. package/es/map/handler/tap_drag_zoom.d.ts +28 -0
  49. package/es/map/handler/tap_drag_zoom.js +92 -0
  50. package/es/map/handler/tap_recognizer.d.ts +35 -0
  51. package/es/map/handler/tap_recognizer.js +107 -0
  52. package/es/map/handler/tap_zoom.d.ts +28 -0
  53. package/es/map/handler/tap_zoom.js +87 -0
  54. package/es/map/handler/touch_pan.d.ts +40 -0
  55. package/es/map/handler/touch_pan.js +85 -0
  56. package/es/map/handler/transform-provider.d.ts +23 -0
  57. package/es/map/handler/transform-provider.js +35 -0
  58. package/es/map/handler/two_fingers_touch.d.ts +107 -0
  59. package/es/map/handler/two_fingers_touch.js +289 -0
  60. package/es/map/handler_inertia.d.ts +20 -0
  61. package/es/map/handler_inertia.js +128 -0
  62. package/es/map/handler_manager.d.ts +154 -0
  63. package/es/map/handler_manager.js +466 -0
  64. package/es/map/map.d.ts +637 -0
  65. package/es/map/map.js +984 -0
  66. package/es/map/util/abort_error.d.ts +15 -0
  67. package/es/map/util/abort_error.js +21 -0
  68. package/es/map/util/browser.d.ts +10 -0
  69. package/es/map/util/browser.js +30 -0
  70. package/es/map/util/dom.d.ts +30 -0
  71. package/es/map/util/dom.js +105 -0
  72. package/es/map/util/evented.d.ts +75 -0
  73. package/es/map/util/evented.js +158 -0
  74. package/es/map/util/simpleMapCoord.d.ts +31 -0
  75. package/es/map/util/simpleMapCoord.js +54 -0
  76. package/es/map/util/task_queue.d.ts +18 -0
  77. package/es/map/util/task_queue.js +54 -0
  78. package/es/map/util/util.d.ts +104 -0
  79. package/es/map/util/util.js +155 -0
  80. package/lib/index.d.ts +5 -0
  81. package/lib/index.js +33 -0
  82. package/lib/map/camera.d.ts +690 -0
  83. package/lib/map/camera.js +1145 -0
  84. package/lib/map/css/l7.css +171 -0
  85. package/lib/map/events.d.ts +384 -0
  86. package/lib/map/events.js +240 -0
  87. package/lib/map/geo/edge_insets.d.ts +97 -0
  88. package/lib/map/geo/edge_insets.js +122 -0
  89. package/lib/map/geo/lng_lat.d.ts +116 -0
  90. package/lib/map/geo/lng_lat.js +166 -0
  91. package/lib/map/geo/lng_lat_bounds.d.ts +217 -0
  92. package/lib/map/geo/lng_lat_bounds.js +341 -0
  93. package/lib/map/geo/mercator_coordinate.d.ts +113 -0
  94. package/lib/map/geo/mercator_coordinate.js +157 -0
  95. package/lib/map/geo/transform.d.ts +262 -0
  96. package/lib/map/geo/transform.js +744 -0
  97. package/lib/map/handler/box_zoom.d.ts +65 -0
  98. package/lib/map/handler/box_zoom.js +153 -0
  99. package/lib/map/handler/click_zoom.d.ts +24 -0
  100. package/lib/map/handler/click_zoom.js +54 -0
  101. package/lib/map/handler/cooperative_gestures.d.ts +40 -0
  102. package/lib/map/handler/cooperative_gestures.js +101 -0
  103. package/lib/map/handler/drag_handler.d.ts +88 -0
  104. package/lib/map/handler/drag_handler.js +97 -0
  105. package/lib/map/handler/drag_move_state_manager.d.ts +30 -0
  106. package/lib/map/handler/drag_move_state_manager.js +103 -0
  107. package/lib/map/handler/handler_util.d.ts +3 -0
  108. package/lib/map/handler/handler_util.js +14 -0
  109. package/lib/map/handler/keyboard.d.ts +88 -0
  110. package/lib/map/handler/keyboard.js +205 -0
  111. package/lib/map/handler/map_event.d.ts +46 -0
  112. package/lib/map/handler/map_event.js +140 -0
  113. package/lib/map/handler/mouse.d.ts +30 -0
  114. package/lib/map/handler/mouse.js +93 -0
  115. package/lib/map/handler/one_finger_touch_drag.d.ts +15 -0
  116. package/lib/map/handler/one_finger_touch_drag.js +47 -0
  117. package/lib/map/handler/scroll_zoom.d.ts +102 -0
  118. package/lib/map/handler/scroll_zoom.js +320 -0
  119. package/lib/map/handler/shim/dblclick_zoom.d.ts +44 -0
  120. package/lib/map/handler/shim/dblclick_zoom.js +68 -0
  121. package/lib/map/handler/shim/drag_pan.d.ts +79 -0
  122. package/lib/map/handler/shim/drag_pan.js +85 -0
  123. package/lib/map/handler/shim/drag_rotate.d.ts +54 -0
  124. package/lib/map/handler/shim/drag_rotate.js +74 -0
  125. package/lib/map/handler/shim/two_fingers_touch.d.ts +74 -0
  126. package/lib/map/handler/shim/two_fingers_touch.js +114 -0
  127. package/lib/map/handler/tap_drag_zoom.d.ts +28 -0
  128. package/lib/map/handler/tap_drag_zoom.js +99 -0
  129. package/lib/map/handler/tap_recognizer.d.ts +35 -0
  130. package/lib/map/handler/tap_recognizer.js +116 -0
  131. package/lib/map/handler/tap_zoom.d.ts +28 -0
  132. package/lib/map/handler/tap_zoom.js +94 -0
  133. package/lib/map/handler/touch_pan.d.ts +40 -0
  134. package/lib/map/handler/touch_pan.js +92 -0
  135. package/lib/map/handler/transform-provider.d.ts +23 -0
  136. package/lib/map/handler/transform-provider.js +43 -0
  137. package/lib/map/handler/two_fingers_touch.d.ts +107 -0
  138. package/lib/map/handler/two_fingers_touch.js +296 -0
  139. package/lib/map/handler_inertia.d.ts +20 -0
  140. package/lib/map/handler_inertia.js +136 -0
  141. package/lib/map/handler_manager.d.ts +154 -0
  142. package/lib/map/handler_manager.js +474 -0
  143. package/lib/map/map.d.ts +637 -0
  144. package/lib/map/map.js +991 -0
  145. package/lib/map/util/abort_error.d.ts +15 -0
  146. package/lib/map/util/abort_error.js +29 -0
  147. package/lib/map/util/browser.d.ts +10 -0
  148. package/lib/map/util/browser.js +36 -0
  149. package/lib/map/util/dom.d.ts +30 -0
  150. package/lib/map/util/dom.js +113 -0
  151. package/lib/map/util/evented.d.ts +75 -0
  152. package/lib/map/util/evented.js +167 -0
  153. package/lib/map/util/simpleMapCoord.d.ts +31 -0
  154. package/lib/map/util/simpleMapCoord.js +62 -0
  155. package/lib/map/util/task_queue.d.ts +18 -0
  156. package/lib/map/util/task_queue.js +62 -0
  157. package/lib/map/util/util.d.ts +104 -0
  158. package/lib/map/util/util.js +171 -0
  159. package/package.json +2 -2
@@ -0,0 +1,65 @@
1
+ /// <reference types="mapbox__point-geometry" />
2
+ import { TransformProvider } from './transform-provider';
3
+ import type Point from '@mapbox/point-geometry';
4
+ import type { Handler } from '../handler_manager';
5
+ import type { Map } from '../map';
6
+ /**
7
+ * The `BoxZoomHandler` allows the user to zoom the map to fit within a bounding box.
8
+ * The bounding box is defined by clicking and holding `shift` while dragging the cursor.
9
+ *
10
+ * @group Handlers
11
+ */
12
+ export declare class BoxZoomHandler implements Handler {
13
+ _map: Map;
14
+ _tr: TransformProvider;
15
+ _el: HTMLElement;
16
+ _container: HTMLElement;
17
+ _enabled: boolean;
18
+ _active: boolean;
19
+ _startPos: Point;
20
+ _lastPos: Point;
21
+ _box: HTMLElement;
22
+ _clickTolerance: number;
23
+ /** @internal */
24
+ constructor(map: Map, options: {
25
+ clickTolerance: number;
26
+ });
27
+ /**
28
+ * Returns a Boolean indicating whether the "box zoom" interaction is enabled.
29
+ *
30
+ * @returns `true` if the "box zoom" interaction is enabled.
31
+ */
32
+ isEnabled(): boolean;
33
+ /**
34
+ * Returns a Boolean indicating whether the "box zoom" interaction is active, i.e. currently being used.
35
+ *
36
+ * @returns `true` if the "box zoom" interaction is active.
37
+ */
38
+ isActive(): boolean;
39
+ /**
40
+ * Enables the "box zoom" interaction.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * map.boxZoom.enable();
45
+ * ```
46
+ */
47
+ enable(): void;
48
+ /**
49
+ * Disables the "box zoom" interaction.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * map.boxZoom.disable();
54
+ * ```
55
+ */
56
+ disable(): void;
57
+ mousedown(e: MouseEvent, point: Point): void;
58
+ mousemoveWindow(e: MouseEvent, point: Point): void;
59
+ mouseupWindow(e: MouseEvent, point: Point): {
60
+ cameraAnimation: (map: any) => any;
61
+ };
62
+ keydown(e: KeyboardEvent): void;
63
+ reset(): void;
64
+ _fireEvent(type: string, e: any): Map;
65
+ }
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.BoxZoomHandler = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _dom = require("../util/dom");
10
+ var _evented = require("../util/evented");
11
+ var _transformProvider = require("./transform-provider");
12
+ /**
13
+ * The `BoxZoomHandler` allows the user to zoom the map to fit within a bounding box.
14
+ * The bounding box is defined by clicking and holding `shift` while dragging the cursor.
15
+ *
16
+ * @group Handlers
17
+ */
18
+ class BoxZoomHandler {
19
+ /** @internal */
20
+ constructor(map, options) {
21
+ (0, _defineProperty2.default)(this, "_map", void 0);
22
+ (0, _defineProperty2.default)(this, "_tr", void 0);
23
+ (0, _defineProperty2.default)(this, "_el", void 0);
24
+ (0, _defineProperty2.default)(this, "_container", void 0);
25
+ (0, _defineProperty2.default)(this, "_enabled", void 0);
26
+ (0, _defineProperty2.default)(this, "_active", void 0);
27
+ (0, _defineProperty2.default)(this, "_startPos", void 0);
28
+ (0, _defineProperty2.default)(this, "_lastPos", void 0);
29
+ (0, _defineProperty2.default)(this, "_box", void 0);
30
+ (0, _defineProperty2.default)(this, "_clickTolerance", void 0);
31
+ this._map = map;
32
+ this._tr = new _transformProvider.TransformProvider(map);
33
+ this._el = map.getCanvasContainer();
34
+ this._container = map.getContainer();
35
+ this._clickTolerance = options.clickTolerance || 1;
36
+ }
37
+
38
+ /**
39
+ * Returns a Boolean indicating whether the "box zoom" interaction is enabled.
40
+ *
41
+ * @returns `true` if the "box zoom" interaction is enabled.
42
+ */
43
+ isEnabled() {
44
+ return !!this._enabled;
45
+ }
46
+
47
+ /**
48
+ * Returns a Boolean indicating whether the "box zoom" interaction is active, i.e. currently being used.
49
+ *
50
+ * @returns `true` if the "box zoom" interaction is active.
51
+ */
52
+ isActive() {
53
+ return !!this._active;
54
+ }
55
+
56
+ /**
57
+ * Enables the "box zoom" interaction.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * map.boxZoom.enable();
62
+ * ```
63
+ */
64
+ enable() {
65
+ if (this.isEnabled()) return;
66
+ this._enabled = true;
67
+ }
68
+
69
+ /**
70
+ * Disables the "box zoom" interaction.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * map.boxZoom.disable();
75
+ * ```
76
+ */
77
+ disable() {
78
+ if (!this.isEnabled()) return;
79
+ this._enabled = false;
80
+ }
81
+ mousedown(e, point) {
82
+ if (!this.isEnabled()) return;
83
+ if (!(e.shiftKey && e.button === 0)) return;
84
+ _dom.DOM.disableDrag();
85
+ this._startPos = this._lastPos = point;
86
+ this._active = true;
87
+ }
88
+ mousemoveWindow(e, point) {
89
+ if (!this._active) return;
90
+ const pos = point;
91
+ if (this._lastPos.equals(pos) || !this._box && pos.dist(this._startPos) < this._clickTolerance) {
92
+ return;
93
+ }
94
+ const p0 = this._startPos;
95
+ this._lastPos = pos;
96
+ if (!this._box) {
97
+ this._box = _dom.DOM.create('div', 'l7-boxzoom', this._container);
98
+ this._container.classList.add('l7-crosshair');
99
+ this._fireEvent('boxzoomstart', e);
100
+ }
101
+ const minX = Math.min(p0.x, pos.x),
102
+ maxX = Math.max(p0.x, pos.x),
103
+ minY = Math.min(p0.y, pos.y),
104
+ maxY = Math.max(p0.y, pos.y);
105
+ _dom.DOM.setTransform(this._box, `translate(${minX}px,${minY}px)`);
106
+ this._box.style.width = `${maxX - minX}px`;
107
+ this._box.style.height = `${maxY - minY}px`;
108
+ }
109
+ mouseupWindow(e, point) {
110
+ if (!this._active) return;
111
+ if (e.button !== 0) return;
112
+ const p0 = this._startPos,
113
+ p1 = point;
114
+ this.reset();
115
+ _dom.DOM.suppressClick();
116
+ if (p0.x === p1.x && p0.y === p1.y) {
117
+ this._fireEvent('boxzoomcancel', e);
118
+ } else {
119
+ this._map.fire(new _evented.Event('boxzoomend', {
120
+ originalEvent: e
121
+ }));
122
+ return {
123
+ cameraAnimation: map => map.fitScreenCoordinates(p0, p1, this._tr.bearing, {
124
+ linear: true
125
+ })
126
+ };
127
+ }
128
+ }
129
+ keydown(e) {
130
+ if (!this._active) return;
131
+ if (e.keyCode === 27) {
132
+ this.reset();
133
+ this._fireEvent('boxzoomcancel', e);
134
+ }
135
+ }
136
+ reset() {
137
+ this._active = false;
138
+ this._container.classList.remove('l7-crosshair');
139
+ if (this._box) {
140
+ _dom.DOM.remove(this._box);
141
+ this._box = null;
142
+ }
143
+ _dom.DOM.enableDrag();
144
+ delete this._startPos;
145
+ delete this._lastPos;
146
+ }
147
+ _fireEvent(type, e) {
148
+ return this._map.fire(new _evented.Event(type, {
149
+ originalEvent: e
150
+ }));
151
+ }
152
+ }
153
+ exports.BoxZoomHandler = BoxZoomHandler;
@@ -0,0 +1,24 @@
1
+ /// <reference types="mapbox__point-geometry" />
2
+ import type Point from '@mapbox/point-geometry';
3
+ import type { Handler } from '../handler_manager';
4
+ import type { Map } from '../map';
5
+ import { TransformProvider } from './transform-provider';
6
+ /**
7
+ * The `ClickZoomHandler` allows the user to zoom the map at a point by double clicking
8
+ * It is used by other handlers
9
+ */
10
+ export declare class ClickZoomHandler implements Handler {
11
+ _tr: TransformProvider;
12
+ _enabled: boolean;
13
+ _active: boolean;
14
+ /** @internal */
15
+ constructor(map: Map);
16
+ reset(): void;
17
+ dblclick(e: MouseEvent, point: Point): {
18
+ cameraAnimation: (map: Map) => void;
19
+ };
20
+ enable(): void;
21
+ disable(): void;
22
+ isEnabled(): boolean;
23
+ isActive(): boolean;
24
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ClickZoomHandler = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _transformProvider = require("./transform-provider");
10
+ /**
11
+ * The `ClickZoomHandler` allows the user to zoom the map at a point by double clicking
12
+ * It is used by other handlers
13
+ */
14
+ class ClickZoomHandler {
15
+ /** @internal */
16
+ constructor(map) {
17
+ (0, _defineProperty2.default)(this, "_tr", void 0);
18
+ (0, _defineProperty2.default)(this, "_enabled", void 0);
19
+ (0, _defineProperty2.default)(this, "_active", void 0);
20
+ this._tr = new _transformProvider.TransformProvider(map);
21
+ this.reset();
22
+ }
23
+ reset() {
24
+ this._active = false;
25
+ }
26
+ dblclick(e, point) {
27
+ e.preventDefault();
28
+ return {
29
+ cameraAnimation: map => {
30
+ map.easeTo({
31
+ duration: 300,
32
+ zoom: this._tr.zoom + (e.shiftKey ? -1 : 1),
33
+ around: this._tr.unproject(point)
34
+ }, {
35
+ originalEvent: e
36
+ });
37
+ }
38
+ };
39
+ }
40
+ enable() {
41
+ this._enabled = true;
42
+ }
43
+ disable() {
44
+ this._enabled = false;
45
+ this.reset();
46
+ }
47
+ isEnabled() {
48
+ return this._enabled;
49
+ }
50
+ isActive() {
51
+ return this._active;
52
+ }
53
+ }
54
+ exports.ClickZoomHandler = ClickZoomHandler;
@@ -0,0 +1,40 @@
1
+ import type { Handler } from '../handler_manager';
2
+ import type { Map } from '../map';
3
+ /**
4
+ * The {@link CooperativeGesturesHandler} options object for the gesture settings
5
+ */
6
+ export type GestureOptions = boolean;
7
+ /**
8
+ * A `CooperativeGestureHandler` is a control that adds cooperative gesture info when user tries to zoom in/out.
9
+ *
10
+ * @group Handlers
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const map = new Map({
15
+ * cooperativeGestures: true
16
+ * });
17
+ * ```
18
+ * @see [Example: cooperative gestures](https://maplibre.org/maplibre-gl-js-docs/example/cooperative-gestures/)
19
+ **/
20
+ export declare class CooperativeGesturesHandler implements Handler {
21
+ _options: GestureOptions;
22
+ _map: Map;
23
+ _container: HTMLElement;
24
+ /**
25
+ * This is the key that will allow to bypass the cooperative gesture protection
26
+ */
27
+ _bypassKey: 'metaKey' | 'ctrlKey';
28
+ _enabled: boolean;
29
+ constructor(map: Map, options: GestureOptions);
30
+ isActive(): boolean;
31
+ reset(): void;
32
+ _setupUI(): void;
33
+ _destoryUI(): void;
34
+ enable(): void;
35
+ disable(): void;
36
+ isEnabled(): boolean;
37
+ touchmove(e: TouchEvent): void;
38
+ wheel(e: WheelEvent): void;
39
+ _onCooperativeGesture(showNotification: boolean): void;
40
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CooperativeGesturesHandler = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _dom = require("../util/dom");
10
+ /**
11
+ * The {@link CooperativeGesturesHandler} options object for the gesture settings
12
+ */
13
+
14
+ /**
15
+ * A `CooperativeGestureHandler` is a control that adds cooperative gesture info when user tries to zoom in/out.
16
+ *
17
+ * @group Handlers
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const map = new Map({
22
+ * cooperativeGestures: true
23
+ * });
24
+ * ```
25
+ * @see [Example: cooperative gestures](https://maplibre.org/maplibre-gl-js-docs/example/cooperative-gestures/)
26
+ **/
27
+ class CooperativeGesturesHandler {
28
+ constructor(map, options) {
29
+ (0, _defineProperty2.default)(this, "_options", void 0);
30
+ (0, _defineProperty2.default)(this, "_map", void 0);
31
+ (0, _defineProperty2.default)(this, "_container", void 0);
32
+ /**
33
+ * This is the key that will allow to bypass the cooperative gesture protection
34
+ */
35
+ (0, _defineProperty2.default)(this, "_bypassKey", navigator.userAgent.indexOf('Mac') !== -1 ? 'metaKey' : 'ctrlKey');
36
+ (0, _defineProperty2.default)(this, "_enabled", void 0);
37
+ this._map = map;
38
+ this._options = options;
39
+ this._enabled = false;
40
+ }
41
+ isActive() {
42
+ return false;
43
+ }
44
+ reset() {}
45
+ _setupUI() {
46
+ if (this._container) return;
47
+ const mapCanvasContainer = this._map.getCanvasContainer();
48
+ // Add a cooperative gestures class (enable touch-action: pan-x pan-y;)
49
+ mapCanvasContainer.classList.add('l7-cooperative-gestures');
50
+ this._container = _dom.DOM.create('div', 'l7-cooperative-gesture-screen', mapCanvasContainer);
51
+ // Create and append the desktop message div
52
+ const desktopDiv = document.createElement('div');
53
+ desktopDiv.className = 'l7-desktop-message';
54
+ desktopDiv.textContent = 'Missing UI string';
55
+ this._container.appendChild(desktopDiv);
56
+ // Create and append the mobile message div
57
+ const mobileDiv = document.createElement('div');
58
+ mobileDiv.className = 'l7-mobile-message';
59
+ mobileDiv.textContent = 'Missing UI string';
60
+ this._container.appendChild(mobileDiv);
61
+ // Remove cooperative gesture screen from the accessibility tree since screenreaders cannot interact with the map using gestures
62
+ this._container.setAttribute('aria-hidden', 'true');
63
+ }
64
+ _destoryUI() {
65
+ if (this._container) {
66
+ _dom.DOM.remove(this._container);
67
+ const mapCanvasContainer = this._map.getCanvasContainer();
68
+ mapCanvasContainer.classList.remove('l7-cooperative-gestures');
69
+ }
70
+ delete this._container;
71
+ }
72
+ enable() {
73
+ this._setupUI();
74
+ this._enabled = true;
75
+ }
76
+ disable() {
77
+ this._enabled = false;
78
+ this._destoryUI();
79
+ }
80
+ isEnabled() {
81
+ return this._enabled;
82
+ }
83
+ touchmove(e) {
84
+ this._onCooperativeGesture(e.touches.length === 1);
85
+ }
86
+ wheel(e) {
87
+ if (!this._map.scrollZoom.isEnabled()) {
88
+ return;
89
+ }
90
+ this._onCooperativeGesture(!e[this._bypassKey]);
91
+ }
92
+ _onCooperativeGesture(showNotification) {
93
+ if (!this._enabled || !showNotification) return;
94
+ // Alert user how to scroll/pan
95
+ this._container.classList.add('l7-show');
96
+ setTimeout(() => {
97
+ this._container.classList.remove('l7-show');
98
+ }, 100);
99
+ }
100
+ }
101
+ exports.CooperativeGesturesHandler = CooperativeGesturesHandler;
@@ -0,0 +1,88 @@
1
+ /// <reference types="mapbox__point-geometry" />
2
+ import type Point from '@mapbox/point-geometry';
3
+ import type { Handler } from '../handler_manager';
4
+ import type { DragMoveStateManager } from './drag_move_state_manager';
5
+ interface DragMovementResult {
6
+ bearingDelta?: number;
7
+ pitchDelta?: number;
8
+ around?: Point;
9
+ panDelta?: Point;
10
+ }
11
+ export interface DragPanResult extends DragMovementResult {
12
+ around: Point;
13
+ panDelta: Point;
14
+ }
15
+ export interface DragRotateResult extends DragMovementResult {
16
+ bearingDelta: number;
17
+ }
18
+ export interface DragPitchResult extends DragMovementResult {
19
+ pitchDelta: number;
20
+ }
21
+ type DragMoveFunction<T extends DragMovementResult> = (lastPoint: Point, point: Point) => T;
22
+ export interface DragMoveHandler<T extends DragMovementResult, E extends Event> extends Handler {
23
+ dragStart: (e: E, point: Point) => void;
24
+ dragMove: (e: E, point: Point) => T | void;
25
+ dragEnd: (e: E) => void;
26
+ getClickTolerance: () => number;
27
+ }
28
+ export type DragMoveHandlerOptions<T, E extends Event> = {
29
+ /**
30
+ * If the movement is shorter than this value, consider it a click.
31
+ */
32
+ clickTolerance: number;
33
+ /**
34
+ * The move function to run on a valid movement.
35
+ */
36
+ move: DragMoveFunction<T>;
37
+ /**
38
+ * A class used to manage the state of the drag event - start, checking valid moves, end. See the class documentation for more details.
39
+ */
40
+ moveStateManager: DragMoveStateManager<E>;
41
+ /**
42
+ * A method used to assign the dragStart, dragMove, and dragEnd methods to the relevant event handlers, as well as assigning the contextmenu handler
43
+ * @param handler - the handler
44
+ */
45
+ assignEvents: (handler: DragMoveHandler<T, E>) => void;
46
+ /**
47
+ * Should the move start on the "start" event, or should it start on the first valid move.
48
+ */
49
+ activateOnStart?: boolean;
50
+ /**
51
+ * If true, handler will be enabled during construction
52
+ */
53
+ enable?: boolean;
54
+ };
55
+ /**
56
+ * A generic class to create handlers for drag events, from both mouse and touch events.
57
+ */
58
+ export declare class DragHandler<T extends DragMovementResult, E extends Event> implements DragMoveHandler<T, E> {
59
+ contextmenu?: Handler['contextmenu'];
60
+ mousedown?: Handler['mousedown'];
61
+ mousemoveWindow?: Handler['mousemoveWindow'];
62
+ mouseup?: Handler['mouseup'];
63
+ touchstart?: Handler['touchstart'];
64
+ touchmoveWindow?: Handler['touchmoveWindow'];
65
+ touchend?: Handler['touchend'];
66
+ _clickTolerance: number;
67
+ _moveFunction: DragMoveFunction<T>;
68
+ _activateOnStart: boolean;
69
+ _active: boolean;
70
+ _enabled: boolean;
71
+ _moved: boolean;
72
+ _lastPoint: Point | null;
73
+ _moveStateManager: DragMoveStateManager<E>;
74
+ constructor(options: DragMoveHandlerOptions<T, E>);
75
+ reset(e?: E): void;
76
+ _move(...params: Parameters<DragMoveFunction<T>>): T;
77
+ dragStart(e: E, point: Point): any;
78
+ dragStart(e: E, point: Point[]): any;
79
+ dragMove(e: E, point: Point): any;
80
+ dragMove(e: E, point: Point[]): any;
81
+ dragEnd(e: E): void;
82
+ enable(): void;
83
+ disable(): void;
84
+ isEnabled(): boolean;
85
+ isActive(): boolean;
86
+ getClickTolerance(): number;
87
+ }
88
+ export {};
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DragHandler = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _dom = require("../util/dom");
10
+ /**
11
+ * A generic class to create handlers for drag events, from both mouse and touch events.
12
+ */
13
+ class DragHandler {
14
+ constructor(options) {
15
+ // Event handlers that may be assigned by the implementations of this class
16
+ (0, _defineProperty2.default)(this, "contextmenu", void 0);
17
+ (0, _defineProperty2.default)(this, "mousedown", void 0);
18
+ (0, _defineProperty2.default)(this, "mousemoveWindow", void 0);
19
+ (0, _defineProperty2.default)(this, "mouseup", void 0);
20
+ (0, _defineProperty2.default)(this, "touchstart", void 0);
21
+ (0, _defineProperty2.default)(this, "touchmoveWindow", void 0);
22
+ (0, _defineProperty2.default)(this, "touchend", void 0);
23
+ (0, _defineProperty2.default)(this, "_clickTolerance", void 0);
24
+ (0, _defineProperty2.default)(this, "_moveFunction", void 0);
25
+ (0, _defineProperty2.default)(this, "_activateOnStart", void 0);
26
+ (0, _defineProperty2.default)(this, "_active", void 0);
27
+ (0, _defineProperty2.default)(this, "_enabled", void 0);
28
+ (0, _defineProperty2.default)(this, "_moved", void 0);
29
+ (0, _defineProperty2.default)(this, "_lastPoint", void 0);
30
+ (0, _defineProperty2.default)(this, "_moveStateManager", void 0);
31
+ this._enabled = !!options.enable;
32
+ this._moveStateManager = options.moveStateManager;
33
+ this._clickTolerance = options.clickTolerance || 1;
34
+ this._moveFunction = options.move;
35
+ this._activateOnStart = !!options.activateOnStart;
36
+ options.assignEvents(this);
37
+ this.reset();
38
+ }
39
+ reset(e) {
40
+ this._active = false;
41
+ this._moved = false;
42
+ delete this._lastPoint;
43
+ this._moveStateManager.endMove(e);
44
+ }
45
+ _move(...params) {
46
+ const move = this._moveFunction(...params);
47
+ if (move.bearingDelta || move.pitchDelta || move.around || move.panDelta) {
48
+ this._active = true;
49
+ return move;
50
+ }
51
+ }
52
+ dragStart(e, point) {
53
+ if (!this.isEnabled() || this._lastPoint) return;
54
+ if (!this._moveStateManager.isValidStartEvent(e)) return;
55
+ this._moveStateManager.startMove(e);
56
+ this._lastPoint = point['length'] ? point[0] : point;
57
+ if (this._activateOnStart && this._lastPoint) this._active = true;
58
+ }
59
+ dragMove(e, point) {
60
+ if (!this.isEnabled()) return;
61
+ const lastPoint = this._lastPoint;
62
+ if (!lastPoint) return;
63
+ e.preventDefault();
64
+ if (!this._moveStateManager.isValidMoveEvent(e)) {
65
+ this.reset(e);
66
+ return;
67
+ }
68
+ const movePoint = point['length'] ? point[0] : point;
69
+ if (!this._moved && movePoint.dist(lastPoint) < this._clickTolerance) return;
70
+ this._moved = true;
71
+ this._lastPoint = movePoint;
72
+ return this._move(lastPoint, movePoint);
73
+ }
74
+ dragEnd(e) {
75
+ if (!this.isEnabled() || !this._lastPoint) return;
76
+ if (!this._moveStateManager.isValidEndEvent(e)) return;
77
+ if (this._moved) _dom.DOM.suppressClick();
78
+ this.reset(e);
79
+ }
80
+ enable() {
81
+ this._enabled = true;
82
+ }
83
+ disable() {
84
+ this._enabled = false;
85
+ this.reset();
86
+ }
87
+ isEnabled() {
88
+ return this._enabled;
89
+ }
90
+ isActive() {
91
+ return this._active;
92
+ }
93
+ getClickTolerance() {
94
+ return this._clickTolerance;
95
+ }
96
+ }
97
+ exports.DragHandler = DragHandler;
@@ -0,0 +1,30 @@
1
+ export interface DragMoveStateManager<E extends Event> {
2
+ startMove: (e: E) => void;
3
+ endMove: (e?: E) => void;
4
+ isValidStartEvent: (e: E) => boolean;
5
+ isValidMoveEvent: (e: E) => boolean;
6
+ isValidEndEvent: (e?: E) => boolean;
7
+ }
8
+ export declare class MouseMoveStateManager implements DragMoveStateManager<MouseEvent> {
9
+ _eventButton: number | undefined;
10
+ _correctEvent: (e: MouseEvent) => boolean;
11
+ constructor(options: {
12
+ checkCorrectEvent: (e: MouseEvent) => boolean;
13
+ });
14
+ startMove(e: MouseEvent): void;
15
+ endMove(_e?: MouseEvent): void;
16
+ isValidStartEvent(e: MouseEvent): boolean;
17
+ isValidMoveEvent(e: MouseEvent): boolean;
18
+ isValidEndEvent(e: MouseEvent): boolean;
19
+ }
20
+ export declare class OneFingerTouchMoveStateManager implements DragMoveStateManager<TouchEvent> {
21
+ _firstTouch: number | undefined;
22
+ constructor();
23
+ _isOneFingerTouch(e: TouchEvent): boolean;
24
+ _isSameTouchEvent(e: TouchEvent): boolean;
25
+ startMove(e: TouchEvent): void;
26
+ endMove(_e?: TouchEvent): void;
27
+ isValidStartEvent(e: TouchEvent): boolean;
28
+ isValidMoveEvent(e: TouchEvent): boolean;
29
+ isValidEndEvent(e: TouchEvent): boolean;
30
+ }