From f2a09771336ad2ddff9c6d3542794a3554ba02c0 Mon Sep 17 00:00:00 2001 From: zengmingjie Date: Wed, 9 Jul 2025 09:50:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=AE=BE=E5=A4=87=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/myForm.vue | 25 +++++++++++++++++++------ src/components/myMarsmap.vue | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/myForm.vue b/src/components/myForm.vue index 55da610..44f6b2f 100644 --- a/src/components/myForm.vue +++ b/src/components/myForm.vue @@ -601,12 +601,25 @@ export default { return item.geometry.coordinates; }); - geojson.coordinates = geojson.coordinates.filter( - (item) => - Array.isArray(item) && - Array.isArray(item[0]) && - Array.isArray(item[0][0]) - ); + // 清理 geojson.coordinates,只保留第一个有效元素 + if ( + Array.isArray(geojson.coordinates) && + geojson.coordinates.length > 1 + ) { + // 寻找第一个有效元素(点、多边形或圆) + const firstValidItem = geojson.coordinates.find( + (item) => + Array.isArray(item) && + // 点坐标:[lng, lat] + ((item.length === 2 && + typeof item[0] === "number" && + typeof item[1] === "number") || + // 多边形或圆坐标:三维数组 + (Array.isArray(item[0]) && Array.isArray(item[0][0]))) + ); + // 如果找到有效元素,只保留它;否则置为空数组 + geojson.coordinates = firstValidItem ? [firstValidItem] : []; + } } this.ruleForm.geoJson = geojson; this.ruleForm.center = [ diff --git a/src/components/myMarsmap.vue b/src/components/myMarsmap.vue index aa85b4a..eb83bfa 100644 --- a/src/components/myMarsmap.vue +++ b/src/components/myMarsmap.vue @@ -336,7 +336,7 @@ export default { }, toGeoJSON() { if (this.typeOf === "pointP") { - // return this.graphicLayer.toGeoJSON({ noAlt: true }); + return this.graphicLayer.toGeoJSON({ noAlt: true }); } else { this.graphicLayer._graphicList._array.forEach((item) => { if (item.type === "billboard") {