|
@@ -3,7 +3,7 @@ import { nanoid } from 'nanoid';
|
|
|
import { deepClone, initDrag } from '@/utils';
|
|
|
import { mergeGeoJsonPolygons, wgs_gcj_encrypts } from '@/utils/gisUtils';
|
|
|
import carImg from '@/assets/images/car.png';
|
|
|
-import { getImageUrl } from '@/views/globalMap/data/mapData';
|
|
|
+import { getImageUrl, iconList } from '@/views/globalMap/data/mapData';
|
|
|
|
|
|
export function useAMap(options) {
|
|
|
let AMap, map, scale, cluster;
|
|
@@ -230,42 +230,68 @@ export function useAMap(options) {
|
|
|
};
|
|
|
// 添加多个点2 后台做点聚合
|
|
|
const addMarker2 = (obj) => {
|
|
|
- if (plotLayers['points2']) {
|
|
|
- plotLayers['points2'] = new AMap.TileLayer({
|
|
|
+ // 新增图层
|
|
|
+ if (!plotLayers['points2']) {
|
|
|
+ plotLayers['points2'] = new AMap.OverlayGroup({
|
|
|
zIndex: 10, // 设置图层层级
|
|
|
visible: true
|
|
|
});
|
|
|
map.add(plotLayers['points2']);
|
|
|
+ } else {
|
|
|
+ plotLayers['points2'].clearOverlays();
|
|
|
+ addPoints = [];
|
|
|
}
|
|
|
Object.keys(obj).forEach((key: string) => {
|
|
|
- if (obj[key].videos && obj[key].videos.length > 1) {
|
|
|
+ const data = obj[key];
|
|
|
+ if (data.type === '3') {
|
|
|
// 聚合点
|
|
|
+ const div = document.createElement('div');
|
|
|
+ div.style.backgroundColor = 'rgba(78,179,211,.5)';
|
|
|
+ const size = Math.round(25 + Math.pow(1 / 5, 1 / 5) * 20);
|
|
|
+ div.style.width = div.style.height = size + 'px';
|
|
|
+ div.style.border = 'solid 1px rgba(78,179,211,1)';
|
|
|
+ div.style.borderRadius = size / 2 + 'px';
|
|
|
+ div.innerHTML = data.count;
|
|
|
+ div.style.lineHeight = size + 'px';
|
|
|
+ div.style.color = '#ffffff';
|
|
|
+ div.style.fontSize = '12px';
|
|
|
+ div.style.textAlign = 'center';
|
|
|
+ const marker = new AMap.Marker({
|
|
|
+ position: [data.longitude, data.latitude],
|
|
|
+ content: div,
|
|
|
+ anchor: 'center',
|
|
|
+ offset: new AMap.Pixel(0, 0),
|
|
|
+ map: map
|
|
|
+ });
|
|
|
+ marker.setContent(div);
|
|
|
+ marker.on('click', (e) => {
|
|
|
+ const bounds = e.target.getBounds();
|
|
|
+ map.setZoomAndCenter(map.getZoom() + 1, bounds.getCenter());
|
|
|
+ });
|
|
|
+ plotLayers['points2'].addOverlay(marker);
|
|
|
+ addPoints.push(data);
|
|
|
} else {
|
|
|
// 单个点
|
|
|
- const data = obj[key].videos[0];
|
|
|
- data.image = getImageUrl('31_lakes_video.png');
|
|
|
- data.imageHover = getImageUrl('31_lakes_video_hover.png');
|
|
|
- data.icon = data.image;
|
|
|
- data.size = [40, 40];
|
|
|
- data.id = data.cameraIndexCode;
|
|
|
- const content =
|
|
|
- '<div style="display: flex;flex-direction: column;align-items: center;justify-content: center">' +
|
|
|
- '<div style="background: url(' +
|
|
|
- data.icon +
|
|
|
- ') no-repeat; width: ' +
|
|
|
- data.size[0] +
|
|
|
- 'px;height: ' +
|
|
|
- data.size[1] +
|
|
|
- 'px;cursor: pointer; background-size: cover"></div>' +
|
|
|
- // '<div style="font-size: 36px;white-space: nowrap">'+ context.data[0].name +'</div>' +
|
|
|
- '</div>';
|
|
|
+ const iconConfig = iconList[data.dataType] || iconList.common;
|
|
|
+ data.image = iconConfig.image;
|
|
|
+ data.imageHover = iconConfig.imageHover;
|
|
|
+ data.size = iconConfig.size;
|
|
|
+ if (data.materia_name) {
|
|
|
+ data.name = data.materia_name;
|
|
|
+ }
|
|
|
+ if (data.dataType === 43) {
|
|
|
+ data.showName = true;
|
|
|
+ }
|
|
|
+ if (!data.id) {
|
|
|
+ data.id = nanoid(8);
|
|
|
+ }
|
|
|
+ data.lnglat = [data.longitude, data.latitude];
|
|
|
const marker = new AMap.Marker({
|
|
|
position: [data.longitude, data.latitude],
|
|
|
- content: content,
|
|
|
+ content: getContent(data.image, data.size),
|
|
|
anchor: 'bottom-center',
|
|
|
offset: new AMap.Pixel(0, 0),
|
|
|
- map: map,
|
|
|
- layer: plotLayers['points2']
|
|
|
+ map: map
|
|
|
});
|
|
|
marker.setExtData(data);
|
|
|
marker.on('click', function (e) {
|
|
@@ -273,15 +299,13 @@ export function useAMap(options) {
|
|
|
let index = 0;
|
|
|
let index2 = 0;
|
|
|
for (let i = 0; i < addPoints.length; i++) {
|
|
|
- if (addPoints[i].id === extData.id && addPoints[i].imageHover) {
|
|
|
- addPoints[i].icon = addPoints[i].imageHover;
|
|
|
- marker.setContent(content);
|
|
|
+ if (addPoints[i].id === extData.id) {
|
|
|
+ marker.setContent(getContent(data.imageHover, data.size));
|
|
|
index++;
|
|
|
} else if (!!clickMarker) {
|
|
|
const extData2 = clickMarker.getExtData();
|
|
|
if (addPoints[i].id === extData2.id) {
|
|
|
- addPoints[i].icon = addPoints[i].image;
|
|
|
- clickMarker.setContent(content);
|
|
|
+ clickMarker.setContent(getContent(extData2.image, extData2.size));
|
|
|
index2++;
|
|
|
}
|
|
|
}
|
|
@@ -289,14 +313,28 @@ export function useAMap(options) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- // addMarker(addPoints);
|
|
|
clickMarker = e.target;
|
|
|
options.onMarkerClick(extData);
|
|
|
});
|
|
|
+ plotLayers['points2'].addOverlay(marker);
|
|
|
addPoints.push(data);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
+ const getContent = (icon: string, size: number[]) => {
|
|
|
+ const content =
|
|
|
+ '<div style="display: flex;flex-direction: column;align-items: center;justify-content: center">' +
|
|
|
+ '<div style="background: url(' +
|
|
|
+ icon +
|
|
|
+ ') no-repeat; width: ' +
|
|
|
+ size[0] +
|
|
|
+ 'px;height: ' +
|
|
|
+ size[1] +
|
|
|
+ 'px;cursor: pointer; background-size: cover"></div>' +
|
|
|
+ // '<div style="font-size: 36px;white-space: nowrap">'+ context.data[0].name +'</div>' +
|
|
|
+ '</div>';
|
|
|
+ return content;
|
|
|
+ };
|
|
|
// 清除所有标加
|
|
|
const clearMarker = (id) => {
|
|
|
if (!cluster || !markers[id]) return;
|
|
@@ -304,7 +342,10 @@ export function useAMap(options) {
|
|
|
markers[id] = [];
|
|
|
};
|
|
|
const clearMarker2 = (id) => {
|
|
|
-
|
|
|
+ if (!!plotLayers['points2']) {
|
|
|
+ plotLayers['points2'].clearOverlays();
|
|
|
+ addPoints = [];
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
const handleHover = (extData, dataType) => {
|
|
@@ -337,14 +378,14 @@ export function useAMap(options) {
|
|
|
|
|
|
// 显示信息框
|
|
|
let infoWindow;
|
|
|
- const showInfo = (content, position, isCustom) => {
|
|
|
+ const showInfo = (content, position, offsetY, isCustom) => {
|
|
|
hideInfo();
|
|
|
// 实例化InfoWindow
|
|
|
infoWindow = new AMap.InfoWindow({
|
|
|
// 完全自定义
|
|
|
isCustom: isCustom,
|
|
|
autoMove: false,
|
|
|
- offset: new AMap.Pixel(0, -20) // 信息窗体的偏移量
|
|
|
+ offset: new AMap.Pixel(0, offsetY ? offsetY : 0) // 信息窗体的偏移量
|
|
|
// 可以根据需要设置其他InfoWindow的属性
|
|
|
});
|
|
|
const lnglat = new AMap.LngLat(position[0], position[1]);
|
|
@@ -366,8 +407,9 @@ export function useAMap(options) {
|
|
|
for (let i = 0; i < addPoints.length; i++) {
|
|
|
if (addPoints[i].id === extData.id) {
|
|
|
addPoints[i].icon = addPoints[i].image;
|
|
|
+ clickMarker.setContent(getContent(addPoints[i].icon, addPoints[i].size));
|
|
|
clickMarker = null;
|
|
|
- addMarker(addPoints);
|
|
|
+ // addMarker(addPoints);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -746,6 +788,7 @@ export function useAMap(options) {
|
|
|
addMarker2,
|
|
|
addSearchMarker,
|
|
|
clearMarker,
|
|
|
+ clearMarker2,
|
|
|
getScale,
|
|
|
showInfo,
|
|
|
hideInfo,
|