GuLiMmo
2024-03-06 52a426373c619415f876952b0de04af82564dd96
src/utils/cesium/use-kmz-tsa.ts
@@ -1,16 +1,17 @@
import { ref } from 'vue'
import { analyzeKmzFile, getKmlParams } from '/@/utils/cesium/kmz'
import { analyzeKmzFile, getKmlParams, generateKmlFormat } from '/@/utils/cesium/kmz'
const useKMLTsa = () => {
  const kmzStr = ref('')
const kmlStr = ref('')
  const init = async (fileUrl: string, fileContent ?: string) => {
const useKmzTsa = () => {
  const init = async (fileUrl: string, fileContent?: string) => {
    const kmzRes: string = await analyzeKmzFile(fileUrl)
    if (fileContent) {
      kmzStr.value = fileContent
      kmlStr.value = fileContent
      return false
    }
    kmzStr.value = kmzRes
    kmlStr.value = kmzRes
    return kmzRes
  }
  const create = () => {
@@ -29,22 +30,54 @@
      </Document>
    </kml>
    `
    kmzStr.value = str
    kmlStr.value = str
  }
  const write = () => {}
  const write = (settingParmas: any = {}, name?: string, isWpml?: boolean = false) => {}
  const del = () => {}
  const del = () => {
  }
  const edit = () => {}
  const edit = (settingParmas: any = {}, keyName?: string, isKeyWpml: boolean = false) => {
    Object.keys(settingParmas).forEach((key: string) => {
      const regxVal: any = getKmlParams(kmlStr.value, true, {
        name: key,
        findRegx: '([\\s\\S]*?)',
      })
      const str = regxVal[1]
      if (str) {
        if (key === 'globalHeight') {
          const regxVal: any = getKmlParams(kmlStr.value, true, {
            name: 'height',
            findRegx: '([\\s\\S]*?)',
            mode: 'g'
          })
          regxVal.forEach((heightStr: string) => {
            const rstr = generateKmlFormat({ height: settingParmas[key] })
            kmlStr.value = kmlStr.value.replace(heightStr, rstr)
          })
        }
        const replaceStr = generateKmlFormat({ [key]: settingParmas[key] })
        kmlStr.value = kmlStr.value.replace(regxVal[0], replaceStr)
      } else {
        console.warn('没有找到对应的属性')
      }
    })
  }
  const save = () => {}
  const save = () => {
    console.log(kmlStr.value)
  }
  return {
    init,
    create,
    write,
    del,
    edit,
    save
    save,
  }
}
export { kmlStr }
export default useKmzTsa