运营区修改

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, showtable: true,
currentRow: null, currentRow: null,
ischange: false, ischange: false,
currentPolygon: null,
// //
rules: { rules: {
parkingName: [ parkingName: [
@ -572,32 +573,114 @@ export default {
// this.initEditor(); // this.initEditor();
}, },
initEditor(pathList) { initEditor(pathList) {
this.ischange = true; console.log('创建了');
var path1 = []; this.ischange = true;
path1 = JSON.parse(pathList) || []; 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.currentPolygon = new AMap.Polygon({
}); path: path1,
this.map.add([polygon1]); fillColor: "#f0e68c", //
polyEditor = new AMap.PolygonEditor(this.map); fillOpacity: 0.3, //
// console.log(polyEditor); strokeColor: "#ffcc00",
// console.dir(polyEditor); strokeWeight: 2,
polyEditor.on("add", (data) => { strokeStyle: "solid",
// console.log(data); });
this.coordList = data.lnglat; this.map.add([this.currentPolygon]);
var polygon = data.target;
polygon.on("dblclick", () => { polyEditor = new AMap.PolygonEditor(this.map);
polyEditor.setTarget(polygon); polyEditor.setTarget(this.currentPolygon); //
polyEditor.open();
//
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.close();
polyEditor.setTarget(polygon1); this.sub();
polyEditor.open();
});
return polyEditor;
}, },
scrollToRow(rowIndex) { scrollToRow(rowIndex) {
// DOM // DOM
@ -636,6 +719,9 @@ export default {
getArea(areaId) { getArea(areaId) {
this.markers = []; this.markers = [];
this.labels = []; this.labels = [];
this.parkingList=[]
this.noParkingList=[]
this.noridingList=[]
getArea(areaId).then((response) => { getArea(areaId).then((response) => {
this.queryParams.areaId = response.data.areaId; this.queryParams.areaId = response.data.areaId;
this.areaId = response.data.areaId; this.areaId = response.data.areaId;
@ -798,18 +884,7 @@ export default {
element.style.visibility = this.show ? "hidden" : "visible"; 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() { changeMapStyle() {
// //
let defaultLayer = new AMap.TileLayer(); let defaultLayer = new AMap.TileLayer();
@ -832,9 +907,9 @@ export default {
this.type = "default"; this.type = "default";
} }
}, },
start() { // start() {
this.timer = setInterval(this.echart, 1000); // : ; // this.timer = setInterval(this.echart, 1000); // : ;
}, // },
initAMap() { initAMap() {
AMapLoader.load({ AMapLoader.load({
key: globalConfig.aMap.key, key: globalConfig.aMap.key,
@ -864,13 +939,29 @@ export default {
// }); // });
this.addArea(JSON.parse(this.areaList) || []); this.addArea(JSON.parse(this.areaList) || []);
this.parkingList.forEach((parking) => { 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( this.addParking(
JSON.parse(parking.boundaryStr) || [], boundary,
parking.parkingName, parking.parkingName,
parking.longitude, parking.longitude,
parking.latitude, parking.latitude,
parking.parkingId parking.parkingId
); );
this.addMarker2( this.addMarker2(
parking, parking,
"https://lxnapi.ccttiot.com/FqcYf6ecsnbC0OT6YYAF5npgu-kh", "https://lxnapi.ccttiot.com/FqcYf6ecsnbC0OT6YYAF5npgu-kh",
@ -878,12 +969,20 @@ export default {
"#1890ff" "#1890ff"
); );
}); });
this.noParkingList.forEach((noparking) => { this.noParkingList.forEach((noparking) => {
this.addNoParking( let boundaryStr = noparking.boundaryStr;
JSON.parse(noparking.boundaryStr) || [], let parsedBoundary = [];
noparking.parkingId
); // 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( this.addMarker2(
noparking, noparking,
"https://lxnapi.ccttiot.com/FjKE5PWbnEnZUq3k-wVIvV4lv8Ab", "https://lxnapi.ccttiot.com/FjKE5PWbnEnZUq3k-wVIvV4lv8Ab",
@ -893,8 +992,21 @@ export default {
}); });
this.noridingList.forEach((noriding) => { 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( this.addNoriding(
JSON.parse(noriding.boundaryStr) || [], parsedBoundary || [],
noriding.parkingName, noriding.parkingName,
noriding.longitude, noriding.longitude,
noriding.latitude, noriding.latitude,
@ -1062,6 +1174,7 @@ export default {
this.labels.push(text); this.labels.push(text);
}, },
addNoriding(data, title, lon, lat, parkingId) { addNoriding(data, title, lon, lat, parkingId) {
console.log("禁行区");
let polygon = new AMap.Polygon({ let polygon = new AMap.Polygon({
path: data, path: data,
fillColor: "#fff9e6", // fillColor: "#fff9e6", //
@ -1074,13 +1187,13 @@ export default {
}); });
polygon.on("mouseover", () => { polygon.on("mouseover", () => {
polygon.setOptions({ polygon.setOptions({
fillOpacity: 0.7, fillOpacity: 0.1,
fillColor: "#FFEBA4FF", fillColor: "#fff",
}); });
}); });
polygon.on("mouseout", () => { polygon.on("mouseout", () => {
polygon.setOptions({ polygon.setOptions({
fillOpacity: 0.5, fillOpacity: 0.1,
fillColor: "#ffeba4", fillColor: "#ffeba4",
}); });
}); });
@ -1093,38 +1206,10 @@ export default {
createPolygon() { createPolygon() {
this.status = true; this.status = true;
polyEditor.close(); // polyEditor.close();
polyEditor.setTarget(); polyEditor.setTarget();
polyEditor.open(); 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() { beforeDestroy() {
clearInterval(this.timer); clearInterval(this.timer);