|
@@ -96,10 +96,12 @@ export function useDrawTool() {
|
|
|
closeDraw();
|
|
|
if (newOptions.graphicsType === 'circle') {
|
|
|
// 绘制圆形
|
|
|
- mouseTool.circle(drawOptions);
|
|
|
+ // mouseTool.circle(drawOptions);
|
|
|
+ drawCircle(drawOptions);
|
|
|
} else if (newOptions.graphicsType === 'rectangle') {
|
|
|
// 绘制矩形
|
|
|
- mouseTool.rectangle(drawOptions);
|
|
|
+ // mouseTool.rectangle(drawOptions);
|
|
|
+ drawRectangle(drawOptions);
|
|
|
} else if (newOptions.graphicsType === 'polygon') {
|
|
|
// 绘制多边形
|
|
|
mouseTool.polygon(drawOptions);
|
|
@@ -118,6 +120,16 @@ export function useDrawTool() {
|
|
|
// 测量面积
|
|
|
mouseTool.polygon(drawOptions);
|
|
|
}
|
|
|
+ if (newOptions.graphicsType !== 'anyLine') {
|
|
|
+ map.setStatus({
|
|
|
+ showIndoorMap: false,
|
|
|
+ dragEnable: false,
|
|
|
+ keyboardEnable: false,
|
|
|
+ doubleClickZoom: false,
|
|
|
+ zoomEnable: false,
|
|
|
+ rotateEnable: false
|
|
|
+ });
|
|
|
+ }
|
|
|
return drawOptions;
|
|
|
};
|
|
|
// 空间分析绘制图形
|
|
@@ -172,9 +184,75 @@ export function useDrawTool() {
|
|
|
data.id = id;
|
|
|
return { text, data };
|
|
|
};
|
|
|
- let anyLine = null;
|
|
|
+ let drawObj = null;
|
|
|
let drawing = false;
|
|
|
let path = null;
|
|
|
+ // 绘制圆
|
|
|
+ const drawCircle = (options) => {
|
|
|
+ map.on('touchstart', handleTouchStart);
|
|
|
+ map.on('touchmove', handleTouchMove1.bind(null, options));
|
|
|
+ document.addEventListener('touchend', handleTouchEnd.bind(null, options));
|
|
|
+ map.on('mousedown', handleTouchStart);
|
|
|
+ map.on('mousemove', handleTouchMove1.bind(null, options));
|
|
|
+ document.addEventListener('mouseup', handleTouchEnd.bind(null, options));
|
|
|
+ };
|
|
|
+ // 绘制矩形
|
|
|
+ const drawRectangle = (options) => {
|
|
|
+ map.on('touchstart', handleTouchStart);
|
|
|
+ map.on('touchmove', handleTouchMove2.bind(null, options));
|
|
|
+ document.addEventListener('touchend', handleTouchEnd.bind(null, options));
|
|
|
+ map.on('mousedown', handleTouchStart);
|
|
|
+ map.on('mousemove', handleTouchMove2.bind(null, options));
|
|
|
+ document.addEventListener('mouseup', handleTouchEnd.bind(null, options));
|
|
|
+ };
|
|
|
+ const handleTouchMove1 = (options, e) => {
|
|
|
+ if (!drawing) return;
|
|
|
+ if (drawObj) {
|
|
|
+ map.remove(drawObj);
|
|
|
+ }
|
|
|
+ const center = path[0]; // 获取圆心坐标
|
|
|
+ const radius = AMap.GeometryUtil.distance(center, e.lnglat);
|
|
|
+ drawObj = new AMap.Circle({
|
|
|
+ center: center, //圆心
|
|
|
+ radius: radius, //半径
|
|
|
+ strokeColor: options.strokeColor, //轮廓线颜色
|
|
|
+ strokeOpacity: options.strokeOpacity, //轮廓线透明度
|
|
|
+ strokeWeight: options.strokeWeight, //轮廓线宽度
|
|
|
+ fillOpacity: options.fillOpacity, //圆形填充透明度
|
|
|
+ fillColor: options.fillColor, //圆形填充颜色
|
|
|
+ });
|
|
|
+ map.add(drawObj);
|
|
|
+ };
|
|
|
+ const handleTouchMove2 = (options, e) => {
|
|
|
+ if (!drawing) return;
|
|
|
+ if (drawObj) {
|
|
|
+ map.remove(drawObj);
|
|
|
+ }
|
|
|
+ const center = path[0]; // 获取圆心坐标
|
|
|
+ const radius = AMap.GeometryUtil.distance(center, e.lnglat);
|
|
|
+ let minLngLat = e.lnglat;
|
|
|
+ let maxLngLat = path[0];
|
|
|
+ if (path[0].lng < e.lnglat.lng) {
|
|
|
+ minLngLat = path[0];
|
|
|
+ maxLngLat = e.lnglat;
|
|
|
+ }
|
|
|
+ const pathArray = [
|
|
|
+ [minLngLat.lng, minLngLat.lat],
|
|
|
+ [minLngLat.lng, maxLngLat.lat],
|
|
|
+ [maxLngLat.lng, maxLngLat.lat],
|
|
|
+ [maxLngLat.lng, minLngLat.lat],
|
|
|
+ [minLngLat.lng, minLngLat.lat],
|
|
|
+ ];
|
|
|
+ drawObj = new AMap.Polygon({
|
|
|
+ path: pathArray,
|
|
|
+ strokeColor: options.strokeColor,
|
|
|
+ strokeOpacity: options.strokeOpacity,
|
|
|
+ strokeWeight: options.strokeWeight,
|
|
|
+ fillColor: options.fillColor,
|
|
|
+ fillOpacity: options.fillOpacity
|
|
|
+ });
|
|
|
+ map.add(drawObj);
|
|
|
+ };
|
|
|
// 绘制任意线
|
|
|
const drawAnyLine = (options) => {
|
|
|
map.on('touchstart', handleTouchStart);
|
|
@@ -195,17 +273,17 @@ export function useDrawTool() {
|
|
|
rotateEnable: false
|
|
|
});
|
|
|
path = [e.lnglat];
|
|
|
- if (anyLine) {
|
|
|
- map.remove(anyLine);
|
|
|
+ if (drawObj) {
|
|
|
+ map.remove(drawObj);
|
|
|
}
|
|
|
};
|
|
|
const handleTouchMove = (options, e) => {
|
|
|
if (!drawing) return;
|
|
|
path.push(e.lnglat);
|
|
|
- if (anyLine) {
|
|
|
- map.remove(anyLine);
|
|
|
+ if (drawObj) {
|
|
|
+ map.remove(drawObj);
|
|
|
}
|
|
|
- anyLine = new AMap.Polyline({
|
|
|
+ drawObj = new AMap.Polyline({
|
|
|
path: path,
|
|
|
strokeColor: options.strokeColor,
|
|
|
strokeOpacity: options.strokeOpacity,
|
|
@@ -213,7 +291,7 @@ export function useDrawTool() {
|
|
|
strokeStyle: options.strokeStyle,
|
|
|
lineJoin: 'round'
|
|
|
});
|
|
|
- map.add(anyLine);
|
|
|
+ map.add(drawObj);
|
|
|
};
|
|
|
const handleTouchEnd = (options) => {
|
|
|
drawing = false;
|
|
@@ -232,9 +310,9 @@ export function useDrawTool() {
|
|
|
map.off('mousemove', handleTouchMove);
|
|
|
document.removeEventListener('mouseup', handleTouchEnd);
|
|
|
if (!!drawEndMethod) {
|
|
|
- drawEndMethod(options, anyLine);
|
|
|
+ drawEndMethod(options, drawObj);
|
|
|
}
|
|
|
- anyLine = null;
|
|
|
+ drawObj = null;
|
|
|
};
|
|
|
// 关闭绘制
|
|
|
const closeDraw = () => {
|