@antv/l7-component 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 (151) hide show
  1. package/es/assets/iconfont/iconfont.d.ts +21 -0
  2. package/es/assets/iconfont/iconfont.js +61 -0
  3. package/es/constants/index.d.ts +60 -0
  4. package/es/constants/index.js +60 -0
  5. package/es/control/baseControl/buttonControl.d.ts +60 -0
  6. package/es/control/baseControl/buttonControl.js +142 -0
  7. package/es/control/baseControl/control.d.ts +112 -0
  8. package/es/control/baseControl/control.js +256 -0
  9. package/es/control/baseControl/index.d.ts +4 -0
  10. package/es/control/baseControl/index.js +4 -0
  11. package/es/control/baseControl/popperControl.d.ts +28 -0
  12. package/es/control/baseControl/popperControl.js +92 -0
  13. package/es/control/baseControl/selectControl.d.ts +53 -0
  14. package/es/control/baseControl/selectControl.js +173 -0
  15. package/es/control/exportImage.d.ts +19 -0
  16. package/es/control/exportImage.js +73 -0
  17. package/es/control/fullscreen.d.ts +20 -0
  18. package/es/control/fullscreen.js +88 -0
  19. package/es/control/geoLocate.d.ts +17 -0
  20. package/es/control/geoLocate.js +60 -0
  21. package/es/control/layerSwitch.d.ts +27 -0
  22. package/es/control/layerSwitch.js +155 -0
  23. package/es/control/logo.d.ts +14 -0
  24. package/es/control/logo.js +49 -0
  25. package/es/control/mapTheme.d.ts +11 -0
  26. package/es/control/mapTheme.js +69 -0
  27. package/es/control/mouseLocation.d.ts +16 -0
  28. package/es/control/mouseLocation.js +52 -0
  29. package/es/control/scale.d.ts +35 -0
  30. package/es/control/scale.js +121 -0
  31. package/es/control/swipe.d.ts +66 -0
  32. package/es/control/swipe.js +392 -0
  33. package/es/control/zoom.d.ts +39 -0
  34. package/es/control/zoom.js +100 -0
  35. package/es/css/button.less +77 -0
  36. package/es/css/control.less +82 -0
  37. package/es/css/index.css +653 -0
  38. package/es/css/index.less +13 -0
  39. package/es/css/l7.less +69 -0
  40. package/es/css/layerPopup.less +9 -0
  41. package/es/css/logo.less +21 -0
  42. package/es/css/mouseLocation.less +9 -0
  43. package/es/css/popper.less +74 -0
  44. package/es/css/popup.less +176 -0
  45. package/es/css/scale.less +37 -0
  46. package/es/css/select.less +96 -0
  47. package/es/css/swipe.less +80 -0
  48. package/es/css/variables.less +29 -0
  49. package/es/css/zoom.less +34 -0
  50. package/es/images/layers.png +0 -0
  51. package/es/images/layers.svg +1 -0
  52. package/es/images/logo.png +0 -0
  53. package/es/images/quanping.svg +12 -0
  54. package/es/index.d.ts +19 -0
  55. package/es/index.js +717 -0
  56. package/es/interface.d.ts +29 -0
  57. package/es/interface.js +1 -0
  58. package/es/marker-layer.d.ts +46 -0
  59. package/es/marker-layer.js +509 -0
  60. package/es/marker.d.ts +66 -0
  61. package/es/marker.js +495 -0
  62. package/es/popup/layerPopup.d.ts +105 -0
  63. package/es/popup/layerPopup.js +341 -0
  64. package/es/popup/popup.d.ts +147 -0
  65. package/es/popup/popup.js +587 -0
  66. package/es/utils/anchor.d.ts +22 -0
  67. package/es/utils/anchor.js +31 -0
  68. package/es/utils/eventManager.d.ts +42 -0
  69. package/es/utils/eventManager.js +84 -0
  70. package/es/utils/icon.d.ts +1 -0
  71. package/es/utils/icon.js +12 -0
  72. package/es/utils/popper.d.ts +76 -0
  73. package/es/utils/popper.js +257 -0
  74. package/es/utils/screenfull.d.ts +2 -0
  75. package/es/utils/screenfull.js +106 -0
  76. package/lib/assets/iconfont/iconfont.d.ts +21 -0
  77. package/lib/assets/iconfont/iconfont.js +68 -0
  78. package/lib/constants/index.d.ts +60 -0
  79. package/lib/constants/index.js +66 -0
  80. package/lib/control/baseControl/buttonControl.d.ts +60 -0
  81. package/lib/control/baseControl/buttonControl.js +149 -0
  82. package/lib/control/baseControl/control.d.ts +112 -0
  83. package/lib/control/baseControl/control.js +269 -0
  84. package/lib/control/baseControl/index.d.ts +4 -0
  85. package/lib/control/baseControl/index.js +39 -0
  86. package/lib/control/baseControl/popperControl.d.ts +28 -0
  87. package/lib/control/baseControl/popperControl.js +99 -0
  88. package/lib/control/baseControl/selectControl.d.ts +53 -0
  89. package/lib/control/baseControl/selectControl.js +180 -0
  90. package/lib/control/exportImage.d.ts +19 -0
  91. package/lib/control/exportImage.js +80 -0
  92. package/lib/control/fullscreen.d.ts +20 -0
  93. package/lib/control/fullscreen.js +95 -0
  94. package/lib/control/geoLocate.d.ts +17 -0
  95. package/lib/control/geoLocate.js +67 -0
  96. package/lib/control/layerSwitch.d.ts +27 -0
  97. package/lib/control/layerSwitch.js +162 -0
  98. package/lib/control/logo.d.ts +14 -0
  99. package/lib/control/logo.js +55 -0
  100. package/lib/control/mapTheme.d.ts +11 -0
  101. package/lib/control/mapTheme.js +76 -0
  102. package/lib/control/mouseLocation.d.ts +16 -0
  103. package/lib/control/mouseLocation.js +59 -0
  104. package/lib/control/scale.d.ts +35 -0
  105. package/lib/control/scale.js +128 -0
  106. package/lib/control/swipe.d.ts +66 -0
  107. package/lib/control/swipe.js +399 -0
  108. package/lib/control/zoom.d.ts +39 -0
  109. package/lib/control/zoom.js +107 -0
  110. package/lib/css/button.less +77 -0
  111. package/lib/css/control.less +82 -0
  112. package/lib/css/index.css +653 -0
  113. package/lib/css/index.less +13 -0
  114. package/lib/css/l7.less +69 -0
  115. package/lib/css/layerPopup.less +9 -0
  116. package/lib/css/logo.less +21 -0
  117. package/lib/css/mouseLocation.less +9 -0
  118. package/lib/css/popper.less +74 -0
  119. package/lib/css/popup.less +176 -0
  120. package/lib/css/scale.less +37 -0
  121. package/lib/css/select.less +96 -0
  122. package/lib/css/swipe.less +80 -0
  123. package/lib/css/variables.less +29 -0
  124. package/lib/css/zoom.less +34 -0
  125. package/lib/images/layers.png +0 -0
  126. package/lib/images/layers.svg +1 -0
  127. package/lib/images/logo.png +0 -0
  128. package/lib/images/quanping.svg +12 -0
  129. package/lib/index.d.ts +19 -0
  130. package/lib/index.js +844 -0
  131. package/lib/interface.d.ts +29 -0
  132. package/lib/interface.js +5 -0
  133. package/lib/marker-layer.d.ts +46 -0
  134. package/lib/marker-layer.js +518 -0
  135. package/lib/marker.d.ts +66 -0
  136. package/lib/marker.js +502 -0
  137. package/lib/popup/layerPopup.d.ts +105 -0
  138. package/lib/popup/layerPopup.js +348 -0
  139. package/lib/popup/popup.d.ts +147 -0
  140. package/lib/popup/popup.js +594 -0
  141. package/lib/utils/anchor.d.ts +22 -0
  142. package/lib/utils/anchor.js +38 -0
  143. package/lib/utils/eventManager.d.ts +42 -0
  144. package/lib/utils/eventManager.js +92 -0
  145. package/lib/utils/icon.d.ts +1 -0
  146. package/lib/utils/icon.js +19 -0
  147. package/lib/utils/popper.d.ts +76 -0
  148. package/lib/utils/popper.js +264 -0
  149. package/lib/utils/screenfull.d.ts +2 -0
  150. package/lib/utils/screenfull.js +112 -0
  151. package/package.json +5 -5
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.ExportImage = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _icon = require("../utils/icon");
12
+ var _buttonControl = _interopRequireDefault(require("./baseControl/buttonControl"));
13
+ class ExportImage extends _buttonControl.default {
14
+ constructor(...args) {
15
+ var _this;
16
+ super(...args);
17
+ _this = this;
18
+ (0, _defineProperty2.default)(this, "onClick", /*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
19
+ const {
20
+ onExport
21
+ } = _this.controlOption;
22
+ onExport === null || onExport === void 0 || onExport(yield _this.getImage());
23
+ }));
24
+ /**
25
+ * 将多张图片合并为一张图片
26
+ * @protected
27
+ * @param base64List
28
+ */
29
+ (0, _defineProperty2.default)(this, "mergeImage", /*#__PURE__*/(0, _asyncToGenerator2.default)(function* (...base64List) {
30
+ var _this$mapsService$get, _this$mapsService$get2;
31
+ const {
32
+ imageType
33
+ } = _this.controlOption;
34
+ const {
35
+ width = 0,
36
+ height = 0
37
+ } = (_this$mapsService$get = (_this$mapsService$get2 = _this.mapsService.getContainer()) === null || _this$mapsService$get2 === void 0 ? void 0 : _this$mapsService$get2.getBoundingClientRect()) !== null && _this$mapsService$get !== void 0 ? _this$mapsService$get : {};
38
+ const canvas = document.createElement('canvas');
39
+ canvas.width = width;
40
+ canvas.height = height;
41
+ const context = canvas.getContext('2d');
42
+ const imgList = yield Promise.all(base64List.map(base64 => {
43
+ return new Promise(resolve => {
44
+ const img = new Image();
45
+ img.onload = () => {
46
+ resolve(img);
47
+ };
48
+ img.src = base64;
49
+ });
50
+ }));
51
+ imgList.forEach(img => {
52
+ context === null || context === void 0 || context.drawImage(img, 0, 0, width, height);
53
+ });
54
+ return canvas.toDataURL(`image/${imageType}`);
55
+ }));
56
+ }
57
+ onAdd() {
58
+ const button = super.onAdd();
59
+ button.addEventListener('click', this.onClick);
60
+ return button;
61
+ }
62
+ getDefault(option) {
63
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
64
+ title: '导出图片',
65
+ btnIcon: (0, _icon.createL7Icon)('l7-icon-export-picture'),
66
+ imageType: 'png'
67
+ });
68
+ }
69
+ getImage() {
70
+ var _this2 = this;
71
+ return (0, _asyncToGenerator2.default)(function* () {
72
+ const mapImage = yield _this2.mapsService.exportMap('png');
73
+ const layerImage = yield _this2.scene.exportPng('png');
74
+ return _this2.mergeImage(
75
+ // 在 Map 底图模式下 mapImage 为 undefined
76
+ ...[mapImage, layerImage].filter(base64 => base64));
77
+ })();
78
+ }
79
+ }
80
+ exports.default = exports.ExportImage = ExportImage;
@@ -0,0 +1,20 @@
1
+ import type { IButtonControlOption } from './baseControl/buttonControl';
2
+ import ButtonControl from './baseControl/buttonControl';
3
+ export interface IFullscreenControlOption extends IButtonControlOption {
4
+ exitBtnText: IButtonControlOption['btnText'];
5
+ exitBtnIcon: IButtonControlOption['btnIcon'];
6
+ exitTitle: IButtonControlOption['title'];
7
+ }
8
+ export { Fullscreen };
9
+ export default class Fullscreen extends ButtonControl<IFullscreenControlOption> {
10
+ protected isFullscreen: boolean;
11
+ protected mapContainer: HTMLElement;
12
+ constructor(option?: Partial<IFullscreenControlOption>);
13
+ setOptions(newOptions: Partial<IFullscreenControlOption>): void;
14
+ onAdd(): HTMLElement;
15
+ onRemove(): void;
16
+ getDefault(option?: Partial<IFullscreenControlOption>): IFullscreenControlOption;
17
+ toggleFullscreen: () => Promise<void>;
18
+ protected onClick: () => void;
19
+ protected onFullscreenChange: () => void;
20
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.Fullscreen = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _l7Utils = require("@antv/l7-utils");
12
+ var _icon = require("../utils/icon");
13
+ var _screenfull = _interopRequireDefault(require("../utils/screenfull"));
14
+ var _buttonControl = _interopRequireDefault(require("./baseControl/buttonControl"));
15
+ class Fullscreen extends _buttonControl.default {
16
+ constructor(option) {
17
+ var _this;
18
+ super(option);
19
+ _this = this;
20
+ (0, _defineProperty2.default)(this, "isFullscreen", false);
21
+ (0, _defineProperty2.default)(this, "mapContainer", void 0);
22
+ (0, _defineProperty2.default)(this, "toggleFullscreen", /*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
23
+ if (_screenfull.default.isEnabled) {
24
+ yield _screenfull.default.toggle(_this.mapContainer);
25
+ }
26
+ }));
27
+ (0, _defineProperty2.default)(this, "onClick", () => {
28
+ this.toggleFullscreen();
29
+ });
30
+ (0, _defineProperty2.default)(this, "onFullscreenChange", () => {
31
+ this.isFullscreen = !!document.fullscreenElement;
32
+ const {
33
+ btnText,
34
+ btnIcon,
35
+ title,
36
+ exitBtnText,
37
+ exitBtnIcon,
38
+ exitTitle
39
+ } = this.controlOption;
40
+ if (this.isFullscreen) {
41
+ this.setBtnTitle(exitTitle);
42
+ this.setBtnText(exitBtnText);
43
+ this.setBtnIcon(exitBtnIcon);
44
+ } else {
45
+ this.setBtnTitle(title);
46
+ this.setBtnText(btnText);
47
+ this.setBtnIcon(btnIcon);
48
+ }
49
+ this.emit('fullscreenChange', this.isFullscreen);
50
+ });
51
+ if (!_screenfull.default.isEnabled) {
52
+ console.warn('当前浏览器环境不支持对地图全屏化');
53
+ }
54
+ }
55
+ setOptions(newOptions) {
56
+ const {
57
+ exitBtnText,
58
+ exitBtnIcon,
59
+ exitTitle
60
+ } = newOptions;
61
+ if (this.isFullscreen) {
62
+ if (this.checkUpdateOption(newOptions, ['exitBtnIcon'])) {
63
+ this.setBtnIcon(exitBtnIcon);
64
+ }
65
+ if (this.checkUpdateOption(newOptions, ['exitBtnText'])) {
66
+ this.setBtnText(exitBtnText);
67
+ }
68
+ if (this.checkUpdateOption(newOptions, ['exitTitle'])) {
69
+ this.setBtnTitle(exitTitle);
70
+ }
71
+ }
72
+ super.setOptions(newOptions);
73
+ }
74
+ onAdd() {
75
+ const button = super.onAdd();
76
+ button.addEventListener('click', this.onClick);
77
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
78
+ this.mapContainer = _l7Utils.DOM.getContainer(this.scene.getSceneConfig().id);
79
+ this.mapContainer.addEventListener('fullscreenchange', this.onFullscreenChange);
80
+ return button;
81
+ }
82
+ onRemove() {
83
+ super.onRemove();
84
+ this.mapContainer.removeEventListener('fullscreenchange', this.onFullscreenChange);
85
+ }
86
+ getDefault(option) {
87
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
88
+ title: '全屏',
89
+ btnIcon: (0, _icon.createL7Icon)('l7-icon-fullscreen'),
90
+ exitTitle: '退出全屏',
91
+ exitBtnIcon: (0, _icon.createL7Icon)('l7-icon-exit-fullscreen')
92
+ });
93
+ }
94
+ }
95
+ exports.default = exports.Fullscreen = Fullscreen;
@@ -0,0 +1,17 @@
1
+ import type { Point } from '@antv/l7-core';
2
+ import type { IButtonControlOption } from './baseControl/buttonControl';
3
+ import ButtonControl from './baseControl/buttonControl';
4
+ export interface IGeoLocateOption extends IButtonControlOption {
5
+ transform: (position: Point) => Point | Promise<Point>;
6
+ }
7
+ export { GeoLocate };
8
+ export default class GeoLocate extends ButtonControl<IGeoLocateOption> {
9
+ constructor(option?: Partial<IGeoLocateOption>);
10
+ getDefault(option?: Partial<IGeoLocateOption>): IGeoLocateOption;
11
+ onAdd(): HTMLElement;
12
+ /**
13
+ * 通过浏览器 API 获取当前所在经纬度
14
+ */
15
+ getGeoLocation: () => Promise<Point>;
16
+ onClick: () => Promise<void>;
17
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.GeoLocate = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _icon = require("../utils/icon");
12
+ var _buttonControl = _interopRequireDefault(require("./baseControl/buttonControl"));
13
+ class GeoLocate extends _buttonControl.default {
14
+ constructor(option) {
15
+ var _this;
16
+ super(option);
17
+ _this = this;
18
+ /**
19
+ * 通过浏览器 API 获取当前所在经纬度
20
+ */
21
+ (0, _defineProperty2.default)(this, "getGeoLocation", () => {
22
+ return new Promise((resolve, reject) => {
23
+ window.navigator.geolocation.getCurrentPosition(({
24
+ coords
25
+ }) => {
26
+ const {
27
+ longitude,
28
+ latitude
29
+ } = coords !== null && coords !== void 0 ? coords : {};
30
+ if (!isNaN(longitude) && !isNaN(latitude)) {
31
+ resolve([longitude, latitude]);
32
+ } else {
33
+ reject();
34
+ }
35
+ }, e => {
36
+ reject(e);
37
+ });
38
+ });
39
+ });
40
+ (0, _defineProperty2.default)(this, "onClick", /*#__PURE__*/(0, _asyncToGenerator2.default)(function* () {
41
+ if (!window.navigator.geolocation) {
42
+ return;
43
+ }
44
+ const {
45
+ transform
46
+ } = _this.controlOption;
47
+ const position = yield _this.getGeoLocation();
48
+ const currentZoom = _this.mapsService.getZoom();
49
+ _this.mapsService.setZoomAndCenter(currentZoom > 15 ? currentZoom : 15, transform ? yield transform(position) : position);
50
+ }));
51
+ if (!window.navigator.geolocation) {
52
+ console.warn('当前浏览器环境不支持获取地理定位');
53
+ }
54
+ }
55
+ getDefault(option) {
56
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
57
+ title: '定位',
58
+ btnIcon: (0, _icon.createL7Icon)('l7-icon-reposition')
59
+ });
60
+ }
61
+ onAdd() {
62
+ const button = super.onAdd();
63
+ button.addEventListener('click', this.onClick);
64
+ return button;
65
+ }
66
+ }
67
+ exports.default = exports.GeoLocate = GeoLocate;
@@ -0,0 +1,27 @@
1
+ import type { ILayer } from '@antv/l7-core';
2
+ import type { ControlOptionItem, ISelectControlOption } from './baseControl/selectControl';
3
+ import SelectControl from './baseControl/selectControl';
4
+ export type LayerSwitchItem = {
5
+ layer: ILayer;
6
+ name?: string;
7
+ img?: string;
8
+ };
9
+ export interface ILayerSwitchOption extends ISelectControlOption {
10
+ layers: Array<ILayer | string | LayerSwitchItem>;
11
+ multiple: boolean;
12
+ }
13
+ export { LayerSwitch };
14
+ export default class LayerSwitch extends SelectControl<ILayerSwitchOption> {
15
+ protected get layers(): ILayer[];
16
+ getDefault(option?: Partial<ILayerSwitchOption>): ILayerSwitchOption;
17
+ getLayerVisible(): string[];
18
+ getLayerOptions(): ControlOptionItem[];
19
+ setOptions(option: Partial<ILayerSwitchOption>): void;
20
+ private handleSingleSelection;
21
+ onAdd(): HTMLElement;
22
+ onRemove(): void;
23
+ protected onLayerChange: () => void;
24
+ protected onLayerVisibleChane: () => void;
25
+ protected onSelectChange: () => void;
26
+ protected getIsMultiple(): boolean;
27
+ }
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.LayerSwitch = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _icon = require("../utils/icon");
11
+ var _selectControl = _interopRequireDefault(require("./baseControl/selectControl"));
12
+ function isLayerSwitchItem(obj) {
13
+ return Object.keys(obj !== null && obj !== void 0 ? obj : {}).every(key => ['layer', 'name', 'img'].includes(key));
14
+ }
15
+ class LayerSwitch extends _selectControl.default {
16
+ constructor(...args) {
17
+ super(...args);
18
+ (0, _defineProperty2.default)(this, "onLayerChange", () => {
19
+ var _this$controlOption$l;
20
+ if ((_this$controlOption$l = this.controlOption.layers) !== null && _this$controlOption$l !== void 0 && _this$controlOption$l.length) {
21
+ return;
22
+ }
23
+ this.selectValue = this.getLayerVisible();
24
+ this.setOptions({
25
+ options: this.getLayerOptions()
26
+ });
27
+ });
28
+ (0, _defineProperty2.default)(this, "onLayerVisibleChane", () => {
29
+ this.setSelectValue(this.getLayerVisible());
30
+ });
31
+ (0, _defineProperty2.default)(this, "onSelectChange", () => {
32
+ this.layers.forEach(layer => {
33
+ const needShow = this.selectValue.includes(layer.name);
34
+ const isShow = layer.isVisible();
35
+ if (needShow && !isShow) {
36
+ layer.show();
37
+ }
38
+ if (!needShow && isShow) {
39
+ layer.hide();
40
+ }
41
+ });
42
+ });
43
+ }
44
+ get layers() {
45
+ const layerService = this.layerService;
46
+ const {
47
+ layers
48
+ } = this.controlOption;
49
+ if (Array.isArray(layers) && layers.length) {
50
+ const layerInstances = [];
51
+ layers.forEach(layer => {
52
+ if (layer instanceof Object) {
53
+ if (isLayerSwitchItem(layer)) {
54
+ layerInstances.push(layer.layer);
55
+ } else {
56
+ layerInstances.push(layer);
57
+ }
58
+ }
59
+ if (typeof layer === 'string') {
60
+ const targetLayer = layerService.getLayer(layer) || layerService.getLayerByName(layer);
61
+ if (targetLayer) {
62
+ layerInstances.push(targetLayer);
63
+ }
64
+ }
65
+ });
66
+ return layerInstances;
67
+ }
68
+ return layerService.getLayers() || [];
69
+ }
70
+ getDefault(option) {
71
+ var _option$multiple;
72
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
73
+ title: '图层控制',
74
+ btnIcon: (0, _icon.createL7Icon)('l7-icon-layer'),
75
+ options: [],
76
+ multiple: (_option$multiple = option === null || option === void 0 ? void 0 : option.multiple) !== null && _option$multiple !== void 0 ? _option$multiple : true
77
+ });
78
+ }
79
+ getLayerVisible() {
80
+ return this.layers.filter(layer => layer.isVisible()).map(layer => layer.name);
81
+ }
82
+ getLayerOptions() {
83
+ const {
84
+ layers
85
+ } = this.controlOption;
86
+ const isAllImg = layers === null || layers === void 0 ? void 0 : layers.every(item => item.img);
87
+ if (layers) {
88
+ return layers === null || layers === void 0 ? void 0 : layers.map(layer => {
89
+ if (isLayerSwitchItem(layer)) {
90
+ return {
91
+ text: layer.name || layer.layer.name,
92
+ value: layer.layer.name,
93
+ img: isAllImg ? layer.img : undefined
94
+ };
95
+ } else if (typeof layer === 'string') {
96
+ const targetLayer = this.layerService.getLayer(layer) || this.layerService.getLayerByName(layer);
97
+ return {
98
+ text: targetLayer === null || targetLayer === void 0 ? void 0 : targetLayer.name,
99
+ value: targetLayer === null || targetLayer === void 0 ? void 0 : targetLayer.name
100
+ };
101
+ }
102
+ return {
103
+ text: layer.name,
104
+ value: layer.name
105
+ };
106
+ });
107
+ }
108
+ return this.layers.map(layer => {
109
+ return {
110
+ text: layer.name,
111
+ value: layer.name
112
+ };
113
+ });
114
+ }
115
+ setOptions(option) {
116
+ const isLayerChange = this.checkUpdateOption(option, ['layers', 'multiple']);
117
+ super.setOptions(option);
118
+ if (isLayerChange) {
119
+ if (this.controlOption.multiple === false) {
120
+ this.handleSingleSelection();
121
+ }
122
+ this.selectValue = this.getLayerVisible();
123
+ this.controlOption.options = this.getLayerOptions();
124
+ this.popper.setContent(this.getPopperContent(this.controlOption.options));
125
+ }
126
+ }
127
+
128
+ // TODO: 单选模式下,目前默认展示第一项,通过用户提供defaultValue展示默认选项的属性待开发
129
+ // 如果是单选模式,则只显示第一个图层
130
+ handleSingleSelection() {
131
+ this.layers.forEach((layer, index) => {
132
+ if (index === 0) {
133
+ layer.show();
134
+ } else {
135
+ layer.hide();
136
+ }
137
+ });
138
+ }
139
+ onAdd() {
140
+ var _this$controlOption$o;
141
+ if (this.controlOption.multiple === false) {
142
+ this.handleSingleSelection();
143
+ }
144
+ if (!((_this$controlOption$o = this.controlOption.options) !== null && _this$controlOption$o !== void 0 && _this$controlOption$o.length)) {
145
+ this.controlOption.options = this.getLayerOptions();
146
+ }
147
+ if (!this.controlOption.defaultValue) {
148
+ this.controlOption.defaultValue = this.getLayerVisible();
149
+ }
150
+ this.on('selectChange', this.onSelectChange);
151
+ this.layerService.on('layerChange', this.onLayerChange);
152
+ return super.onAdd();
153
+ }
154
+ onRemove() {
155
+ this.off('selectChange', this.onSelectChange);
156
+ this.layerService.off('layerChange', this.onLayerChange);
157
+ }
158
+ getIsMultiple() {
159
+ return this.controlOption.multiple;
160
+ }
161
+ }
162
+ exports.default = exports.LayerSwitch = LayerSwitch;
@@ -0,0 +1,14 @@
1
+ import type { IControlOption } from './baseControl';
2
+ import { Control } from './baseControl';
3
+ export interface ILogoControlOption extends IControlOption {
4
+ img: string;
5
+ href?: string | null;
6
+ }
7
+ export { Logo };
8
+ export default class Logo extends Control<ILogoControlOption> {
9
+ getDefault(): ILogoControlOption;
10
+ onAdd(): HTMLElement;
11
+ onRemove(): null;
12
+ setOptions(option: Partial<ILogoControlOption>): void;
13
+ protected setLogoContent(container: HTMLElement): void;
14
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.Logo = void 0;
7
+ var _l7Utils = require("@antv/l7-utils");
8
+ var _baseControl = require("./baseControl");
9
+ class Logo extends _baseControl.Control {
10
+ getDefault() {
11
+ return {
12
+ position: _baseControl.PositionType.BOTTOMLEFT,
13
+ name: 'logo',
14
+ href: 'https://l7.antv.antgroup.com/',
15
+ img: 'https://gw.alipayobjects.com/mdn/rms_816329/afts/img/A*GRb1TKp4HcMAAAAAAAAAAAAAARQnAQ'
16
+ };
17
+ }
18
+ onAdd() {
19
+ const container = _l7Utils.DOM.create('div', 'l7-control-logo');
20
+ this.setLogoContent(container);
21
+ return container;
22
+ }
23
+ onRemove() {
24
+ return null;
25
+ }
26
+ setOptions(option) {
27
+ super.setOptions(option);
28
+ if (this.checkUpdateOption(option, ['img', 'href'])) {
29
+ _l7Utils.DOM.clearChildren(this.container);
30
+ this.setLogoContent(this.container);
31
+ }
32
+ }
33
+ setLogoContent(container) {
34
+ const {
35
+ href,
36
+ img
37
+ } = this.controlOption;
38
+ const imgDOM = _l7Utils.DOM.create('img');
39
+ imgDOM.setAttribute('src', img);
40
+ imgDOM.setAttribute('aria-label', 'AntV logo');
41
+ _l7Utils.DOM.setUnDraggable(imgDOM);
42
+ if (href) {
43
+ const anchorDOM = _l7Utils.DOM.create('a', 'l7-control-logo-link');
44
+ anchorDOM.target = '_blank';
45
+ anchorDOM.href = href;
46
+ anchorDOM.rel = 'noopener nofollow';
47
+ anchorDOM.setAttribute('rel', 'noopener nofollow');
48
+ anchorDOM.appendChild(imgDOM);
49
+ container.appendChild(anchorDOM);
50
+ } else {
51
+ container.appendChild(imgDOM);
52
+ }
53
+ }
54
+ }
55
+ exports.default = exports.Logo = Logo;
@@ -0,0 +1,11 @@
1
+ import type { ControlOptionItem, ISelectControlOption } from './baseControl/selectControl';
2
+ import SelectControl from './baseControl/selectControl';
3
+ export { MapTheme };
4
+ export default class MapTheme extends SelectControl<ISelectControlOption> {
5
+ getDefault(option?: Partial<ISelectControlOption>): ISelectControlOption;
6
+ getStyleOptions(): ControlOptionItem[];
7
+ getMapStyle(): any;
8
+ onAdd(): HTMLElement;
9
+ protected onMapThemeChange: () => void;
10
+ protected getIsMultiple(): boolean;
11
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.MapTheme = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _constants = require("../constants");
11
+ var _icon = require("../utils/icon");
12
+ var _selectControl = _interopRequireDefault(require("./baseControl/selectControl"));
13
+ class MapTheme extends _selectControl.default {
14
+ constructor(...args) {
15
+ super(...args);
16
+ (0, _defineProperty2.default)(this, "onMapThemeChange", () => {
17
+ this.mapsService.setMapStyle(this.selectValue[0]);
18
+ });
19
+ }
20
+ getDefault(option) {
21
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
22
+ title: '地图样式',
23
+ btnIcon: (0, _icon.createL7Icon)('l7-icon-color'),
24
+ options: []
25
+ });
26
+ }
27
+ getStyleOptions() {
28
+ const mapStyleConfig = this.mapsService.getType() === 'mapbox' ? _constants.MapboxMapStyleConfig : _constants.GaodeMapStyleConfig;
29
+ return Object.entries(this.mapsService.getMapStyleConfig()).filter(([key, value]) => typeof value === 'string' && key !== 'blank').map(([key, value]) => {
30
+ var _mapStyleConfig$key;
31
+ // @ts-ignore
32
+ const {
33
+ text,
34
+ img
35
+ } = (_mapStyleConfig$key = mapStyleConfig[key]) !== null && _mapStyleConfig$key !== void 0 ? _mapStyleConfig$key : {};
36
+ return {
37
+ text: text !== null && text !== void 0 ? text : key,
38
+ value,
39
+ img,
40
+ key
41
+ };
42
+ });
43
+ }
44
+ getMapStyle() {
45
+ return this.mapsService.getMapStyle();
46
+ }
47
+ onAdd() {
48
+ var _this$controlOption$o;
49
+ if (!((_this$controlOption$o = this.controlOption.options) !== null && _this$controlOption$o !== void 0 && _this$controlOption$o.length)) {
50
+ this.controlOption.options = this.getStyleOptions();
51
+ }
52
+ if (this.controlOption.defaultValue) {
53
+ var _this$controlOption$o2, _this$controlOption$o3;
54
+ const defaultValue = this.controlOption.defaultValue;
55
+ this.controlOption.defaultValue = (_this$controlOption$o2 = (_this$controlOption$o3 = this.controlOption.options.find(item => item.key === defaultValue)) === null || _this$controlOption$o3 === void 0 ? void 0 : _this$controlOption$o3.value) !== null && _this$controlOption$o2 !== void 0 ? _this$controlOption$o2 : defaultValue;
56
+ } else {
57
+ const defaultStyle = this.getMapStyle();
58
+ if (defaultStyle) {
59
+ this.controlOption.defaultValue = defaultStyle;
60
+ } else {
61
+ // @ts-ignore
62
+ this.mapsService.map.once('styledata', () => {
63
+ const mapboxStyle = this.mapsService.getMapStyle();
64
+ this.controlOption.defaultValue = mapboxStyle;
65
+ this.setSelectValue(mapboxStyle, false);
66
+ });
67
+ }
68
+ }
69
+ this.on('selectChange', this.onMapThemeChange);
70
+ return super.onAdd();
71
+ }
72
+ getIsMultiple() {
73
+ return false;
74
+ }
75
+ }
76
+ exports.default = exports.MapTheme = MapTheme;
@@ -0,0 +1,16 @@
1
+ import type { Position } from '@antv/l7-core';
2
+ import type { IControlOption } from './baseControl/control';
3
+ import Control from './baseControl/control';
4
+ export interface IMouseLocationControlOption extends IControlOption {
5
+ transform: (position: Position) => Position;
6
+ }
7
+ export { MouseLocation };
8
+ export default class MouseLocation extends Control<IMouseLocationControlOption> {
9
+ protected location: Position;
10
+ getLocation(): Position;
11
+ getDefault(option?: Partial<IMouseLocationControlOption>): IMouseLocationControlOption;
12
+ onAdd(): HTMLElement;
13
+ onRemove(): void;
14
+ protected onMouseMove: (e: any) => void;
15
+ protected insertLocation2HTML(position: Position): void;
16
+ }