@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,15 @@
1
+ /**
2
+ * An error message to use when an operation is aborted
3
+ */
4
+ export declare const ABORT_ERROR = "AbortError";
5
+ /**
6
+ * Check if an error is an abort error
7
+ * @param error - An error object
8
+ * @returns - true if the error is an abort error
9
+ */
10
+ export declare function isAbortError(error: Error): boolean;
11
+ /**
12
+ * Use this when you need to create an abort error.
13
+ * @returns An error object with the message "AbortError"
14
+ */
15
+ export declare function createAbortError(): Error;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * An error message to use when an operation is aborted
3
+ */
4
+ export const ABORT_ERROR = 'AbortError';
5
+
6
+ /**
7
+ * Check if an error is an abort error
8
+ * @param error - An error object
9
+ * @returns - true if the error is an abort error
10
+ */
11
+ export function isAbortError(error) {
12
+ return error.message === ABORT_ERROR;
13
+ }
14
+
15
+ /**
16
+ * Use this when you need to create an abort error.
17
+ * @returns An error object with the message "AbortError"
18
+ */
19
+ export function createAbortError() {
20
+ return new Error(ABORT_ERROR);
21
+ }
@@ -0,0 +1,10 @@
1
+ /** */
2
+ export declare const browser: {
3
+ /**
4
+ * Provides a function that outputs milliseconds: either performance.now()
5
+ * or a fallback to Date.now()
6
+ */
7
+ now: any;
8
+ frameAsync(abortController: AbortController): Promise<number>;
9
+ readonly prefersReducedMotion: boolean;
10
+ };
@@ -0,0 +1,30 @@
1
+ import { createAbortError } from "./abort_error";
2
+ const now = typeof performance !== 'undefined' && performance && performance.now ? performance.now.bind(performance) : Date.now.bind(Date);
3
+ let reducedMotionQuery;
4
+
5
+ /** */
6
+ export const browser = {
7
+ /**
8
+ * Provides a function that outputs milliseconds: either performance.now()
9
+ * or a fallback to Date.now()
10
+ */
11
+ now,
12
+ frameAsync(abortController) {
13
+ return new Promise((resolve, reject) => {
14
+ const frame = requestAnimationFrame(resolve);
15
+ abortController.signal.addEventListener('abort', () => {
16
+ cancelAnimationFrame(frame);
17
+ reject(createAbortError());
18
+ });
19
+ });
20
+ },
21
+ get prefersReducedMotion() {
22
+ // In case your test crashes when checking matchMedia, call setMatchMedia from 'src/util/test/util'
23
+ if (!window.matchMedia) return false;
24
+ //Lazily initialize media query
25
+ if (reducedMotionQuery == null) {
26
+ reducedMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
27
+ }
28
+ return reducedMotionQuery.matches;
29
+ }
30
+ };
@@ -0,0 +1,30 @@
1
+ /// <reference types="mapbox__point-geometry" />
2
+ import Point from '@mapbox/point-geometry';
3
+ export declare class DOM {
4
+ private static readonly docStyle;
5
+ private static userSelect;
6
+ private static selectProp;
7
+ private static transformProp;
8
+ private static testProp;
9
+ static create<K extends keyof HTMLElementTagNameMap>(tagName: K, className?: string, container?: HTMLElement): HTMLElementTagNameMap[K];
10
+ static createNS(namespaceURI: string, tagName: string): Element;
11
+ static disableDrag(): void;
12
+ static enableDrag(): void;
13
+ static setTransform(el: HTMLElement, value: string): void;
14
+ static addEventListener(target: HTMLElement | Window | Document, type: string, callback: EventListenerOrEventListenerObject, options?: {
15
+ passive?: boolean;
16
+ capture?: boolean;
17
+ }): void;
18
+ static removeEventListener(target: HTMLElement | Window | Document, type: string, callback: EventListenerOrEventListenerObject, options?: {
19
+ passive?: boolean;
20
+ capture?: boolean;
21
+ }): void;
22
+ private static suppressClickInternal;
23
+ static suppressClick(): void;
24
+ private static getScale;
25
+ private static getPoint;
26
+ static mousePos(el: HTMLElement, e: MouseEvent | Touch): Point;
27
+ static touchPos(el: HTMLElement, touches: TouchList): Point[];
28
+ static mouseButton(e: MouseEvent): number;
29
+ static remove(node: HTMLElement): void;
30
+ }
@@ -0,0 +1,105 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ var _class;
3
+ import Point from '@mapbox/point-geometry';
4
+ export class DOM {
5
+ static testProp(props) {
6
+ if (!DOM.docStyle) return props[0];
7
+ for (let i = 0; i < props.length; i++) {
8
+ if (props[i] in DOM.docStyle) {
9
+ return props[i];
10
+ }
11
+ }
12
+ return props[0];
13
+ }
14
+ static create(tagName, className, container) {
15
+ const el = window.document.createElement(tagName);
16
+ if (className !== undefined) el.className = className;
17
+ if (container) container.appendChild(el);
18
+ return el;
19
+ }
20
+ static createNS(namespaceURI, tagName) {
21
+ const el = window.document.createElementNS(namespaceURI, tagName);
22
+ return el;
23
+ }
24
+ static disableDrag() {
25
+ if (DOM.docStyle && DOM.selectProp) {
26
+ DOM.userSelect = DOM.docStyle[DOM.selectProp];
27
+ DOM.docStyle[DOM.selectProp] = 'none';
28
+ }
29
+ }
30
+ static enableDrag() {
31
+ if (DOM.docStyle && DOM.selectProp) {
32
+ DOM.docStyle[DOM.selectProp] = DOM.userSelect;
33
+ }
34
+ }
35
+ static setTransform(el, value) {
36
+ el.style[DOM.transformProp] = value;
37
+ }
38
+ static addEventListener(target, type, callback, options = {}) {
39
+ if ('passive' in options) {
40
+ target.addEventListener(type, callback, options);
41
+ } else {
42
+ target.addEventListener(type, callback, options.capture);
43
+ }
44
+ }
45
+ static removeEventListener(target, type, callback, options = {}) {
46
+ if ('passive' in options) {
47
+ target.removeEventListener(type, callback, options);
48
+ } else {
49
+ target.removeEventListener(type, callback, options.capture);
50
+ }
51
+ }
52
+
53
+ // Suppress the next click, but only if it's immediate.
54
+ static suppressClickInternal(e) {
55
+ e.preventDefault();
56
+ e.stopPropagation();
57
+ window.removeEventListener('click', DOM.suppressClickInternal, true);
58
+ }
59
+ static suppressClick() {
60
+ window.addEventListener('click', DOM.suppressClickInternal, true);
61
+ window.setTimeout(() => {
62
+ window.removeEventListener('click', DOM.suppressClickInternal, true);
63
+ }, 0);
64
+ }
65
+ static getScale(element) {
66
+ const rect = element.getBoundingClientRect();
67
+ return {
68
+ x: rect.width / element.offsetWidth || 1,
69
+ y: rect.height / element.offsetHeight || 1,
70
+ boundingClientRect: rect
71
+ };
72
+ }
73
+ static getPoint(el, scale, e) {
74
+ const rect = scale.boundingClientRect;
75
+ return new Point(
76
+ // rect.left/top values are in page scale (like clientX/Y),
77
+ // whereas clientLeft/Top (border width) values are the original values (before CSS scale applies).
78
+ (e.clientX - rect.left) / scale.x - el.clientLeft, (e.clientY - rect.top) / scale.y - el.clientTop);
79
+ }
80
+ static mousePos(el, e) {
81
+ const scale = DOM.getScale(el);
82
+ return DOM.getPoint(el, scale, e);
83
+ }
84
+ static touchPos(el, touches) {
85
+ const points = [];
86
+ const scale = DOM.getScale(el);
87
+ for (let i = 0; i < touches.length; i++) {
88
+ points.push(DOM.getPoint(el, scale, touches[i]));
89
+ }
90
+ return points;
91
+ }
92
+ static mouseButton(e) {
93
+ return e.button;
94
+ }
95
+ static remove(node) {
96
+ if (node.parentNode) {
97
+ node.parentNode.removeChild(node);
98
+ }
99
+ }
100
+ }
101
+ _class = DOM;
102
+ _defineProperty(DOM, "docStyle", typeof window !== 'undefined' && window.document && window.document.documentElement.style);
103
+ _defineProperty(DOM, "userSelect", void 0);
104
+ _defineProperty(DOM, "selectProp", _class.testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']));
105
+ _defineProperty(DOM, "transformProp", _class.testProp(['transform', 'WebkitTransform']));
@@ -0,0 +1,75 @@
1
+ /**
2
+ * A listener method used as a callback to events
3
+ */
4
+ export type Listener = (a: any) => any;
5
+ type Listeners = {
6
+ [_: string]: Array<Listener>;
7
+ };
8
+ /**
9
+ * The event class
10
+ */
11
+ export declare class Event {
12
+ readonly type: string;
13
+ constructor(type: string, data?: any);
14
+ }
15
+ interface ErrorLike {
16
+ message: string;
17
+ }
18
+ /**
19
+ * An error event
20
+ */
21
+ export declare class ErrorEvent extends Event {
22
+ error: ErrorLike;
23
+ constructor(error: ErrorLike, data?: any);
24
+ }
25
+ /**
26
+ * Methods mixed in to other classes for event capabilities.
27
+ *
28
+ * @group Event Related
29
+ */
30
+ export declare class Evented {
31
+ _listeners: Listeners;
32
+ _oneTimeListeners: Listeners;
33
+ _eventedParent: Evented;
34
+ _eventedParentData: any | (() => any);
35
+ /**
36
+ * Adds a listener to a specified event type.
37
+ *
38
+ * @param type - The event type to add a listen for.
39
+ * @param listener - The function to be called when the event is fired.
40
+ * The listener function is called with the data object passed to `fire`,
41
+ * extended with `target` and `type` properties.
42
+ */
43
+ on(type: string, listener: Listener): this;
44
+ /**
45
+ * Removes a previously registered event listener.
46
+ *
47
+ * @param type - The event type to remove listeners for.
48
+ * @param listener - The listener function to remove.
49
+ */
50
+ off(type: string, listener: Listener): this;
51
+ /**
52
+ * Adds a listener that will be called only once to a specified event type.
53
+ *
54
+ * The listener will be called first time the event fires after the listener is registered.
55
+ *
56
+ * @param type - The event type to listen for.
57
+ * @param listener - The function to be called when the event is fired the first time.
58
+ * @returns `this` or a promise if a listener is not provided
59
+ */
60
+ once(type: string, listener?: Listener): this | Promise<any>;
61
+ fire(event: Event | string, properties?: any): this;
62
+ emit(event: Event | string, properties?: any): this;
63
+ /**
64
+ * Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
65
+ *
66
+ * @param type - The event type
67
+ * @returns `true` if there is at least one registered listener for specified event type, `false` otherwise
68
+ */
69
+ listens(type: string): boolean;
70
+ /**
71
+ * Bubble all events fired by this instance of Evented to this parent instance of Evented.
72
+ */
73
+ setEventedParent(parent?: Evented | null, data?: any | (() => any)): this;
74
+ }
75
+ export {};
@@ -0,0 +1,158 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import { extend } from "./util";
3
+
4
+ /**
5
+ * A listener method used as a callback to events
6
+ */
7
+
8
+ function _addEventListener(type, listener, listenerList) {
9
+ const listenerExists = listenerList[type] && listenerList[type].indexOf(listener) !== -1;
10
+ if (!listenerExists) {
11
+ listenerList[type] = listenerList[type] || [];
12
+ listenerList[type].push(listener);
13
+ }
14
+ }
15
+ function _removeEventListener(type, listener, listenerList) {
16
+ if (listenerList && listenerList[type]) {
17
+ const index = listenerList[type].indexOf(listener);
18
+ if (index !== -1) {
19
+ listenerList[type].splice(index, 1);
20
+ }
21
+ }
22
+ }
23
+
24
+ /**
25
+ * The event class
26
+ */
27
+ export class Event {
28
+ constructor(type, data = {}) {
29
+ _defineProperty(this, "type", void 0);
30
+ extend(this, data);
31
+ this.type = type;
32
+ }
33
+ }
34
+ /**
35
+ * An error event
36
+ */
37
+ export class ErrorEvent extends Event {
38
+ constructor(error, data = {}) {
39
+ super('error', data);
40
+ _defineProperty(this, "error", void 0);
41
+ this.error = error;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Methods mixed in to other classes for event capabilities.
47
+ *
48
+ * @group Event Related
49
+ */
50
+ export class Evented {
51
+ constructor() {
52
+ _defineProperty(this, "_listeners", void 0);
53
+ _defineProperty(this, "_oneTimeListeners", void 0);
54
+ _defineProperty(this, "_eventedParent", void 0);
55
+ _defineProperty(this, "_eventedParentData", void 0);
56
+ }
57
+ /**
58
+ * Adds a listener to a specified event type.
59
+ *
60
+ * @param type - The event type to add a listen for.
61
+ * @param listener - The function to be called when the event is fired.
62
+ * The listener function is called with the data object passed to `fire`,
63
+ * extended with `target` and `type` properties.
64
+ */
65
+ on(type, listener) {
66
+ this._listeners = this._listeners || {};
67
+ _addEventListener(type, listener, this._listeners);
68
+ return this;
69
+ }
70
+
71
+ /**
72
+ * Removes a previously registered event listener.
73
+ *
74
+ * @param type - The event type to remove listeners for.
75
+ * @param listener - The listener function to remove.
76
+ */
77
+ off(type, listener) {
78
+ _removeEventListener(type, listener, this._listeners);
79
+ _removeEventListener(type, listener, this._oneTimeListeners);
80
+ return this;
81
+ }
82
+
83
+ /**
84
+ * Adds a listener that will be called only once to a specified event type.
85
+ *
86
+ * The listener will be called first time the event fires after the listener is registered.
87
+ *
88
+ * @param type - The event type to listen for.
89
+ * @param listener - The function to be called when the event is fired the first time.
90
+ * @returns `this` or a promise if a listener is not provided
91
+ */
92
+ once(type, listener) {
93
+ if (!listener) {
94
+ return new Promise(resolve => this.once(type, resolve));
95
+ }
96
+ this._oneTimeListeners = this._oneTimeListeners || {};
97
+ _addEventListener(type, listener, this._oneTimeListeners);
98
+ return this;
99
+ }
100
+ fire(event, properties) {
101
+ // Compatibility with (type: string, properties: Object) signature from previous versions.
102
+ // See https://github.com/mapbox/mapbox-gl-js/issues/6522,
103
+ // https://github.com/mapbox/mapbox-gl-draw/issues/766
104
+ if (typeof event === 'string') {
105
+ event = new Event(event, properties || {});
106
+ }
107
+ const type = event.type;
108
+ if (this.listens(type)) {
109
+ event.target = this;
110
+
111
+ // make sure adding or removing listeners inside other listeners won't cause an infinite loop
112
+ const listeners = this._listeners && this._listeners[type] ? this._listeners[type].slice() : [];
113
+ for (const listener of listeners) {
114
+ listener.call(this, event);
115
+ }
116
+ const oneTimeListeners = this._oneTimeListeners && this._oneTimeListeners[type] ? this._oneTimeListeners[type].slice() : [];
117
+ for (const listener of oneTimeListeners) {
118
+ _removeEventListener(type, listener, this._oneTimeListeners);
119
+ listener.call(this, event);
120
+ }
121
+ const parent = this._eventedParent;
122
+ if (parent) {
123
+ extend(event, typeof this._eventedParentData === 'function' ? this._eventedParentData() : this._eventedParentData);
124
+ parent.fire(event);
125
+ }
126
+
127
+ // To ensure that no error events are dropped, print them to the
128
+ // console if they have no listeners.
129
+ } else if (event instanceof ErrorEvent) {
130
+ console.error(event.error);
131
+ }
132
+ return this;
133
+ }
134
+ emit(event, properties) {
135
+ return this.fire(event, properties);
136
+ }
137
+
138
+ /**
139
+ * Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
140
+ *
141
+ * @param type - The event type
142
+ * @returns `true` if there is at least one registered listener for specified event type, `false` otherwise
143
+ */
144
+ listens(type) {
145
+ return this._listeners && this._listeners[type] && this._listeners[type].length > 0 || this._oneTimeListeners && this._oneTimeListeners[type] && this._oneTimeListeners[type].length > 0 || this._eventedParent && this._eventedParent.listens(type);
146
+ }
147
+
148
+ /**
149
+ * Bubble all events fired by this instance of Evented to this parent instance of Evented.
150
+ */
151
+ setEventedParent(parent, data) {
152
+ if (parent) {
153
+ this._eventedParent = parent;
154
+ }
155
+ this._eventedParentData = data;
156
+ return this;
157
+ }
158
+ }
@@ -0,0 +1,31 @@
1
+ export interface ISimpleMapCoord {
2
+ setSize(size: number): void;
3
+ getSize(): [number, number];
4
+ project(lnglat: [number, number]): [number, number];
5
+ unproject(xy: [number, number]): [number, number];
6
+ }
7
+ export declare class SimpleMapCoord implements ISimpleMapCoord {
8
+ private size;
9
+ constructor(size?: number);
10
+ setSize(size: number): void;
11
+ getSize(): [number, number];
12
+ /**
13
+ * coord
14
+ * ^ y (y > 0)
15
+ * |
16
+ * |
17
+ * |
18
+ * |(x = 0, y = 0)
19
+ * ---------------> x (x > 0)
20
+ */
21
+ /***
22
+ * lng: [-180, 180] 360
23
+ * lat: [-85.05112877980659, 85.05112877980659] 170.10225755961318
24
+ */
25
+ mercatorXfromLng(lng: number): number;
26
+ mercatorYfromLat(lat: number): number;
27
+ lngFromMercatorX(x: number): number;
28
+ latFromMercatorY(y: number): number;
29
+ project(lnglat: [number, number]): [number, number];
30
+ unproject(xy: [number, number]): [number, number];
31
+ }
@@ -0,0 +1,54 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ export class SimpleMapCoord {
3
+ constructor(size) {
4
+ _defineProperty(this, "size", 10000);
5
+ this.size = size ? size : 10000;
6
+ }
7
+ setSize(size) {
8
+ this.size = size;
9
+ }
10
+ getSize() {
11
+ return [this.size, this.size];
12
+ }
13
+
14
+ /**
15
+ * coord
16
+ * ^ y (y > 0)
17
+ * |
18
+ * |
19
+ * |
20
+ * |(x = 0, y = 0)
21
+ * ---------------> x (x > 0)
22
+ */
23
+
24
+ /***
25
+ * lng: [-180, 180] 360
26
+ * lat: [-85.05112877980659, 85.05112877980659] 170.10225755961318
27
+ */
28
+
29
+ mercatorXfromLng(lng) {
30
+ // (0 - 1) * this.size
31
+ return (180 + lng) / 360 * this.size;
32
+ }
33
+ mercatorYfromLat(lat) {
34
+ // (0 - 1) * this.size
35
+ return (1 - (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360))) / 360) * this.size;
36
+ }
37
+ lngFromMercatorX(x) {
38
+ return x / this.size * 360 - 180;
39
+ }
40
+ latFromMercatorY(y) {
41
+ const y2 = 180 - (1 - y / this.size) * 360;
42
+ return 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
43
+ }
44
+ project(lnglat) {
45
+ const x = this.mercatorXfromLng(lnglat[0]);
46
+ const y = this.mercatorYfromLat(lnglat[1]);
47
+ return [x, y];
48
+ }
49
+ unproject(xy) {
50
+ const lng = this.lngFromMercatorX(xy[0]);
51
+ const lat = this.latFromMercatorY(xy[1]);
52
+ return [lng, lat];
53
+ }
54
+ }
@@ -0,0 +1,18 @@
1
+ export type TaskID = number;
2
+ type Task = {
3
+ callback: (timeStamp: number) => void;
4
+ id: TaskID;
5
+ cancelled: boolean;
6
+ };
7
+ export declare class TaskQueue {
8
+ _queue: Array<Task>;
9
+ _id: TaskID;
10
+ _cleared: boolean;
11
+ _currentlyRunning: Array<Task> | false;
12
+ constructor();
13
+ add(callback: (timeStamp: number) => void): TaskID;
14
+ remove(id: TaskID): void;
15
+ run(timeStamp?: number): void;
16
+ clear(): void;
17
+ }
18
+ export {};
@@ -0,0 +1,54 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ export class TaskQueue {
3
+ constructor() {
4
+ _defineProperty(this, "_queue", void 0);
5
+ _defineProperty(this, "_id", void 0);
6
+ _defineProperty(this, "_cleared", void 0);
7
+ _defineProperty(this, "_currentlyRunning", void 0);
8
+ this._queue = [];
9
+ this._id = 0;
10
+ this._cleared = false;
11
+ this._currentlyRunning = false;
12
+ }
13
+ add(callback) {
14
+ const id = ++this._id;
15
+ const queue = this._queue;
16
+ queue.push({
17
+ callback,
18
+ id,
19
+ cancelled: false
20
+ });
21
+ return id;
22
+ }
23
+ remove(id) {
24
+ const running = this._currentlyRunning;
25
+ const queue = running ? this._queue.concat(running) : this._queue;
26
+ for (const task of queue) {
27
+ if (task.id === id) {
28
+ task.cancelled = true;
29
+ return;
30
+ }
31
+ }
32
+ }
33
+ run(timeStamp = 0) {
34
+ if (this._currentlyRunning) throw new Error('Attempting to run(), but is already running.');
35
+ const queue = this._currentlyRunning = this._queue;
36
+
37
+ // Tasks queued by callbacks in the current queue should be executed
38
+ // on the next run, not the current run.
39
+ this._queue = [];
40
+ for (const task of queue) {
41
+ if (task.cancelled) continue;
42
+ task.callback(timeStamp);
43
+ if (this._cleared) break;
44
+ }
45
+ this._cleared = false;
46
+ this._currentlyRunning = false;
47
+ }
48
+ clear() {
49
+ if (this._currentlyRunning) {
50
+ this._cleared = true;
51
+ }
52
+ this._queue = [];
53
+ }
54
+ }