运营区修改

This commit is contained in:
tx 2024-09-02 15:07:52 +08:00
parent 24c0a1a060
commit 28f5307624

View File

@ -408,6 +408,7 @@ export default {
showtable: true,
currentRow: null,
ischange: false,
currentPolygon: null,
//
rules: {
parkingName: [
@ -572,32 +573,114 @@ export default {
// this.initEditor();
},
initEditor(pathList) {
this.ischange = true;
var path1 = [];
path1 = JSON.parse(pathList) || [];
console.log('创建了');
this.ischange = true;
if(pathList==''){
pathList=null
}
// pathList
var path1;
try {
path1 = JSON.parse(pathList) || [];
} catch (e) {
console.error("Invalid JSON format in pathList:", e);
path1 = []; // JSON path1
}
var polygon1 = new AMap.Polygon({
path: path1,
});
this.map.add([polygon1]);
polyEditor = new AMap.PolygonEditor(this.map);
// console.log(polyEditor);
// console.dir(polyEditor);
polyEditor.on("add", (data) => {
// console.log(data);
this.coordList = data.lnglat;
var polygon = data.target;
polygon.on("dblclick", () => {
polyEditor.setTarget(polygon);
polyEditor.open();
//
this.currentPolygon = new AMap.Polygon({
path: path1,
fillColor: "#f0e68c", //
fillOpacity: 0.3, //
strokeColor: "#ffcc00",
strokeWeight: 2,
strokeStyle: "solid",
});
this.map.add([this.currentPolygon]);
polyEditor = new AMap.PolygonEditor(this.map);
polyEditor.setTarget(this.currentPolygon); //
//
polyEditor.on("add", (data) => {
this.coordList = data.lnglat;
var polygon = data.target;
polygon.on("dblclick", () => {
polyEditor.setTarget(polygon);
polyEditor.open();
});
//
this.currentPolygon = polygon;
});
this.currentPolygon.on("dblclick", () => {
polyEditor.setTarget(this.currentPolygon);
polyEditor.open();
});
return polyEditor;
},
clearPolygon() {
this.status = false;
if (this.currentPolygon) {
this.map.remove(this.currentPolygon); //
this.currentPolygon = null; //
}
if (polyEditor) {
polyEditor.close(); //
polyEditor.setTarget(null); //
polyEditor.off("add"); //
polyEditor.off("end"); //
}
//
this.coordList = [];
this.form.boundaryStr = "";
// this.form.longitude = '';
// this.form.latitude = '';
},
createPolygon() {
this.status = true;
if (!polyEditor) {
polyEditor = new AMap.PolygonEditor(this.map); // polyEditor
}
polyEditor.close(); //
polyEditor.setTarget(); //
polyEditor.open(); //
},
editClose: function () {
// console.log("this", this);
this.ischange = false;
let that = this;
polyEditor.on("end", function (event) {
// event.target
//
this.coordList = event.target.getPath();
// console.log("coordList", this.coordList);
let mapList = [];
this.coordList.forEach((v) => {
// console.log("v", v.lng, "--", v.lat);
mapList.push([v.lng, v.lat]);
});
let center = calculateCenter(mapList);
console.log(mapList, "mapListmapList");
// this.newmapList=mapList
let mapListJson = JSON.stringify(mapList);
console.log("mapListJson:" + mapListJson);
// console.log(this.form.boundaryStr,'this.form.boundaryStrthis.form.boundaryStr');
that.form.boundaryStr = mapListJson;
let centerArr = center.toString().split(",");
that.form.longitude = centerArr[0];
that.form.latitude = centerArr[1];
});
polygon1.on("dblclick", () => {
polyEditor.setTarget(polygon1);
polyEditor.open();
});
return polyEditor;
polyEditor.close();
this.sub();
},
scrollToRow(rowIndex) {
// DOM
@ -636,6 +719,9 @@ export default {
getArea(areaId) {
this.markers = [];
this.labels = [];
this.parkingList=[]
this.noParkingList=[]
this.noridingList=[]
getArea(areaId).then((response) => {
this.queryParams.areaId = response.data.areaId;
this.areaId = response.data.areaId;
@ -798,18 +884,7 @@ export default {
element.style.visibility = this.show ? "hidden" : "visible";
});
},
clearPolygon() {
this.status = false;
const polygons = polyEditor.getPolygons(); //
console.log(polygons, "polygonspolygons");
polygons.forEach((polygon) => {
this.map.remove(polygon); //
});
polyEditor.close(); //
//
this.coordList = "";
},
changeMapStyle() {
//
let defaultLayer = new AMap.TileLayer();
@ -832,9 +907,9 @@ export default {
this.type = "default";
}
},
start() {
this.timer = setInterval(this.echart, 1000); // : ;
},
// start() {
// this.timer = setInterval(this.echart, 1000); // : ;
// },
initAMap() {
AMapLoader.load({
key: globalConfig.aMap.key,
@ -864,13 +939,29 @@ export default {
// });
this.addArea(JSON.parse(this.areaList) || []);
this.parkingList.forEach((parking) => {
let boundary = [];
// boundaryStr JSON
if (parking.boundaryStr) {
try {
boundary = JSON.parse(parking.boundaryStr);
} catch (e) {
console.error(
"Invalid JSON in boundaryStr:",
parking.boundaryStr
);
boundary = []; // 使
}
}
this.addParking(
JSON.parse(parking.boundaryStr) || [],
boundary,
parking.parkingName,
parking.longitude,
parking.latitude,
parking.parkingId
);
this.addMarker2(
parking,
"https://lxnapi.ccttiot.com/FqcYf6ecsnbC0OT6YYAF5npgu-kh",
@ -878,12 +969,20 @@ export default {
"#1890ff"
);
});
this.noParkingList.forEach((noparking) => {
this.addNoParking(
JSON.parse(noparking.boundaryStr) || [],
noparking.parkingId
);
let boundaryStr = noparking.boundaryStr;
let parsedBoundary = [];
// boundaryStr JSON
if (boundaryStr && boundaryStr.trim() !== "") {
try {
parsedBoundary = JSON.parse(boundaryStr);
} catch (error) {
console.error("Error parsing noParking boundaryStr:", error);
}
}
this.addNoParking(parsedBoundary || [], noparking.parkingId);
this.addMarker2(
noparking,
"https://lxnapi.ccttiot.com/FjKE5PWbnEnZUq3k-wVIvV4lv8Ab",
@ -893,8 +992,21 @@ export default {
});
this.noridingList.forEach((noriding) => {
console.log(noriding, "noridingnoriding");
let boundaryStr = noriding.boundaryStr;
let parsedBoundary = [];
// boundaryStr
if (boundaryStr && boundaryStr.trim() !== "") {
try {
parsedBoundary = JSON.parse(boundaryStr);
} catch (error) {
console.error("Error parsing noriding boundaryStr:", error);
}
}
this.addNoriding(
JSON.parse(noriding.boundaryStr) || [],
parsedBoundary || [],
noriding.parkingName,
noriding.longitude,
noriding.latitude,
@ -1062,6 +1174,7 @@ export default {
this.labels.push(text);
},
addNoriding(data, title, lon, lat, parkingId) {
console.log("禁行区");
let polygon = new AMap.Polygon({
path: data,
fillColor: "#fff9e6", //
@ -1074,13 +1187,13 @@ export default {
});
polygon.on("mouseover", () => {
polygon.setOptions({
fillOpacity: 0.7,
fillColor: "#FFEBA4FF",
fillOpacity: 0.1,
fillColor: "#fff",
});
});
polygon.on("mouseout", () => {
polygon.setOptions({
fillOpacity: 0.5,
fillOpacity: 0.1,
fillColor: "#ffeba4",
});
});
@ -1093,38 +1206,10 @@ export default {
createPolygon() {
this.status = true;
polyEditor.close();
// polyEditor.close();
polyEditor.setTarget();
polyEditor.open();
},
editClose: function () {
// console.log("this", this);
this.ischange = false;
let that = this;
polyEditor.on("end", function (event) {
// event.target
//
this.coordList = event.target.getPath();
// console.log("coordList", this.coordList);
let mapList = [];
this.coordList.forEach((v) => {
// console.log("v", v.lng, "--", v.lat);
mapList.push([v.lng, v.lat]);
});
let center = calculateCenter(mapList);
console.log(mapList, "mapListmapList");
// this.newmapList=mapList
let mapListJson = JSON.stringify(mapList);
console.log("mapListJson:" + mapListJson);
// console.log(this.form.boundaryStr,'this.form.boundaryStrthis.form.boundaryStr');
that.form.boundaryStr = mapListJson;
let centerArr = center.toString().split(",");
that.form.longitude = centerArr[0];
that.form.latitude = centerArr[1];
});
polyEditor.close();
this.sub();
},
},
beforeDestroy() {
clearInterval(this.timer);