From 9825e6086a58c3ff9a9c68a07afffb22a3c31f6d Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Mon, 07 Apr 2025 16:29:40 +0800
Subject: [PATCH] feat: 解析kmz文件逻辑
---
src/utils/cesium/kmz.js | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/src/utils/cesium/kmz.js b/src/utils/cesium/kmz.js
index 4ef1af9..a6cf77f 100644
--- a/src/utils/cesium/kmz.js
+++ b/src/utils/cesium/kmz.js
@@ -207,3 +207,32 @@
}
}
}
+
+
+export function removeTextKey(obj) {
+ if (typeof obj !== 'object' || obj === null) {
+ // 如果是数值字符串,转换为数值
+ if (typeof obj === 'string' && /^-?\d+(\.\d+)?$/.test(obj)) {
+ return Number(obj);
+ }
+ return obj;
+ }
+
+ if (Array.isArray(obj)) {
+ return obj.map(item => removeTextKey(item));
+ }
+
+ if (Object.prototype.hasOwnProperty.call(obj, '#text')) {
+ // 如果 #text 的值是数值字符串,转换为数值
+ const textValue = obj['#text'];
+ return typeof textValue === 'string' && /^-?\d+(\.\d+)?$/.test(textValue) ? Number(textValue) : textValue;
+ }
+
+ const newObj = {};
+ for (const key in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
+ newObj[key] = Object.keys(obj[key]).length === 0 ? '' : removeTextKey(obj[key]);
+ }
+ }
+ return newObj;
+}
--
Gitblit v1.9.3