|
@@ -325,9 +325,9 @@ export function useAMap(options) {
|
|
};
|
|
};
|
|
|
|
|
|
const drawData = (data) => {
|
|
const drawData = (data) => {
|
|
|
|
+ let res = [];
|
|
data.forEach((item) => {
|
|
data.forEach((item) => {
|
|
let graphic;
|
|
let graphic;
|
|
- // debugger
|
|
|
|
if (['rectangle', 'polygon'].includes(item.type)) {
|
|
if (['rectangle', 'polygon'].includes(item.type)) {
|
|
graphic = new AMap.Polygon({
|
|
graphic = new AMap.Polygon({
|
|
path: item.path,
|
|
path: item.path,
|
|
@@ -337,7 +337,11 @@ export function useAMap(options) {
|
|
fillColor: item.fillColor,
|
|
fillColor: item.fillColor,
|
|
fillOpacity: item.fillOpacity
|
|
fillOpacity: item.fillOpacity
|
|
});
|
|
});
|
|
|
|
+ graphic._opts.extData = {
|
|
|
|
+ id: item.id
|
|
|
|
+ };
|
|
map.add(graphic);
|
|
map.add(graphic);
|
|
|
|
+ res.push(graphic);
|
|
} else if (item.type === 'circle') {
|
|
} else if (item.type === 'circle') {
|
|
graphic = new AMap.Circle({
|
|
graphic = new AMap.Circle({
|
|
center: item.center,
|
|
center: item.center,
|
|
@@ -348,7 +352,11 @@ export function useAMap(options) {
|
|
fillColor: item.fillColor,
|
|
fillColor: item.fillColor,
|
|
fillOpacity: item.fillOpacity
|
|
fillOpacity: item.fillOpacity
|
|
});
|
|
});
|
|
|
|
+ graphic._opts.extData = {
|
|
|
|
+ id: item.id
|
|
|
|
+ };
|
|
map.add(graphic);
|
|
map.add(graphic);
|
|
|
|
+ res.push(graphic);
|
|
} else if (item.type === 'straightLine') {
|
|
} else if (item.type === 'straightLine') {
|
|
graphic = new AMap.Polyline({
|
|
graphic = new AMap.Polyline({
|
|
path: item.path,
|
|
path: item.path,
|
|
@@ -357,9 +365,14 @@ export function useAMap(options) {
|
|
strokeWeight: item.strokeWeight,
|
|
strokeWeight: item.strokeWeight,
|
|
strokeStyle: item.strokeStyle
|
|
strokeStyle: item.strokeStyle
|
|
});
|
|
});
|
|
|
|
+ graphic._opts.extData = {
|
|
|
|
+ id: item.id
|
|
|
|
+ };
|
|
map.add(graphic);
|
|
map.add(graphic);
|
|
|
|
+ res.push(graphic);
|
|
} else if (item.type === 'text') {
|
|
} else if (item.type === 'text') {
|
|
- addText(item);
|
|
|
|
|
|
+ const { text } = addText(item);
|
|
|
|
+ res.push(text);
|
|
} else if (item.type === 'measureArea') {
|
|
} else if (item.type === 'measureArea') {
|
|
graphic = new AMap.Polygon({
|
|
graphic = new AMap.Polygon({
|
|
path: item.path,
|
|
path: item.path,
|
|
@@ -369,21 +382,45 @@ export function useAMap(options) {
|
|
fillColor: item.fillColor,
|
|
fillColor: item.fillColor,
|
|
fillOpacity: item.fillOpacity
|
|
fillOpacity: item.fillOpacity
|
|
});
|
|
});
|
|
|
|
+ graphic._opts.extData = {
|
|
|
|
+ id: item.id
|
|
|
|
+ };
|
|
map.add(graphic);
|
|
map.add(graphic);
|
|
// 计算区域面积
|
|
// 计算区域面积
|
|
const area = Math.round(AMap.GeometryUtil.ringArea(item.path));
|
|
const area = Math.round(AMap.GeometryUtil.ringArea(item.path));
|
|
-
|
|
|
|
const text = new AMap.Text({
|
|
const text = new AMap.Text({
|
|
position: item.path[item.path.length - 1],
|
|
position: item.path[item.path.length - 1],
|
|
text: '区域面积' + area + '平方米',
|
|
text: '区域面积' + area + '平方米',
|
|
offset: new AMap.Pixel(-20, -20)
|
|
offset: new AMap.Pixel(-20, -20)
|
|
});
|
|
});
|
|
|
|
+ text._opts.extData = {
|
|
|
|
+ id: item.id
|
|
|
|
+ };
|
|
data.area = area;
|
|
data.area = area;
|
|
- map.add(text);
|
|
|
|
|
|
+ map.add([graphic, text]);
|
|
|
|
+ // res.push(text);
|
|
} else if (item.type === 'marker') {
|
|
} else if (item.type === 'marker') {
|
|
- addMarker([item], true);
|
|
|
|
|
|
+ // 创建标注点
|
|
|
|
+ const marker = new AMap.Marker({
|
|
|
|
+ position: new AMap.LngLat(item.longitude, item.latitude), // 标注点的位置
|
|
|
|
+ icon: new AMap.Icon({
|
|
|
|
+ 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) => {
|
|
const addText = (options) => {
|
|
// 文本覆盖物的样式
|
|
// 文本覆盖物的样式
|