From 5fc6e09508182701f31f017453b5c116adf40f7f Mon Sep 17 00:00:00 2001
From: wangjuncheng <1>
Date: 星期四, 17 四月 2025 10:44:30 +0800
Subject: [PATCH] change

---
 src/utils/wktUtils.js |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/utils/wktUtils.js b/src/utils/wktUtils.js
index e1c19b7..55cc6be 100644
--- a/src/utils/wktUtils.js
+++ b/src/utils/wktUtils.js
@@ -1,26 +1,31 @@
 /**
- * 灏嗘櫘閫氱粡绾害鏁扮粍杞崲涓烘爣鍑嗙殑 MULTIPOLYGON WKT 鏍煎紡
- * @param {Array<Array<number>>} coordinates - 缁忕含搴︽暟缁勶紝姣忎釜鍏冪礌鏄竴涓� [缁忓害, 绾害] 鐨勭偣
+ * 灏嗗涓杈瑰舰鐨勭粡绾害鏁扮粍杞崲涓烘爣鍑嗙殑 MULTIPOLYGON WKT 鏍煎紡
+ * @param {Array<Array<Array<number>>>} multiPolygonCoordinates - 澶氫釜澶氳竟褰㈢殑鍧愭爣鏁扮粍
  * @returns {string} 鏍囧噯鍖栫殑 WKT 鏍煎紡瀛楃涓�
  */
-export function convertToWKT(coordinates) {
+export function convertToWKT(multiPolygonCoordinates) {
     // 妫�鏌ヨ緭鍏ユ槸鍚︿负闈炵┖鏁扮粍
-    if (!Array.isArray(coordinates) || coordinates.length === 0) {
-        throw new Error("Invalid input: 'coordinates' must be a non-empty array of [longitude, latitude] points.");
+    if (!Array.isArray(multiPolygonCoordinates) || multiPolygonCoordinates.length === 0) {
+        throw new Error("Invalid input: 'multiPolygonCoordinates' must be a non-empty array of polygons.");
     }
 
-    // 妫�鏌ユ瘡涓偣鏄惁鏄湁鏁堢殑 [缁忓害, 绾害] 鏁扮粍
-    for (const point of coordinates) {
-        if (!Array.isArray(point) || point.length !== 2 || typeof point[0] !== "number" || typeof point[1] !== "number") {
-            throw new Error("Invalid input: Each coordinate must be an array of two numbers [longitude, latitude].");
+    // 杞崲姣忎釜澶氳竟褰㈢殑鍧愭爣
+    const polygons = multiPolygonCoordinates.map(polygon => {
+        if (!Array.isArray(polygon) || polygon.length === 0) {
+            throw new Error("Invalid input: Each polygon must be a non-empty array of [longitude, latitude] points.");
         }
-    }
 
-    // 灏嗙粡绾害鏁扮粍杞崲涓� WKT 鏍煎紡鐨勫潗鏍囧瓧绗︿覆
-    const wktCoordinates = coordinates
-        .map(([longitude, latitude]) => `${longitude} ${latitude}`)
-        .join(",");
+        // 妫�鏌ユ瘡涓偣鏄惁鏄湁鏁堢殑 [缁忓害, 绾害] 鏁扮粍
+        for (const point of polygon) {
+            if (!Array.isArray(point) || point.length !== 2 || typeof point[0] !== "number" || typeof point[1] !== "number") {
+                throw new Error("Invalid input: Each coordinate must be an array of two numbers [longitude, latitude].");
+            }
+        }
+
+        // 灏嗘瘡涓杈瑰舰鐨勫潗鏍囪浆鎹负 WKT 鏍煎紡鐨勫瓧绗︿覆
+        return `((${polygon.map(([lng, lat]) => `${lng} ${lat}`).join(",")}))`;
+    });
 
     // 鏋勫缓鏍囧噯鐨� MULTIPOLYGON WKT 鏍煎紡
-    return `MULTIPOLYGON(((${wktCoordinates})))`;
+    return `MULTIPOLYGON(${polygons.join(",")})`;
 }
\ No newline at end of file

--
Gitblit v1.9.3