|
@@ -35,7 +35,7 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
// 右键删除按钮
|
|
// 右键删除按钮
|
|
contextMenu.addItem(
|
|
contextMenu.addItem(
|
|
'删除',
|
|
'删除',
|
|
- function (event) {
|
|
|
|
|
|
+ function () {
|
|
deleteGraphics();
|
|
deleteGraphics();
|
|
},
|
|
},
|
|
0
|
|
0
|
|
@@ -65,8 +65,8 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
}
|
|
}
|
|
overlays.push(obj);
|
|
overlays.push(obj);
|
|
overlaysData.push(data);
|
|
overlaysData.push(data);
|
|
- debugger
|
|
|
|
commit(deepClone(overlaysData));
|
|
commit(deepClone(overlaysData));
|
|
|
|
+ debugger
|
|
if (typeof options.onDrawCompleted === 'function') {
|
|
if (typeof options.onDrawCompleted === 'function') {
|
|
options.onDrawCompleted(data, overlaysData, obj, event);
|
|
options.onDrawCompleted(data, overlaysData, obj, event);
|
|
}
|
|
}
|
|
@@ -95,7 +95,7 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
// 绘制图形
|
|
// 绘制图形
|
|
const drawGraphics = (newOptions: MouseTool) => {
|
|
const drawGraphics = (newOptions: MouseTool) => {
|
|
const data = getRgba(newOptions.color);
|
|
const data = getRgba(newOptions.color);
|
|
- if (['circle', 'rectangle', 'polygon'].includes(newOptions.graphicsType)) {
|
|
|
|
|
|
+ if (['circle', 'rectangle', 'polygon', 'measureArea'].includes(newOptions.graphicsType)) {
|
|
drawOptions = {
|
|
drawOptions = {
|
|
type: newOptions.graphicsType,
|
|
type: newOptions.graphicsType,
|
|
strokeColor: !!data.color ? data.color : newOptions.color,
|
|
strokeColor: !!data.color ? data.color : newOptions.color,
|
|
@@ -151,6 +151,9 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
} else if (newOptions.graphicsType === 'marker') {
|
|
} else if (newOptions.graphicsType === 'marker') {
|
|
// 绘制图标
|
|
// 绘制图标
|
|
mouseTool.marker(drawOptions);
|
|
mouseTool.marker(drawOptions);
|
|
|
|
+ } else if (newOptions.graphicsType === 'measureArea') {
|
|
|
|
+ // 测量面积
|
|
|
|
+ mouseTool.measureArea(drawOptions);
|
|
}
|
|
}
|
|
if (newOptions.graphicsType !== 'text') {
|
|
if (newOptions.graphicsType !== 'text') {
|
|
// 绘制完成事件
|
|
// 绘制完成事件
|
|
@@ -266,12 +269,12 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
} else if (data.type === 'polygon') {
|
|
} else if (data.type === 'polygon') {
|
|
// 绘制多边形
|
|
// 绘制多边形
|
|
createPolygon(data);
|
|
createPolygon(data);
|
|
- } else if (data.type === 'polygon') {
|
|
|
|
- // 绘制多边形
|
|
|
|
- createPolygon(data);
|
|
|
|
} else if (data.type === 'marker') {
|
|
} else if (data.type === 'marker') {
|
|
// 绘制图标
|
|
// 绘制图标
|
|
createMarker(data);
|
|
createMarker(data);
|
|
|
|
+ } else if (data.type === 'measureArea') {
|
|
|
|
+ // 绘制图标
|
|
|
|
+ createMeasureArea(data);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
// 创建圆形
|
|
// 创建圆形
|
|
@@ -283,7 +286,7 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
strokeOpacity: 1,
|
|
strokeOpacity: 1,
|
|
strokeWeight: options.lineWidth,
|
|
strokeWeight: options.lineWidth,
|
|
fillColor: options.color,
|
|
fillColor: options.color,
|
|
- fillOpacity: options.drawType === '1' ? 0 : 0.5,
|
|
|
|
|
|
+ fillOpacity: options.opacity,
|
|
strokeStyle: 'solid'
|
|
strokeStyle: 'solid'
|
|
});
|
|
});
|
|
overlays.push(circle);
|
|
overlays.push(circle);
|
|
@@ -300,7 +303,7 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
strokeOpacity: 1,
|
|
strokeOpacity: 1,
|
|
strokeWeight: options.lineWidth,
|
|
strokeWeight: options.lineWidth,
|
|
fillColor: options.color,
|
|
fillColor: options.color,
|
|
- fillOpacity: options.drawType === '1' ? 0 : 0.5,
|
|
|
|
|
|
+ fillOpacity: options.opacity,
|
|
strokeStyle: 'solid'
|
|
strokeStyle: 'solid'
|
|
});
|
|
});
|
|
overlays.push(rectangle);
|
|
overlays.push(rectangle);
|
|
@@ -318,7 +321,7 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
strokeOpacity: 1,
|
|
strokeOpacity: 1,
|
|
strokeWeight: options.lineWidth,
|
|
strokeWeight: options.lineWidth,
|
|
fillColor: options.color,
|
|
fillColor: options.color,
|
|
- fillOpacity: options.drawType === '1' ? 0 : 0.5,
|
|
|
|
|
|
+ fillOpacity: options.opacity,
|
|
strokeStyle: 'solid'
|
|
strokeStyle: 'solid'
|
|
});
|
|
});
|
|
overlays.push(polygon);
|
|
overlays.push(polygon);
|
|
@@ -326,7 +329,6 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
};
|
|
};
|
|
// 绘制图标
|
|
// 绘制图标
|
|
const createMarker = (options: any) => {
|
|
const createMarker = (options: any) => {
|
|
- debugger
|
|
|
|
const marker = new AMap.Marker({
|
|
const marker = new AMap.Marker({
|
|
position: new AMap.LngLat(116.38, 39.92),
|
|
position: new AMap.LngLat(116.38, 39.92),
|
|
// 将一张图片的地址设置为 icon
|
|
// 将一张图片的地址设置为 icon
|
|
@@ -335,7 +337,32 @@ export function useDrawTool(options: DrawToolOptions) {
|
|
anchor: 'bottom-center'
|
|
anchor: 'bottom-center'
|
|
});
|
|
});
|
|
map.add(marker);
|
|
map.add(marker);
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
+ // 绘制测量面积
|
|
|
|
+ const createMeasureArea = (options: any) => {
|
|
|
|
+ // 将数组转换为AMap.LngLat对象的数组
|
|
|
|
+ const path = options.path.map((coord) => {
|
|
|
|
+ return new AMap.LngLat(coord[0], coord[1]);
|
|
|
|
+ });
|
|
|
|
+ const polygon = new AMap.Polygon({
|
|
|
|
+ path: path,
|
|
|
|
+ strokeColor: options.color,
|
|
|
|
+ strokeOpacity: 1,
|
|
|
|
+ strokeWeight: options.lineWidth,
|
|
|
|
+ fillColor: options.color,
|
|
|
|
+ fillOpacity: options.opacity,
|
|
|
|
+ strokeStyle: 'solid'
|
|
|
|
+ });
|
|
|
|
+ // 计算区域面积
|
|
|
|
+ const area = Math.round(AMap.GeometryUtil.ringArea(options.path));
|
|
|
|
+ const text = new AMap.Text({
|
|
|
|
+ position: path[path.length - 1],
|
|
|
|
+ text: '区域面积' + area + '平方米',
|
|
|
|
+ offset: new AMap.Pixel(-20, -20)
|
|
|
|
+ });
|
|
|
|
+ map.add(polygon);
|
|
|
|
+ map.add(text);
|
|
|
|
+ };
|
|
// 处理撤销
|
|
// 处理撤销
|
|
const handleUndo = () => {
|
|
const handleUndo = () => {
|
|
const previous = history.value[history.value.length - 2];
|
|
const previous = history.value[history.value.length - 2];
|