import axios from 'axios'
|
import { mode } from 'crypto-js'
|
import JsZip from 'jszip'
|
|
/**
|
* @description: 读取kmz文件解析出kml文件
|
* @param {string} filePath 文件地址
|
* @return {*}
|
*/
|
export const analyzeKmzFile = (filePath: string) => {
|
return axios
|
.get(filePath, { responseType: 'arraybuffer' })
|
.then((fileRes) => fileRes.data)
|
.then((kmzData) => JsZip.loadAsync(kmzData)) // 解压kmz文件
|
.then((kmzZip) => {
|
// 通过文件名找到 KML 文件
|
const kmlFile = kmzZip.file(/\.kml$/i)[0]
|
return kmlFile.async('text')
|
})
|
}
|
|
export const getKmlParams = (
|
source: string,
|
isWpml: boolean,
|
params: { name: string; findRegx: string; mode?: string },
|
) => {
|
let regx = null
|
if (isWpml) {
|
if (params.mode) {
|
regx = new RegExp(
|
`<wpml:${params.name}>${params.findRegx}<\\/wpml:${params.name}>`,
|
params.mode,
|
)
|
} else {
|
regx = new RegExp(
|
`<wpml:${params.name}>${params.findRegx}<\\/wpml:${params.name}>`,
|
)
|
}
|
} else {
|
if (params.mode) {
|
regx = new RegExp(
|
`<${params.name}>${params.findRegx}<\\/${params.name}>`,
|
params.mode,
|
)
|
} else {
|
regx = new RegExp(
|
`<${params.name}>${params.findRegx}<\\/${params.name}>`,
|
)
|
}
|
}
|
return source?.match(regx)
|
}
|