@antv/l7-map 2.18.2 → 2.18.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 (168) hide show
  1. package/es/camera.d.ts +85 -0
  2. package/es/camera.js +718 -0
  3. package/es/css/l7.css +98 -0
  4. package/es/earthmap.d.ts +66 -0
  5. package/es/earthmap.js +369 -0
  6. package/es/geo/edge_insets.d.ts +54 -0
  7. package/es/geo/edge_insets.js +108 -0
  8. package/es/geo/lng_lat.d.ts +18 -0
  9. package/es/geo/lng_lat.js +73 -0
  10. package/es/geo/lng_lat_bounds.d.ts +24 -0
  11. package/es/geo/lng_lat_bounds.js +154 -0
  12. package/es/geo/mercator.d.ts +29 -0
  13. package/es/geo/mercator.js +84 -0
  14. package/es/geo/point.d.ts +40 -0
  15. package/es/geo/point.js +224 -0
  16. package/es/geo/simple.d.ts +29 -0
  17. package/es/geo/simple.js +87 -0
  18. package/es/geo/transform.d.ts +198 -0
  19. package/es/geo/transform.js +961 -0
  20. package/es/handler/IHandler.d.ts +34 -0
  21. package/es/handler/IHandler.js +1 -0
  22. package/es/handler/blockable_map_event.d.ts +17 -0
  23. package/es/handler/blockable_map_event.js +78 -0
  24. package/es/handler/box_zoom.d.ts +59 -0
  25. package/es/handler/box_zoom.js +180 -0
  26. package/es/handler/click_zoom.d.ts +16 -0
  27. package/es/handler/click_zoom.js +54 -0
  28. package/es/handler/events/event.d.ts +4 -0
  29. package/es/handler/events/event.js +11 -0
  30. package/es/handler/events/index.d.ts +4 -0
  31. package/es/handler/events/index.js +4 -0
  32. package/es/handler/events/map_mouse_event.d.ts +34 -0
  33. package/es/handler/events/map_mouse_event.js +64 -0
  34. package/es/handler/events/map_touch_event.d.ts +57 -0
  35. package/es/handler/events/map_touch_event.js +95 -0
  36. package/es/handler/events/map_wheel_event.d.ts +33 -0
  37. package/es/handler/events/map_wheel_event.js +50 -0
  38. package/es/handler/events/render_event.d.ts +5 -0
  39. package/es/handler/events/render_event.js +26 -0
  40. package/es/handler/handler_inertia.d.ts +23 -0
  41. package/es/handler/handler_inertia.js +157 -0
  42. package/es/handler/handler_manager.d.ts +61 -0
  43. package/es/handler/handler_manager.js +577 -0
  44. package/es/handler/handler_util.d.ts +4 -0
  45. package/es/handler/handler_util.js +9 -0
  46. package/es/handler/keyboard.d.ts +36 -0
  47. package/es/handler/keyboard.js +143 -0
  48. package/es/handler/map_event.d.ts +29 -0
  49. package/es/handler/map_event.js +125 -0
  50. package/es/handler/mouse/index.d.ts +4 -0
  51. package/es/handler/mouse/index.js +4 -0
  52. package/es/handler/mouse/mouse_handler.d.ts +22 -0
  53. package/es/handler/mouse/mouse_handler.js +118 -0
  54. package/es/handler/mouse/mousepan_handler.d.ts +10 -0
  55. package/es/handler/mouse/mousepan_handler.js +44 -0
  56. package/es/handler/mouse/mousepitch_hander.d.ts +9 -0
  57. package/es/handler/mouse/mousepitch_hander.js +46 -0
  58. package/es/handler/mouse/mouserotate_hander.d.ts +9 -0
  59. package/es/handler/mouse/mouserotate_hander.js +46 -0
  60. package/es/handler/mouse/util.d.ts +6 -0
  61. package/es/handler/mouse/util.js +11 -0
  62. package/es/handler/scroll_zoom.d.ts +93 -0
  63. package/es/handler/scroll_zoom.js +325 -0
  64. package/es/handler/shim/dblclick_zoom.d.ts +40 -0
  65. package/es/handler/shim/dblclick_zoom.js +67 -0
  66. package/es/handler/shim/drag_pan.d.ts +61 -0
  67. package/es/handler/shim/drag_pan.js +84 -0
  68. package/es/handler/shim/drag_rotate.d.ts +46 -0
  69. package/es/handler/shim/drag_rotate.js +74 -0
  70. package/es/handler/shim/touch_zoom_rotate.d.ts +70 -0
  71. package/es/handler/shim/touch_zoom_rotate.js +115 -0
  72. package/es/handler/tap/single_tap_recognizer.d.ts +20 -0
  73. package/es/handler/tap/single_tap_recognizer.js +97 -0
  74. package/es/handler/tap/tap_drag_zoom.d.ts +22 -0
  75. package/es/handler/tap/tap_drag_zoom.js +106 -0
  76. package/es/handler/tap/tap_recognizer.d.ts +17 -0
  77. package/es/handler/tap/tap_recognizer.js +54 -0
  78. package/es/handler/tap/tap_zoom.d.ts +22 -0
  79. package/es/handler/tap/tap_zoom.js +109 -0
  80. package/es/handler/touch/index.d.ts +5 -0
  81. package/es/handler/touch/index.js +5 -0
  82. package/es/handler/touch/touch_pan.d.ts +30 -0
  83. package/es/handler/touch/touch_pan.js +110 -0
  84. package/es/handler/touch/touch_pitch.d.ts +13 -0
  85. package/es/handler/touch/touch_pitch.js +93 -0
  86. package/es/handler/touch/touch_rotate.d.ts +12 -0
  87. package/es/handler/touch/touch_rotate.js +77 -0
  88. package/es/handler/touch/touch_zoom.d.ts +12 -0
  89. package/es/handler/touch/touch_zoom.js +54 -0
  90. package/es/handler/touch/two_touch.d.ts +23 -0
  91. package/es/handler/touch/two_touch.js +125 -0
  92. package/es/hash.d.ts +14 -0
  93. package/es/hash.js +134 -0
  94. package/es/index.d.ts +4 -0
  95. package/es/index.js +4 -0
  96. package/es/interface.d.ts +34 -0
  97. package/es/interface.js +1 -0
  98. package/es/map.d.ts +70 -0
  99. package/es/map.js +387 -0
  100. package/es/util.d.ts +25 -0
  101. package/es/util.js +88 -0
  102. package/es/utils/Aabb.d.ts +12 -0
  103. package/es/utils/Aabb.js +112 -0
  104. package/es/utils/dom.d.ts +4 -0
  105. package/es/utils/dom.js +140 -0
  106. package/es/utils/performance.d.ts +17 -0
  107. package/es/utils/performance.js +62 -0
  108. package/es/utils/primitives.d.ts +6 -0
  109. package/es/utils/primitives.js +47 -0
  110. package/es/utils/task_queue.d.ts +13 -0
  111. package/es/utils/task_queue.js +89 -0
  112. package/lib/camera.js +724 -0
  113. package/lib/css/l7.css +98 -0
  114. package/lib/earthmap.js +376 -0
  115. package/lib/geo/edge_insets.js +114 -0
  116. package/lib/geo/lng_lat.js +81 -0
  117. package/lib/geo/lng_lat_bounds.js +161 -0
  118. package/lib/geo/mercator.js +100 -0
  119. package/lib/geo/point.js +231 -0
  120. package/lib/geo/simple.js +104 -0
  121. package/lib/geo/transform.js +971 -0
  122. package/lib/handler/IHandler.js +5 -0
  123. package/lib/handler/blockable_map_event.js +84 -0
  124. package/lib/handler/box_zoom.js +186 -0
  125. package/lib/handler/click_zoom.js +61 -0
  126. package/lib/handler/events/event.js +20 -0
  127. package/lib/handler/events/index.js +27 -0
  128. package/lib/handler/events/map_mouse_event.js +70 -0
  129. package/lib/handler/events/map_touch_event.js +100 -0
  130. package/lib/handler/events/map_wheel_event.js +57 -0
  131. package/lib/handler/events/render_event.js +33 -0
  132. package/lib/handler/handler_inertia.js +162 -0
  133. package/lib/handler/handler_manager.js +584 -0
  134. package/lib/handler/handler_util.js +15 -0
  135. package/lib/handler/keyboard.js +151 -0
  136. package/lib/handler/map_event.js +131 -0
  137. package/lib/handler/mouse/index.js +27 -0
  138. package/lib/handler/mouse/mouse_handler.js +124 -0
  139. package/lib/handler/mouse/mousepan_handler.js +49 -0
  140. package/lib/handler/mouse/mousepitch_hander.js +51 -0
  141. package/lib/handler/mouse/mouserotate_hander.js +51 -0
  142. package/lib/handler/mouse/util.js +22 -0
  143. package/lib/handler/scroll_zoom.js +333 -0
  144. package/lib/handler/shim/dblclick_zoom.js +74 -0
  145. package/lib/handler/shim/drag_pan.js +91 -0
  146. package/lib/handler/shim/drag_rotate.js +81 -0
  147. package/lib/handler/shim/touch_zoom_rotate.js +122 -0
  148. package/lib/handler/tap/single_tap_recognizer.js +106 -0
  149. package/lib/handler/tap/tap_drag_zoom.js +112 -0
  150. package/lib/handler/tap/tap_recognizer.js +63 -0
  151. package/lib/handler/tap/tap_zoom.js +115 -0
  152. package/lib/handler/touch/index.js +34 -0
  153. package/lib/handler/touch/touch_pan.js +117 -0
  154. package/lib/handler/touch/touch_pitch.js +98 -0
  155. package/lib/handler/touch/touch_rotate.js +82 -0
  156. package/lib/handler/touch/touch_zoom.js +59 -0
  157. package/lib/handler/touch/two_touch.js +131 -0
  158. package/lib/hash.js +143 -0
  159. package/lib/index.js +49 -0
  160. package/lib/interface.js +5 -0
  161. package/lib/map.js +394 -0
  162. package/lib/util.js +108 -0
  163. package/lib/utils/Aabb.js +119 -0
  164. package/lib/utils/dom.js +147 -0
  165. package/lib/utils/performance.js +70 -0
  166. package/lib/utils/primitives.js +54 -0
  167. package/lib/utils/task_queue.js +97 -0
  168. package/package.json +3 -3
