|
@@ -322,6 +322,7 @@ export function useAMap(options) {
|
|
|
};
|
|
|
|
|
|
const drawData = (data) => {
|
|
|
+ let res = [];
|
|
|
data.forEach((item) => {
|
|
|
let graphic;
|
|
|
if (['rectangle', 'polygon'].includes(item.type)) {
|
|
@@ -333,7 +334,11 @@ export function useAMap(options) {
|
|
|
fillColor: item.fillColor,
|
|
|
fillOpacity: item.fillOpacity
|
|
|
});
|
|
|
+ graphic._opts.extData = {
|
|
|
+ id: item.id
|
|
|
+ };
|
|
|
map.add(graphic);
|
|
|
+ res.push(graphic);
|
|
|
} else if (item.type === 'circle') {
|
|
|
graphic = new AMap.Circle({
|
|
|
center: item.center,
|
|
@@ -344,7 +349,11 @@ export function useAMap(options) {
|
|
|
fillColor: item.fillColor,
|
|
|
fillOpacity: item.fillOpacity
|
|
|
});
|
|
|
+ graphic._opts.extData = {
|
|
|
+ id: item.id
|
|
|
+ };
|
|
|
map.add(graphic);
|
|
|
+ res.push(graphic);
|
|
|
} else if (item.type === 'straightLine') {
|
|
|
graphic = new AMap.Polyline({
|
|
|
path: item.path,
|
|
@@ -353,9 +362,14 @@ export function useAMap(options) {
|
|
|
strokeWeight: item.strokeWeight,
|
|
|
strokeStyle: item.strokeStyle
|
|
|
});
|
|
|
+ graphic._opts.extData = {
|
|
|
+ id: item.id
|
|
|
+ };
|
|
|
map.add(graphic);
|
|
|
+ res.push(graphic);
|
|
|
} else if (item.type === 'text') {
|
|
|
- addText(item);
|
|
|
+ const { text } = addText(item);
|
|
|
+ res.push(text);
|
|
|
} else if (item.type === 'measureArea') {
|
|
|
graphic = new AMap.Polygon({
|
|
|
path: item.path,
|
|
@@ -365,6 +379,9 @@ export function useAMap(options) {
|
|
|
fillColor: item.fillColor,
|
|
|
fillOpacity: item.fillOpacity
|
|
|
});
|
|
|
+ graphic._opts.extData = {
|
|
|
+ id: item.id
|
|
|
+ };
|
|
|
map.add(graphic);
|
|
|
// 计算区域面积
|
|
|
const area = Math.round(AMap.GeometryUtil.ringArea(item.path));
|
|
@@ -373,25 +390,34 @@ export function useAMap(options) {
|
|
|
text: '区域面积' + area + '平方米',
|
|
|
offset: new AMap.Pixel(-20, -20)
|
|
|
});
|
|
|
+ text._opts.extData = {
|
|
|
+ id: item.id
|
|
|
+ };
|
|
|
data.area = area;
|
|
|
- map.add(text);
|
|
|
+ map.add([graphic, text]);
|
|
|
+ // res.push(text);
|
|
|
} else if (item.type === 'marker') {
|
|
|
// 创建标注点
|
|
|
const marker = new AMap.Marker({
|
|
|
position: new AMap.LngLat(item.longitude, item.latitude), // 标注点的位置
|
|
|
icon: new AMap.Icon({
|
|
|
- size: item.size, //图标所处区域大小
|
|
|
+ size: item.size, //图标所处区域大小
|
|
|
image: item.icon
|
|
|
}),
|
|
|
size: item.size
|
|
|
});
|
|
|
+ marker._opts.extData = {
|
|
|
+ id: item.id
|
|
|
+ };
|
|
|
marker.setLabel({
|
|
|
content: '<div>' + item.title + '</div>',
|
|
|
direction: 'top'
|
|
|
});
|
|
|
map.add(marker);
|
|
|
+ res.push(marker);
|
|
|
}
|
|
|
});
|
|
|
+ return res;
|
|
|
};
|
|
|
const addText = (options) => {
|
|
|
// 文本覆盖物的样式
|