Commit db351864 authored by 纪泽龙's avatar 纪泽龙

画线的时候直接计算长度

parent 69d7d39e
...@@ -189,6 +189,7 @@ export default { ...@@ -189,6 +189,7 @@ export default {
pipeName: "", pipeName: "",
pipeType: "1", pipeType: "1",
pipePressure: "1", pipePressure: "1",
pipeLength:"",
iconUrl: "", iconUrl: "",
}, },
dialogVisible: false, dialogVisible: false,
...@@ -235,6 +236,7 @@ export default { ...@@ -235,6 +236,7 @@ export default {
}, },
created() { created() {
console.log("lineData", this.lineData, this.lnglatsArr, this.pipeLength); console.log("lineData", this.lineData, this.lnglatsArr, this.pipeLength);
this.editForm.pipeLength=parseInt(this.pipeLength);
if (this.lineData?.pipeId) { if (this.lineData?.pipeId) {
this.editForm = { ...this.lineData }; this.editForm = { ...this.lineData };
} else { } else {
......
...@@ -101,6 +101,24 @@ class gaodeMap { ...@@ -101,6 +101,24 @@ class gaodeMap {
this.closeInfoWindow(); this.closeInfoWindow();
this.polyLinesColorClear(); this.polyLinesColorClear();
}); });
// 鼠标在地图上移动
this.myMap.on("mousemove", e => {
if (this.mouseTool.overlays.polyline.length > 0) {
const arr = this.mouseTool.overlays.polyline;
const length = parseInt(arr[0].getLength());
if (this.lengthMarker) {
this.myMap.remove(this.lengthMarker);
}
const position = e.lnglat;
this.lengthMarker = new AMap.Marker({
map: map,
position,
content: `<div style="color:#000;font-size:14px;display:inline-block;background:#fff;white-space:nowrap;padding:2px 5px;">
管道长度:<span>${length}米</span><div>`,
offset: new AMap.Pixel(20, 20)
});
}
});
this.myMap.on("moveend", () => { this.myMap.on("moveend", () => {
if (this.handleInfoWindowOpenFunc) { if (this.handleInfoWindowOpenFunc) {
this.handleInfoWindowOpenFunc(); this.handleInfoWindowOpenFunc();
...@@ -751,13 +769,19 @@ class gaodeMap { ...@@ -751,13 +769,19 @@ class gaodeMap {
createNewLine() { createNewLine() {
map.remove(this.markerOverlays); map.remove(this.markerOverlays);
console.log("创造一条线了啊"); console.log("创造一条线了啊");
// 线测距
map.plugin(["AMap.MouseTool"], () => {
this.ruler = new AMap.RangingTool(map);
this.ruler.turnOn();
// console.log(this.ruler.)
});
this.mouseTool.polyline({ this.mouseTool.polyline({
// bubbles:false, // bubbles:false,
strokeWeight: 4, strokeWeight: 4,
strokeColor: "#80d8ff", strokeColor: "#80d8ff",
extData: { extData: {
type: "newLine", type: "newLine",
//当前line状态 0:正常状态 1:正在编辑状态 //当前line状态 0:正常状态 1:正在编辑状态
isState: 0 isState: 0
} }
//同Polyline的Option设置 //同Polyline的Option设置
...@@ -770,6 +794,9 @@ class gaodeMap { ...@@ -770,6 +794,9 @@ class gaodeMap {
this.lineFlag = false; this.lineFlag = false;
if (this.mouserTool) { if (this.mouserTool) {
this.mouseTool.close(); this.mouseTool.close();
if (this.lengthMarker) {
this.myMap.remove(this.lengthMarker);
}
} }
if (this.newLineObj) { if (this.newLineObj) {
this.newLineObj.polyEditor.close(); this.newLineObj.polyEditor.close();
...@@ -1006,6 +1033,10 @@ class gaodeMap { ...@@ -1006,6 +1033,10 @@ class gaodeMap {
let that = this; let that = this;
this.markerOverlays = []; this.markerOverlays = [];
this.mouseTool.on("draw", function(e) { this.mouseTool.on("draw", function(e) {
// 如果正在测量就删掉
if (that.lengthMarker) {
that.myMap.remove(that.lengthMarker);
}
if (e.obj.getExtData().type != "newLine") { if (e.obj.getExtData().type != "newLine") {
map.remove(that.markerOverlays); map.remove(that.markerOverlays);
const device = that.createInfowindow("新增"); const device = that.createInfowindow("新增");
...@@ -1037,19 +1068,29 @@ class gaodeMap { ...@@ -1037,19 +1068,29 @@ class gaodeMap {
if (e.obj && e.obj.getExtData().type == "newLine") { if (e.obj && e.obj.getExtData().type == "newLine") {
console.log("挂上事件"); console.log("挂上事件");
// that.mouseTool.overlays.polyLine = [];
// 清空当前算距离用的内部数组
that.mouseTool.overlays.polyline = [];
that.newLineAddEvent(e.obj); that.newLineAddEvent(e.obj);
// 测距结束
that.ruler.turnOff(true);
// console.log(e.obj)
e.obj.on("mouseover", () => { e.obj.on("mouseover", () => {
e.obj.setOptions({ strokeColor: "#F7FE38" }); e.obj.setOptions({ strokeColor: "#F7FE38" });
}); });
e.obj.on("mouseout", () => { e.obj.on("mouseout", () => {
e.obj.setOptions({ strokeColor: "#80d8ff" }); e.obj.setOptions({ strokeColor: "#80d8ff" });
}); });
// 记录这条线 // 记录这条线
// console.log(e.obj.getPath().length) // console.log(e.obj.getPath().length)
// 如果只有一个点,并没有连成线的时候就不close 大于一个点的时候才执行clse // 如果只有一个点,并没有连成线的时候就不close 大于一个点的时候才执行clse
console.log(that.lineType); // console.log(that.lineType);
if (e.obj.getPath().length > 1) { if (e.obj.getPath().length > 1) {
that.newLineObj = e.obj; that.newLineObj = e.obj;
that.ruler.turnOff(true);
that.mouseTool.close(); that.mouseTool.close();
} else { } else {
// that.newLineObj = null; // that.newLineObj = null;
...@@ -1182,6 +1223,9 @@ class gaodeMap { ...@@ -1182,6 +1223,9 @@ class gaodeMap {
closeAddMarker() { closeAddMarker() {
this.mouseTool.close(); this.mouseTool.close();
map.remove(this.markerOverlays); map.remove(this.markerOverlays);
if (this.lengthMarker) {
this.myMap.remove(this.lengthMarker);
}
} }
// 只上图没功能 // 只上图没功能
onlyLine(obj) { onlyLine(obj) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment