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