diff --git a/src/components/myForm.vue b/src/components/myForm.vue index d0d2d04..3aae2ad 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 e6d650d..0654e60 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") {