This commit is contained in:
zk
2023-12-11 18:34:15 +08:00
parent e449d5687b
commit 35f21a4342
11 changed files with 380 additions and 52 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

+4
View File
@@ -1,4 +1,5 @@
import { mapIcon1, mapIcon2, mapIcon3, mapIcon4 } from '/@/components/chinaMap/chinaHooks.ts';
import { watchIcon } from '/@/components/secondaryScreen/secondMap/secondMapHooks.ts';
/**
* @desc 创建icon
@@ -33,6 +34,9 @@ export function typeToIcon(type: string) {
if (type == '4') {
return createIcon({ icon: mapIcon3, iconSize, imageSize });
}
if (type == '6') {
return createIcon({ icon: watchIcon, iconSize: [21, 44], imageSize: [21, 44] });
}
}
/**
+9 -6
View File
@@ -2,6 +2,7 @@ import china from '/@/assets/lngLat/china.ts';
import chinaInner from '/@/assets/lngLat/chinaInner.ts';
import { createCircle, createIcon, typeToIcon } from '/@/assets/mapUtils/commonFun.ts';
import { aircraftContent, alarmIcon } from '/@/components/chinaMap/chinaHooks.ts';
import { isFunction } from '/@/utils/is.ts';
export const defaultOption = {
center: [106.3, 37.87], //地图中心点
@@ -87,7 +88,7 @@ export const Map = {
* @desc 创建覆盖物组,用于批量处理点 (控制显隐,点击事件等)
* @param result
*/
createOverlay(result) {
createOverlay(result, { extOption = {}, content }, callback) {
this.removeOverlayGroup();
this.overlayGroup = new AMap.OverlayGroup();
for (let i = 0; i < result.length; i++) {
@@ -104,10 +105,12 @@ export const Map = {
icon: startIcon, //启用点击事件 如果需要点击事件,必须开启
clickable: true, //点额外携带的数据,用户自定义属性,支持JavaScript API任意数据类型
extData: result[i],
label: {
content: isFunction(content) && content(result[i]),
},
...extOption,
});
// 可以调用setExtData()设置自定义属性
//startMarker.setExtData('222')
//将组 挂载到地图上
this.overlayGroup.setMap(this.map);
//将需要批量控制的点放到一个组中,通过控制组,就可以操作组内所有所有覆盖物
@@ -115,10 +118,10 @@ export const Map = {
}
this.overlayGroup.on('click', function (e) {
//e.target触发事件的点对象
console.log(e.target);
//拿到点中携带的数据
console.log(e.target.getExtData());
// console.log(e.target.getExtData());
if (!isFunction(callback)) return;
callback(e.target.getExtData());
});
},
clearOverlay() {