更改防区点击定位之后添加失败问题

This commit is contained in:
zengmingjie 2025-07-08 22:31:25 +08:00
parent 1ee3fe56e2
commit 837255691e
4 changed files with 111 additions and 62 deletions

View File

@ -121,6 +121,7 @@ body {
align-items: center; align-items: center;
margin-right: 40px; margin-right: 40px;
margin-top: 10px; margin-top: 10px;
z-index: 10;
.menuItem { .menuItem {
width: 305px; width: 305px;
display: flex; display: flex;

View File

@ -423,7 +423,8 @@ export default {
} }
if (newVal.geojson === undefined) { if (newVal.geojson === undefined) {
if (this.$refs.myMarsmap !== undefined) { if (this.$refs.myMarsmap !== undefined) {
this.$refs.myMarsmap[0].clearDraw(); console.log(111122223333);
// this.$refs.myMarsmap[0].clearDraw();
} }
} }
} }
@ -536,37 +537,77 @@ export default {
}; };
if (this.$refs.myMarsmap) { if (this.$refs.myMarsmap) {
let toJson = this.$refs.myMarsmap[0].toGeoJSON(); let toJson = this.$refs.myMarsmap[0].toGeoJSON();
if (toJson.features.length !== 0) {
console.log(toJson, "toJson");
// //
geojson.coordinates = toJson.features.map((item) => { geojson.coordinates = toJson.features.map((item) => {
if (item.properties.type === "polygon") { if (item.properties.type === "polygon") {
item.geometry.coordinates[0][ // coordinates
item.geometry.coordinates[0].length if (
] = item.geometry.coordinates[0][0]; Array.isArray(item.geometry.coordinates) &&
Array.isArray(item.geometry.coordinates[0]) &&
Array.isArray(item.geometry.coordinates[0][0])
) {
let coords = item.geometry.coordinates[0];
if (coords.length > 1) {
let firstCoord = coords[0];
let lastCoord = coords[coords.length - 1];
//
while (
coords.length > 1 &&
lastCoord[0] === firstCoord[0] &&
lastCoord[1] === firstCoord[1]
) {
coords.pop();
// lastCoord
if (coords.length > 1) {
lastCoord = coords[coords.length - 1];
}
}
//
if (
coords.length > 1 &&
(firstCoord[0] !== lastCoord[0] ||
firstCoord[1] !== lastCoord[1])
) {
//
item.geometry.coordinates[0].push(firstCoord);
}
}
}
} else if (item.properties.type === "pointP") { } else if (item.properties.type === "pointP") {
console.log(item.geometry.coordinates); console.log(item.geometry.coordinates, "112233");
} else if (item.properties.type === "circle") { } else if (item.properties.type === "circle") {
// eslint-disable-next-line no-undef
const positions = mars3d.PolyUtil.getEllipseOuterPositions({ const positions = mars3d.PolyUtil.getEllipseOuterPositions({
position: item.geometry.coordinates, position: item.geometry.coordinates,
radius: item.properties.style.radius radius: item.properties.style.radius
}); });
item.geometry.coordinates = [[]]; item.geometry.coordinates = [[]];
positions.forEach((el) => { positions.forEach((el) => {
// eslint-disable-next-line no-undef
mars3d.LngLatPoint.fromCartesian(el).toArray(),
item.geometry.coordinates[0].push( item.geometry.coordinates[0].push(
// eslint-disable-next-line no-undef
mars3d.LngLatPoint.fromCartesian(el).toArray() mars3d.LngLatPoint.fromCartesian(el).toArray()
); );
}); });
console.log(item.geometry.coordinates); console.log(item.geometry.coordinates);
//
if (item.geometry.coordinates[0].length > 0) {
item.geometry.coordinates[0].push( item.geometry.coordinates[0].push(
item.geometry.coordinates[0][0] item.geometry.coordinates[0][0]
); );
// console.log(item.geometry.coordinates); }
} }
return item.geometry.coordinates; return item.geometry.coordinates;
}); });
geojson.coordinates = geojson.coordinates.filter(
(item) =>
Array.isArray(item) &&
Array.isArray(item[0]) &&
Array.isArray(item[0][0])
);
}
this.ruleForm.geoJson = geojson; this.ruleForm.geoJson = geojson;
this.ruleForm.center = [ this.ruleForm.center = [
this.$refs.myMarsmap[0].lonData, this.$refs.myMarsmap[0].lonData,

View File

@ -99,15 +99,14 @@ export default {
deep: true, deep: true,
immediate: true, immediate: true,
handler(newVal) { handler(newVal) {
console.log("newVal1111", newVal);
if (newVal) { if (newVal) {
this.jsonData = JSON.parse(newVal); this.jsonData = JSON.parse(newVal);
if (this.jsonData) { if (this.jsonData) {
if (newVal) {
this.showRegion(this.jsonData, "geojson"); this.showRegion(this.jsonData, "geojson");
} }
} }
} }
}
}, },
mapData: { mapData: {
deep: true, deep: true,
@ -121,9 +120,9 @@ export default {
this.lonData = ""; this.lonData = "";
this.latData = ""; this.latData = "";
} }
console.log("mapData发生变化", newVal);
if (this.lonData && this.latData) { if (this.lonData && this.latData) {
if (this.lonData && this.latData) { if (this.lonData && this.latData) {
this.isinputDisabled = true;
this.deviceDrid(this.lonData, this.latData); this.deviceDrid(this.lonData, this.latData);
} }
} }
@ -217,6 +216,7 @@ export default {
} }
if (this.lonData && this.latData) { if (this.lonData && this.latData) {
this.deviceDrid(this.lonData, this.latData); this.deviceDrid(this.lonData, this.latData);
this.isinputDisabled = true;
} }
}, },
lineClicks(val) { lineClicks(val) {
@ -328,15 +328,15 @@ export default {
} }
}, },
clearDraw() { clearDraw() {
console.log(111);
this.isinputDisabled = false; this.isinputDisabled = false;
if (this.graphicLayer) { if (this.graphicLayer) {
this.graphicLayer.clear(); this.graphicLayer.clear();
} }
}, },
toGeoJSON() { toGeoJSON() {
console.log(this.graphicLayer, this.typeOf, "this.graphicLayer");
if (this.typeOf === "pointP") { if (this.typeOf === "pointP") {
return this.graphicLayer.toGeoJSON({ noAlt: true }); // return this.graphicLayer.toGeoJSON({ noAlt: true });
} else { } else {
this.graphicLayer._graphicList._array.forEach((item) => { this.graphicLayer._graphicList._array.forEach((item) => {
if (item.type === "billboard") { if (item.type === "billboard") {
@ -347,6 +347,7 @@ export default {
} }
}, },
showRegion(value, type) { showRegion(value, type) {
this.clearDraw();
let geojson = {}; let geojson = {};
if (type === "uploadGeojson") { if (type === "uploadGeojson") {
if (this.graphicLayer._graphicList.length === 0) { if (this.graphicLayer._graphicList.length === 0) {
@ -387,7 +388,6 @@ export default {
} }
}, },
deviceDrid(lon, lat) { deviceDrid(lon, lat) {
// this.clearDraw();
console.log(this.graphicLayer, "this.graphicLayer"); console.log(this.graphicLayer, "this.graphicLayer");
if (this.graphicLayer) { if (this.graphicLayer) {
this.graphicLayer.eachGraphic((item) => { this.graphicLayer.eachGraphic((item) => {

View File

@ -216,9 +216,9 @@ export default {
}, },
// //
determine(value) { determine(value) {
let params = {}; let params = { ...value };
params = value;
console.log(params, "params"); console.log(params, "params");
if (params.geoJson.coordinates.length !== 0) {
params.regionJson = JSON.stringify(params.geoJson); params.regionJson = JSON.stringify(params.geoJson);
params.lon = params.center[0]; params.lon = params.center[0];
@ -234,6 +234,8 @@ export default {
if (res.code === 0) { if (res.code === 0) {
this.$message.success("新增成功"); this.$message.success("新增成功");
this.headdenForm({}, "search"); this.headdenForm({}, "search");
} else {
this.$message.error(res.msg);
} }
}) })
.catch((err) => { .catch((err) => {
@ -244,6 +246,8 @@ export default {
if (res.code === 0) { if (res.code === 0) {
this.$message.success("编辑成功"); this.$message.success("编辑成功");
this.headdenForm({}, "search"); this.headdenForm({}, "search");
} else {
this.$message.error(res.msg);
} }
}); });
} }
@ -251,6 +255,9 @@ export default {
} else { } else {
this.$message.error("请选择地图上的经纬度"); this.$message.error("请选择地图上的经纬度");
} }
} else {
this.$message.error("请绘制地图上的防区");
}
}, },
// //
headdenForm(value, type) { headdenForm(value, type) {