Commit abe7e7ae authored by wanghao's avatar wanghao

1 气量监管-停气区域 多区域功能实现中。

parent 55dd880b
...@@ -36,10 +36,11 @@ ...@@ -36,10 +36,11 @@
return{ return{
gaoMap: null, gaoMap: null,
mouseTool: null, mouseTool: null,
drawLayers: [],
selectedLayerIndex: null,
overlays: null, overlays: null,
firstClick: 0, firstClick: 0,
nowMouseTarget: null, nowMouseTarget: null,
polygons: [],
currentPolygonId: 0, currentPolygonId: 0,
isClickPolygonFlag: false, isClickPolygonFlag: false,
opts:{ opts:{
...@@ -71,65 +72,148 @@ ...@@ -71,65 +72,148 @@
initMapEvent(){ initMapEvent(){
let that = this; let that = this;
this.gaoMap.map.on("click", () => { this.gaoMap.map.on("click", () => {
// if(that.nowMouseTarget && !that.isClickPolygonFlag){ if(that.nowMouseTarget && !that.isClickPolygonFlag){
// that.$confirm("是否重新绘制区域", { type: "warning" }) //that.$emit("input", []);
// .then(() => { that.mouseTool && that.mouseTool.close();
// that.$emit("input", []); that.nowMouseTarget.polygonEditor && that.nowMouseTarget.polygonEditor.close();
// that.mouseTool && that.mouseTool.close(); //that.gaoMap.map.remove(that.nowMouseTarget);
// that.nowMouseTarget.polygonEditor && that.nowMouseTarget.polygonEditor.close(); that.mouseTool && that.mouseTool.polygon(that.opts);
// that.gaoMap.map.remove(that.nowMouseTarget); if(!that.mouseTool){
// that.mouseTool && that.mouseTool.polygon(that.opts); that.initMouseEvent();
// if(!that.mouseTool){ }
// that.initMouseEvent(); that.isClickPolygonFlag = true;
// }
// that.isClickPolygonFlag = true;
// }).catch(() => {});
// }
this.drawLayers.push('[' + that.nowMouseTarget + ']');
that.nowMouseTarget.setMap(this.gaoMap.map);
this.selectedLayerIndex = this.drawLayers.length - 1; // 设置当前选中的图层索引
console.log("this.drawLayers = " + this.drawLayers)
that.nowMouseTarget = null;
}
}); });
}, },
//初始化鼠标事件 //初始化鼠标事件
initMouseEvent(){ initMouseEvent(){
let that = this;
this.gaoMap.map.plugin(["AMap.MouseTool"], () => { this.gaoMap.map.plugin(["AMap.MouseTool"], () => {
this.mouseTool = new AMap.MouseTool(this.gaoMap.map); that.mouseTool = new AMap.MouseTool(this.gaoMap.map);
this.mouseTool.polygon(this.opts); that.mouseTool.polygon(that.opts);
that.mouseTool.on('draw',function(e){
this.mouseTool.on('draw',function(e){ that.nowMouseTarget = e.obj;
const polygon = e.obj; that.$emit("input", that.nowMouseTarget._opts.path);
polygon.on('click',function () { that.isClickPolygonFlag = false;
this.gaoMap.map.plugin(["AMap.PolygonEditor"],(n) => { if(that.nowMouseTarget._opts.path.length > 2){
const polygonEditor = new AMap.PolygonEditor(this.gaoMap.map,polygon); that.mouseTool.close();
polygon.polygonEditor = polygonEditor; that.isClickPolygonFlag = true;
polygonEditor.on("removenode", (e) => { }
// that.$emit("input", e.target._opts.path); that.firstClick = 0;
// that.isClickPolygonFlag = true; e.obj.on('click',function () {
if(polygon._opts.path.length == 0){ that.isClickPolygonFlag = true;
setTimeout(() => { that.firstClick++;
that.mouseTool.polygon(that.opts); if(that.firstClick < 2){
}, 230); that.gaoMap.map.plugin(["AMap.PolygonEditor"],(n) => {
} const polygonEditor = new AMap.PolygonEditor(that.gaoMap.map,e.obj);
that.nowMouseTarget.polygonEditor = polygonEditor;
polygonEditor.on("removenode", (e) => {
that.$emit("input", e.target._opts.path);
that.isClickPolygonFlag = true;
if(that.nowMouseTarget._opts.path.length == 0){
setTimeout(() => {
that.mouseTool.polygon(that.opts);
}, 230);
}
});
polygonEditor.on("adjust",(e) =>{
that.$emit("input", e.target._opts.path);
})
polygonEditor.on("addnode",(e) =>{
that.$emit("input", e.target._opts.path);
})
polygonEditor.open();
}); });
polygonEditor.on("adjust",(e) =>{ }
// that.$emit("input", e.target._opts.path);
})
polygonEditor.on("addnode",(e) =>{
// that.$emit("input", e.target._opts.path);
})
polygonEditor.open();
});
}); });
polygon.on("mouseout", (e) => { e.obj.on("mouseout", (e) => {
// that.isClickPolygonFlag = false; that.isClickPolygonFlag = false;
}) })
//右键关闭区域编辑 //右键关闭区域编辑
polygon.on("rightclick",() => { e.obj.on("rightclick",() => {
// that.firstClick = 0; that.firstClick = 0;
polygon.polygonEditor.close(); that.nowMouseTarget.polygonEditor.close();
}) })
this.polygons.push({ id: this.currentPolygonId++, polygon }); //双击删除
e.obj.on('dblclick',(e) => {
console.log("this.e = " + e)
that.$confirm("是否删除此区域", { type: "warning" })
.then(() => {
console.log("确实要删除了。")
debugger;
let point = new AMap.LngLat(e.lngLat.lng, e.lngLat.lat);
for (let i = 0; i < this.drawLayers.length; i++) {
if (this.drawLayers[i].contains(point)){
console.log("第" + i + "个包含点击的坐标点,该删除");
}
}
}).catch(() => {});
})
}),
that.mouseTool.on('click',()=>{
if (!this.selectedLayerIndex) return;
let layer = this.drawLayers[this.selectedLayerIndex];
let point = new AMap.LngLat(e.lnglat.lng, e.lnglat.lat);
if (layer.contains(point)) {
// 点击点在区域内,则添加到区域中
layer.getPath().push(point);
} else {
// 点击点不在区域内,则删除最近的一个点
let path = layer.getPath();
let lastPoint = path[path.length - 1];
if (lastPoint.distance(point) > 50) {
path.pop();
}
}
}) })
}); });
}, },
handleDrawEnd(e){
let layer = e.layer;
this.drawLayers.push(layer);
layer.setMap(this.gaoMap.map);
// 设置当前选中的图层索引
this.selectedLayerIndex = this.drawLayers.length - 1;
},
handleClick(e){
if (!this.selectedLayerIndex) return;
let layer = this.drawLayers[this.selectedLayerIndex];
let point = new Amap.lngLat(e.lnglat.lng,e.lnglat.lat);
if (layer.contains(point)) {
//点击点在区域内,则添加到区域内
layer.getPath().push(point);
} else {
//点击点不在区域内,则删除最近的一个点
let path = layer.getPath();
let lastPoint = path[path.length - 1];
if (lastPoint.distance(point) > 50) {
path.pop();
}
}
},
selectLayer(index) {
this.selectedLayerIndex = index;
},
deleteLayer(index){
let layer = this.drawLayers[index];
layer.setMap(null);
this.drawLayers.splice(index,1);
if (this.selectedLayerIndex >= index) {
this.selectedLayerIndex = Math.max(0,this.selectedLayerIndex - 1);
}
},
//区域回显 //区域回显
loadArea(){ loadArea(){
const polygon = new AMap.Polygon({ const polygon = new AMap.Polygon({
......
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