forked from drone/command-center-dashboard

罗广辉
2025-04-07 9825e6086a58c3ff9a9c68a07afffb22a3c31f6d
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;
}