package/es/hash.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { Map } from './map';
2
+ declare class Hash {
3
+ private map;
4
+ private updateHash;
5
+ private hashName?;
6
+ constructor(hashName?: string);
7
+ addTo(map: Map): this;
8
+ remove(): this;
9
+ onHashChange: () => boolean;
10
+ private getCurrentHash;
11
+ private getHashString;
12
+ private updateHashUnthrottled;
13
+ }
14
+ export default Hash;
package/es/hash.js ADDED
@@ -0,0 +1,134 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ // @ts-ignore
5
+ // tslint:disable-next-line:no-submodule-imports
6
+ import { lodashUtil } from '@antv/l7-utils';
7
+ var throttle = lodashUtil.throttle;
8
+ /*
9
+ * Adds the map's position to its page's location hash.
10
+ * Passed as an option to the map object.
11
+ *
12
+ * @returns {Hash} `this`
13
+ */
14
+ var Hash = /*#__PURE__*/function () {
15
+ function Hash(hashName) {
16
+ var _this = this;
17
+ _classCallCheck(this, Hash);
18
+ _defineProperty(this, "onHashChange", function () {
19
+ var loc = _this.getCurrentHash();
20
+ if (loc.length >= 3 && !loc.some(function (v) {
21
+ return isNaN(+v);
22
+ })) {
23
+ var bearing = _this.map.dragRotate.isEnabled() && _this.map.touchZoomRotate.isEnabled() ? +(loc[3] || 0) : _this.map.getBearing();
24
+ _this.map.jumpTo({
25
+ center: [+loc[2], +loc[1]],
26
+ zoom: +loc[0],
27
+ bearing: bearing,
28
+ pitch: +(loc[4] || 0)
29
+ });
30
+ return true;
31
+ }
32
+ return false;
33
+ });
34
+ _defineProperty(this, "getCurrentHash", function () {
35
+ // Get the current hash from location, stripped from its number sign
36
+ var hash = window.location.hash.replace('#', '');
37
+ if (_this.hashName) {
38
+ // Split the parameter-styled hash into parts and find the value we need
39
+ var keyval;
40
+ hash.split('&').map(function (part) {
41
+ return part.split('=');
42
+ }).forEach(function (part) {
43
+ if (part[0] === _this.hashName) {
44
+ keyval = part;
45
+ }
46
+ });
47
+ return (keyval ? keyval[1] || '' : '').split('/');
48
+ }
49
+ return hash.split('/');
50
+ });
51
+ _defineProperty(this, "updateHashUnthrottled", function () {
52
+ var hash = _this.getHashString();
53
+ try {
54
+ window.history.replaceState(window.history.state, '', hash);
55
+ } catch (SecurityError) {
56
+ // IE11 does not allow this if the page is within an iframe created
57
+ // with iframe.contentWindow.document.write(...).
58
+ // https://github.com/mapbox/mapbox-gl-js/issues/7410
59
+ }
60
+ });
61
+ this.hashName = hashName && encodeURIComponent(hashName);
62
+
63
+ // Mobile Safari doesn't allow updating the hash more than 100 times per 30 seconds.
64
+ this.updateHash = throttle(this.updateHashUnthrottled, 30 * 1000 / 100);
65
+ }
66
+ _createClass(Hash, [{
67
+ key: "addTo",
68
+ value: function addTo(map) {
69
+ this.map = map;
70
+ window.addEventListener('hashchange', this.onHashChange, false);
71
+ this.map.on('moveend', this.updateHash);
72
+ return this;
73
+ }
74
+ }, {
75
+ key: "remove",
76
+ value: function remove() {
77
+ window.removeEventListener('hashchange', this.onHashChange, false);
78
+ this.map.off('moveend', this.updateHash);
79
+ // clearTimeout(this.updateHash());
80
+
81
+ // @ts-ignore
82
+ delete this.map;
83
+ return this;
84
+ }
85
+ }, {
86
+ key: "getHashString",
87
+ value: function getHashString(mapFeedback) {
88
+ var center = this.map.getCenter();
89
+ var zoom = Math.round(this.map.getZoom() * 100) / 100;
90
+ // derived from equation: 512px * 2^z / 360 / 10^d < 0.5px
91
+ var precision = Math.ceil((zoom * Math.LN2 + Math.log(512 / 360 / 0.5)) / Math.LN10);
92
+ var m = Math.pow(10, precision);
93
+ var lng = Math.round(center.lng * m) / m;
94
+ var lat = Math.round(center.lat * m) / m;
95
+ var bearing = this.map.getBearing();
96
+ var pitch = this.map.getPitch();
97
+ var hash = '';
98
+ if (mapFeedback) {
99
+ // new map feedback site has some constraints that don't allow
100
+ // us to use the same hash format as we do for the Map hash option.
101
+ hash += "/".concat(lng, "/").concat(lat, "/").concat(zoom);
102
+ } else {
103
+ hash += "".concat(zoom, "/").concat(lat, "/").concat(lng);
104
+ }
105
+ if (bearing || pitch) {
106
+ hash += "/".concat(Math.round(bearing * 10) / 10);
107
+ }
108
+ if (pitch) {
109
+ hash += "/".concat(Math.round(pitch));
110
+ }
111
+ if (this.hashName) {
112
+ var hashName = this.hashName;
113
+ var found = false;
114
+ var parts = window.location.hash.slice(1).split('&').map(function (part) {
115
+ var key = part.split('=')[0];
116
+ if (key === hashName) {
117
+ found = true;
118
+ return "".concat(key, "=").concat(hash);
119
+ }
120
+ return part;
121
+ }).filter(function (a) {
122
+ return a;
123
+ });
124
+ if (!found) {
125
+ parts.push("".concat(hashName, "=").concat(hash));
126
+ }
127
+ return "#".concat(parts.join('&'));
128
+ }
129
+ return "#".concat(hash);
130
+ }
131
+ }]);
132
+ return Hash;
133
+ }();
134
+ export default Hash;
package/es/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './earthmap';
2
+ export * from './geo/mercator';
3
+ export * from './interface';
4
+ export * from './map';
package/es/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./earthmap";
2
+ export * from "./geo/mercator";
3
+ export * from "./interface";
4
+ export * from "./map";
@@ -0,0 +1,34 @@
1
+ import { LngLatBoundsLike } from './geo/lng_lat_bounds';
2
+ export interface IMapOptions {
3
+ hash: boolean;
4
+ style?: any;
5
+ container?: HTMLElement | string;
6
+ canvas?: HTMLCanvasElement;
7
+ center: [number, number];
8
+ zoom: number;
9
+ bearing: number;
10
+ pitch: number;
11
+ interactive: boolean;
12
+ scrollZoom: boolean;
13
+ bounds?: LngLatBoundsLike;
14
+ maxBounds?: LngLatBoundsLike;
15
+ fitBoundsOptions?: any;
16
+ minZoom: number;
17
+ maxZoom: number;
18
+ minPitch: number;
19
+ maxPitch: number;
20
+ boxZoom: boolean;
21
+ dragRotate: boolean;
22
+ dragPan: boolean;
23
+ keyboard: boolean;
24
+ doubleClickZoom: boolean;
25
+ touchZoomRotate: boolean;
26
+ touchPitch: boolean;
27
+ trackResize: boolean;
28
+ renderWorldCopies: boolean;
29
+ bearingSnap: number;
30
+ clickTolerance: number;
31
+ pitchWithRotate: boolean;
32
+ pitchEnabled: boolean;
33
+ rotateEnabled: boolean;
34
+ }
@@ -0,0 +1 @@
1
+ export {};
package/es/map.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ import Camera from './camera';
2
+ import './css/l7.css';
3
+ import LngLat, { LngLatLike } from './geo/lng_lat';
4
+ import LngLatBounds, { LngLatBoundsLike } from './geo/lng_lat_bounds';
5
+ import Point, { PointLike } from './geo/point';
6
+ import BoxZoomHandler from './handler/box_zoom';
7
+ import HandlerManager from './handler/handler_manager';
8
+ import KeyboardHandler from './handler/keyboard';
9
+ import ScrollZoomHandler from './handler/scroll_zoom';
10
+ import DoubleClickZoomHandler from './handler/shim/dblclick_zoom';
11
+ import DragPanHandler from './handler/shim/drag_pan';
12
+ import DragRotateHandler from './handler/shim/drag_rotate';
13
+ import TouchZoomRotateHandler from './handler/shim/touch_zoom_rotate';
14
+ import { TouchPitchHandler } from './handler/touch';
15
+ import { IMapOptions } from './interface';
16
+ import { TaskID } from './utils/task_queue';
17
+ type CallBack = (_: number) => void;
18
+ export declare class Map extends Camera {
19
+ doubleClickZoom: DoubleClickZoomHandler;
20
+ dragRotate: DragRotateHandler;
21
+ dragPan: DragPanHandler;
22
+ touchZoomRotate: TouchZoomRotateHandler;
23
+ scrollZoom: ScrollZoomHandler;
24
+ keyboard: KeyboardHandler;
25
+ touchPitch: TouchPitchHandler;
26
+ boxZoom: BoxZoomHandler;
27
+ handlers: HandlerManager;
28
+ private container;
29
+ private canvas;
30
+ private canvasContainer;
31
+ private renderTaskQueue;
32
+ private frame;
33
+ private trackResize;
34
+ private hash;
35
+ constructor(options: Partial<IMapOptions>);
36
+ resize(eventData?: any): this;
37
+ getContainer(): HTMLElement;
38
+ getCanvas(): HTMLCanvasElement;
39
+ getCanvasContainer(): HTMLElement;
40
+ project(lngLat: LngLatLike): Point;
41
+ unproject(point: PointLike): LngLat;
42
+ getBounds(): LngLatBounds;
43
+ getMaxBounds(): LngLatBounds | null;
44
+ setMaxBounds(bounds: LngLatBoundsLike): void;
45
+ setStyle(style: any): void;
46
+ setMinZoom(minZoom?: number): this;
47
+ getMinZoom(): number;
48
+ setMaxZoom(maxZoom?: number): this;
49
+ getMaxZoom(): number;
50
+ setMinPitch(minPitch?: number): this;
51
+ getMinPitch(): number;
52
+ setMaxPitch(maxPitch?: number): this;
53
+ getMaxPitch(): number;
54
+ getRenderWorldCopies(): boolean;
55
+ setRenderWorldCopies(renderWorldCopies?: boolean): void;
56
+ remove(): void;
57
+ requestRenderFrame(cb: CallBack): TaskID;
58
+ cancelRenderFrame(id: TaskID): void;
59
+ triggerRepaint(): void;
60
+ update(time?: number): void;
61
+ private initContainer;
62
+ /**
63
+ * 小程序环境构建容器
64
+ */
65
+ private initMiniContainer;
66
+ private containerDimensions;
67
+ private onWindowOnline;
68
+ private onWindowResize;
69
+ }
70
+ export {};
package/es/map.js ADDED
@@ -0,0 +1,387 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
5
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
6
+ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
7
+ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11
+ import { DOM, lodashUtil } from '@antv/l7-utils';
12
+ import Camera from "./camera";
13
+ function loadStyles(css, doc) {
14
+ var isMiniAli = typeof my !== 'undefined' && !!my && typeof my.showToast === 'function' && my.isFRM !== true;
15
+ var isWeChatMiniProgram = typeof wx !== 'undefined' && wx !== null && (typeof wx.request !== 'undefined' || typeof wx.miniProgram !== 'undefined');
16
+ if (isMiniAli || isWeChatMiniProgram) {
17
+ return;
18
+ }
19
+ if (!doc) doc = document;
20
+ if (!doc) {
21
+ return;
22
+ }
23
+ var head = doc.head || doc.getElementsByTagName('head')[0];
24
+ if (!head) {
25
+ head = doc.createElement('head');
26
+ var body = doc.body || doc.getElementsByTagName('body')[0];
27
+ if (body) {
28
+ body.parentNode.insertBefore(head, body);
29
+ } else {
30
+ doc.documentElement.appendChild(head);
31
+ }
32
+ }
33
+ var style = doc.createElement('style');
34
+ style.type = 'text/css';
35
+ if (style.styleSheet) {
36
+ style.styleSheet.cssText = css;
37
+ } else {
38
+ style.appendChild(doc.createTextNode(css));
39
+ }
40
+ head.appendChild(style);
41
+ return style;
42
+ }
43
+ loadStyles(".l7-map {\n font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;\n overflow: hidden;\n position: relative;\n -webkit-tap-highlight-color: rgba(0, 0, 0, 0);\n}\n\n.l7-canvas {\n position: absolute;\n left: 0;\n top: 0;\n}\n\n.l7-map:-webkit-full-screen {\n width: 100%;\n height: 100%;\n}\n\n.l7-canary {\n background-color: salmon;\n}\n\n.l7-canvas-container.l7-interactive,\n.l7-ctrl-group button.l7-ctrl-compass {\n cursor: -webkit-grab;\n cursor: grab;\n -moz-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n.l7-canvas-container.l7-interactive.l7-track-pointer {\n cursor: pointer;\n}\n\n.l7-canvas-container.l7-interactive:active,\n.l7-ctrl-group button.l7-ctrl-compass:active {\n cursor: -webkit-grabbing;\n cursor: grabbing;\n}\n\n.l7-canvas-container.l7-touch-zoom-rotate,\n.l7-canvas-container.l7-touch-zoom-rotate .l7-canvas {\n -ms-touch-action: pan-x pan-y;\n touch-action: pan-x pan-y;\n}\n\n.l7-canvas-container.l7-touch-drag-pan,\n.l7-canvas-container.l7-touch-drag-pan .l7-canvas {\n -ms-touch-action: pinch-zoom;\n touch-action: pinch-zoom;\n}\n\n.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan,\n.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan .l7-canvas {\n -ms-touch-action: none;\n touch-action: none;\n}\n\n.l7-ctrl-top-left,\n.l7-ctrl-top-right,\n.l7-ctrl-bottom-left,\n.l7-ctrl-bottom-right { position: absolute; pointer-events: none; z-index: 2; }\n.l7-ctrl-top-left { top: 0; left: 0; }\n.l7-ctrl-top-right { top: 0; right: 0; }\n.l7-ctrl-bottom-left { bottom: 0; left: 0; }\n.l7-ctrl-bottom-right { right: 0; bottom: 0; }\n\n.l7-ctrl {\n clear: both;\n pointer-events: auto;\n\n /* workaround for a Safari bug https://github.com/mapbox/mapbox-gl-js/issues/8185 */\n -webkit-transform: translate(0, 0);\n transform: translate(0, 0);\n}\n.l7-ctrl-top-left .l7-ctrl { margin: 10px 0 0 10px; float: left; }\n.l7-ctrl-top-right .l7-ctrl { margin: 10px 10px 0 0; float: right; }\n.l7-ctrl-bottom-left .l7-ctrl { margin: 0 0 10px 10px; float: left; }\n.l7-ctrl-bottom-right .l7-ctrl { margin: 0 10px 10px 0; float: right; }\n\n\n.l7-crosshair,\n.l7-crosshair .l7-interactive,\n.l7-crosshair .l7-interactive:active {\n cursor: crosshair;\n}\n\n.l7-boxzoom {\n position: absolute;\n top: 0;\n left: 0;\n width: 0;\n height: 0;\n background: #fff;\n border: 2px dotted #202020;\n opacity: 0.5;\n z-index: 10;\n}\n");
44
+ import LngLat from "./geo/lng_lat";
45
+ import LngLatBounds from "./geo/lng_lat_bounds";
46
+ // @ts-ignore
47
+ import Point from "./geo/point";
48
+ import HandlerManager from "./handler/handler_manager";
49
+ import Hash from "./hash";
50
+ import { renderframe } from "./util";
51
+ import { PerformanceUtils } from "./utils/performance";
52
+ import TaskQueue from "./utils/task_queue";
53
+ var defaultMinZoom = -2;
54
+ var defaultMaxZoom = 22;
55
+ var merge = lodashUtil.merge;
56
+ // the default values, but also the valid range
57
+ var defaultMinPitch = 0;
58
+ var defaultMaxPitch = 60;
59
+ var DefaultOptions = {
60
+ hash: false,
61
+ zoom: -1,
62
+ center: [112, 32],
63
+ pitch: 0,
64
+ bearing: 0,
65
+ interactive: true,
66
+ minZoom: defaultMinZoom,
67
+ maxZoom: defaultMaxZoom,
68
+ minPitch: defaultMinPitch,
69
+ maxPitch: defaultMaxPitch,
70
+ scrollZoom: true,
71
+ boxZoom: true,
72
+ dragRotate: true,
73
+ dragPan: true,
74
+ keyboard: true,
75
+ doubleClickZoom: true,
76
+ touchZoomRotate: true,
77
+ touchPitch: true,
78
+ bearingSnap: 7,
79
+ clickTolerance: 3,
80
+ pitchWithRotate: true,
81
+ trackResize: true,
82
+ renderWorldCopies: true,
83
+ pitchEnabled: true,
84
+ rotateEnabled: true
85
+ };
86
+ export var Map = /*#__PURE__*/function (_Camera) {
87
+ _inherits(Map, _Camera);
88
+ var _super = _createSuper(Map);
89
+ function Map(options) {
90
+ var _this;
91
+ _classCallCheck(this, Map);
92
+ _this = _super.call(this, merge({}, DefaultOptions, options));
93
+ _defineProperty(_assertThisInitialized(_this), "renderTaskQueue", new TaskQueue());
94
+ _defineProperty(_assertThisInitialized(_this), "trackResize", true);
95
+ _defineProperty(_assertThisInitialized(_this), "onWindowOnline", function () {
96
+ _this.update();
97
+ });
98
+ _defineProperty(_assertThisInitialized(_this), "onWindowResize", function (event) {
99
+ if (_this.trackResize) {
100
+ _this.resize({
101
+ originalEvent: event
102
+ }).update();
103
+ }
104
+ });
105
+ _this.initContainer();
106
+ _this.resize();
107
+ _this.handlers = new HandlerManager(_assertThisInitialized(_this), _this.options);
108
+ if (typeof window !== 'undefined') {
109
+ window.addEventListener('online', _this.onWindowOnline, false);
110
+ window.addEventListener('resize', _this.onWindowResize, false);
111
+ window.addEventListener('orientationchange', _this.onWindowResize, false);
112
+ }
113
+ var hashName = typeof options.hash === 'string' && options.hash || undefined;
114
+ if (options.hash) {
115
+ _this.hash = new Hash(hashName).addTo(_assertThisInitialized(_this));
116
+ }
117
+
118
+ // don't set position from options if set through hash
119
+ if (!_this.hash || !_this.hash.onHashChange()) {
120
+ _this.jumpTo({
121
+ center: options.center,
122
+ zoom: options.zoom,
123
+ bearing: options.bearing,
124
+ pitch: options.pitch
125
+ });
126
+ if (options.bounds) {
127
+ _this.resize();
128
+ _this.fitBounds(options.bounds, merge({}, options.fitBoundsOptions, {
129
+ duration: 0
130
+ }));
131
+ }
132
+ }
133
+ return _this;
134
+ }
135
+ _createClass(Map, [{
136
+ key: "resize",
137
+ value: function resize(eventData) {
138
+ var _this$containerDimens = this.containerDimensions(),
139
+ _this$containerDimens2 = _slicedToArray(_this$containerDimens, 2),
140
+ width = _this$containerDimens2[0],
141
+ height = _this$containerDimens2[1];
142
+ this.transform.resize(width, height);
143
+ // 小程序环境不需要执行后续动作
144
+ var fireMoving = !this.moving;
145
+ if (fireMoving) {
146
+ this.stop();
147
+ this.emit('movestart', new window.Event('movestart', eventData));
148
+ this.emit('move', new window.Event('move', eventData));
149
+ }
150
+ this.emit('resize', new window.Event('resize', eventData));
151
+ if (fireMoving) {
152
+ this.emit('moveend', new window.Event('moveend', eventData));
153
+ }
154
+ return this;
155
+ }
156
+ }, {
157
+ key: "getContainer",
158
+ value: function getContainer() {
159
+ return this.container;
160
+ }
161
+ }, {
162
+ key: "getCanvas",
163
+ value: function getCanvas() {
164
+ return this.canvas;
165
+ }
166
+ }, {
167
+ key: "getCanvasContainer",
168
+ value: function getCanvasContainer() {
169
+ return this.canvasContainer;
170
+ }
171
+ }, {
172
+ key: "project",
173
+ value: function project(lngLat) {
174
+ return this.transform.locationPoint(LngLat.convert(lngLat));
175
+ }
176
+ }, {
177
+ key: "unproject",
178
+ value: function unproject(point) {
179
+ return this.transform.pointLocation(Point.convert(point));
180
+ }
181
+ }, {
182
+ key: "getBounds",
183
+ value: function getBounds() {
184
+ return this.transform.getBounds();
185
+ }
186
+ }, {
187
+ key: "getMaxBounds",
188
+ value: function getMaxBounds() {
189
+ return this.transform.getMaxBounds();
190
+ }
191
+ }, {
192
+ key: "setMaxBounds",
193
+ value: function setMaxBounds(bounds) {
194
+ this.transform.setMaxBounds(LngLatBounds.convert(bounds));
195
+ }
196
+
197
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
198
+ }, {
199
+ key: "setStyle",
200
+ value: function setStyle(style) {
201
+ return;
202
+ }
203
+ }, {
204
+ key: "setMinZoom",
205
+ value: function setMinZoom(minZoom) {
206
+ minZoom = minZoom === null || minZoom === undefined ? defaultMinZoom : minZoom;
207
+ if (minZoom >= defaultMinZoom && minZoom <= this.transform.maxZoom) {
208
+ this.transform.minZoom = minZoom;
209
+ if (this.getZoom() < minZoom) {
210
+ this.setZoom(minZoom);
211
+ }
212
+ return this;
213
+ } else {
214
+ throw new Error("minZoom must be between ".concat(defaultMinZoom, " and the current maxZoom, inclusive"));
215
+ }
216
+ }
217
+ }, {
218
+ key: "getMinZoom",
219
+ value: function getMinZoom() {
220
+ return this.transform.minZoom;
221
+ }
222
+ }, {
223
+ key: "setMaxZoom",
224
+ value: function setMaxZoom(maxZoom) {
225
+ maxZoom = maxZoom === null || maxZoom === undefined ? defaultMaxZoom : maxZoom;
226
+ if (maxZoom >= this.transform.minZoom) {
227
+ this.transform.maxZoom = maxZoom;
228
+ if (this.getZoom() > maxZoom) {
229
+ this.setZoom(maxZoom);
230
+ }
231
+ return this;
232
+ } else {
233
+ throw new Error('maxZoom must be greater than the current minZoom');
234
+ }
235
+ }
236
+ }, {
237
+ key: "getMaxZoom",
238
+ value: function getMaxZoom() {
239
+ return this.transform.maxZoom;
240
+ }
241
+ }, {
242
+ key: "setMinPitch",
243
+ value: function setMinPitch(minPitch) {
244
+ minPitch = minPitch === null || minPitch === undefined ? defaultMinPitch : minPitch;
245
+ if (minPitch < defaultMinPitch) {
246
+ throw new Error("minPitch must be greater than or equal to ".concat(defaultMinPitch));
247
+ }
248
+ if (minPitch >= defaultMinPitch && minPitch <= this.transform.maxPitch) {
249
+ this.transform.minPitch = minPitch;
250
+ if (this.getPitch() < minPitch) {
251
+ this.setPitch(minPitch);
252
+ }
253
+ return this;
254
+ } else {
255
+ throw new Error("minPitch must be between ".concat(defaultMinPitch, " and the current maxPitch, inclusive"));
256
+ }
257
+ }
258
+ }, {
259
+ key: "getMinPitch",
260
+ value: function getMinPitch() {
261
+ return this.transform.minPitch;
262
+ }
263
+ }, {
264
+ key: "setMaxPitch",
265
+ value: function setMaxPitch(maxPitch) {
266
+ maxPitch = maxPitch === null || maxPitch === undefined ? defaultMaxPitch : maxPitch;
267
+ if (maxPitch > defaultMaxPitch) {
268
+ throw new Error("maxPitch must be less than or equal to ".concat(defaultMaxPitch));
269
+ }
270
+ if (maxPitch >= this.transform.minPitch) {
271
+ this.transform.maxPitch = maxPitch;
272
+ if (this.getPitch() > maxPitch) {
273
+ this.setPitch(maxPitch);
274
+ }
275
+ return this;
276
+ } else {
277
+ throw new Error('maxPitch must be greater than the current minPitch');
278
+ }
279
+ }
280
+ }, {
281
+ key: "getMaxPitch",
282
+ value: function getMaxPitch() {
283
+ return this.transform.maxPitch;
284
+ }
285
+ }, {
286
+ key: "getRenderWorldCopies",
287
+ value: function getRenderWorldCopies() {
288
+ return this.transform.renderWorldCopies;
289
+ }
290
+ }, {
291
+ key: "setRenderWorldCopies",
292
+ value: function setRenderWorldCopies(renderWorldCopies) {
293
+ this.transform.renderWorldCopies = !!renderWorldCopies;
294
+ }
295
+ }, {
296
+ key: "remove",
297
+ value: function remove() {
298
+ this.container.removeChild(this.canvasContainer);
299
+ // @ts-ignore
300
+ this.canvasContainer = null;
301
+ if (this.frame) {
302
+ this.frame.cancel();
303
+ this.frame = null;
304
+ }
305
+ this.renderTaskQueue.clear();
306
+ }
307
+ }, {
308
+ key: "requestRenderFrame",
309
+ value: function requestRenderFrame(cb) {
310
+ this.update();
311
+ return this.renderTaskQueue.add(cb);
312
+ }
313
+ }, {
314
+ key: "cancelRenderFrame",
315
+ value: function cancelRenderFrame(id) {
316
+ return this.renderTaskQueue.remove(id);
317
+ }
318
+ }, {
319
+ key: "triggerRepaint",
320
+ value: function triggerRepaint() {
321
+ var _this2 = this;
322
+ if (!this.frame) {
323
+ this.frame = renderframe(function (paintStartTimeStamp) {
324
+ PerformanceUtils.frame(paintStartTimeStamp);
325
+ _this2.frame = null;
326
+ _this2.update(paintStartTimeStamp);
327
+ });
328
+ }
329
+ }
330
+ }, {
331
+ key: "update",
332
+ value: function update(time) {
333
+ var _this3 = this;
334
+ if (!this.frame) {
335
+ this.frame = renderframe(function (paintStartTimeStamp) {
336
+ PerformanceUtils.frame(paintStartTimeStamp);
337
+ _this3.frame = null;
338
+ _this3.renderTaskQueue.run(time);
339
+ });
340
+ }
341
+ }
342
+ }, {
343
+ key: "initContainer",
344
+ value: function initContainer() {
345
+ if (typeof this.options.container === 'string') {
346
+ this.container = window.document.getElementById(this.options.container);
347
+ if (!this.container) {
348
+ throw new Error("Container '".concat(this.options.container, "' not found."));
349
+ }
350
+ } else if (this.options.container instanceof HTMLElement) {
351
+ this.container = this.options.container;
352
+ } else {
353
+ throw new Error("Invalid type: 'container' must be a String or HTMLElement.");
354
+ }
355
+ var container = this.container;
356
+ container.classList.add('l7-map');
357
+ var canvasContainer = this.canvasContainer = DOM.create('div', 'l7-canvas-container', container);
358
+ if (this.options.interactive) {
359
+ canvasContainer.classList.add('l7-interactive');
360
+ }
361
+ }
362
+
363
+ /**
364
+ * 小程序环境构建容器
365
+ */
366
+ }, {
367
+ key: "initMiniContainer",
368
+ value: function initMiniContainer() {
369
+ this.container = this.options.canvas;
370
+ this.canvasContainer = this.container;
371
+ }
372
+ }, {
373
+ key: "containerDimensions",
374
+ value: function containerDimensions() {
375
+ var width = 0;
376
+ var height = 0;
377
+ if (this.container) {
378
+ width = this.container.clientWidth;
379
+ height = this.container.clientHeight;
380
+ width = width === 0 ? 400 : width;
381
+ height = height === 0 ? 300 : height;
382
+ }
383
+ return [width, height];
384
+ }
385
+ }]);
386
+ return Map;
387
+ }(Camera);
package/es/util.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export interface ICancelable {
2
+ cancel: () => void;
3
+ }
4
+ export declare function wrap(n: number, min: number, max: number): number;
5
+ export declare function clamp(n: number, min: number, max: number): number;
6
+ export declare function interpolate(a: number, b: number, t: number): number;
7
+ export declare function bezier(p1x: number, p1y: number, p2x: number, p2y: number): (t: number) => number;
8
+ export declare const ease: (t: number) => number;
9
+ export declare function prefersReducedMotion(): boolean;
10
+ export declare function pick(src: {
11
+ [key: string]: any;
12
+ }, properties: string[]): {
13
+ [key: string]: any;
14
+ };
15
+ export declare const now: () => number;
16
+ export declare const raf: ((callback: FrameRequestCallback) => number) & typeof requestAnimationFrame;
17
+ export declare const cancel: ((handle: number) => void) & typeof cancelAnimationFrame;
18
+ export declare function renderframe(fn: (paintStartTimestamp: number) => void): ICancelable;
19
+ export declare function extend(dest: {
20
+ [key: string]: any;
21
+ }, ...sources: Array<Partial<{
22
+ [key: string]: any;
23
+ }>>): {
24
+ [key: string]: any;
25
+ };