| | |
| | | import { ref } from 'vue' |
| | | import { ref, getCurrentInstance } from 'vue' |
| | | import { analyzeKmzFile, getKmlParams, generateKmlFormat } from '/@/utils/cesium/kmz' |
| | | import { getLngLatAltitude } from './mapUtils' |
| | | import JSZIP from 'jszip' |
| | | import { saveAs } from 'file-saver' |
| | | |
| | | const JsZip = new JSZIP() |
| | | |
| | | const kmlStr = ref('') |
| | | const kmzFile = ref<any>(null) |
| | | |
| | | // 点位参数 |
| | | const placemark: any = { |
| | | Point: { |
| | | coordinates: '', |
| | | }, |
| | | index: 0, |
| | | executeHeight: 80, |
| | | height: 80, |
| | | waypointSpeed: 10, |
| | | waypointHeadingParam: { |
| | | waypointHeadingMode: 'followWayline', |
| | | waypointHeadingAngle: 0, |
| | | waypointPoiPoint: '0.000000,0.000000,0.000000', |
| | | waypointHeadingPathMode: 'followBadArc', |
| | | waypointHeadingPoiIndex: 0, |
| | | }, |
| | | waypointTurnParam: { |
| | | waypointTurnMode: 'toPointAndStopWithDiscontinuityCurvature', |
| | | waypointTurnDampingDist: 0.2, |
| | | }, |
| | | useGlobalHeight: 1, |
| | | useGlobalSpeed: 1, |
| | | useGlobalHeadingParam: 1, |
| | | useGlobalTurnParam: 1, |
| | | useStraightLine: 1, |
| | | actionGroup: {}, |
| | | } |
| | | |
| | | const useKmzTsa = () => { |
| | | const init = async (fileUrl: string, fileContent?: string) => { |
| | | const kmzRes: string = await analyzeKmzFile(fileUrl) |
| | | const fileRes = await analyzeKmzFile(fileUrl) |
| | | kmzFile.value = fileRes.file |
| | | const kmzRes = await fileRes.content |
| | | if (fileContent) { |
| | | kmlStr.value = fileContent |
| | | return false |
| | |
| | | kmlStr.value = str |
| | | } |
| | | |
| | | const write = (settingParmas: any = {}, name?: string, isWpml?: boolean = false) => {} |
| | | |
| | | const del = () => { |
| | | // const write = (settingParmas: any = {}, name: string) => { |
| | | // } |
| | | const writePoint = (settingParmas: any = {}) => { |
| | | Object.keys(settingParmas).forEach((key: string) => { |
| | | placemark[key] = settingParmas[key] |
| | | }) |
| | | const Placemark = `<Placemark>${generateKmlFormat(placemark)}</Placemark>` |
| | | const points: RegExpMatchArray = getKmlParams(kmlStr.value, false, { |
| | | name: 'Placemark', |
| | | findRegx: '([\\s\\S]*?)', |
| | | mode: 'g', |
| | | }) || [''] |
| | | const lastPoint = points[points.length - 1] |
| | | const index = kmlStr.value.indexOf(lastPoint) |
| | | const beforeStr = kmlStr.value.slice(0, index) |
| | | const afterStr = kmlStr.value.slice(index + lastPoint.length) |
| | | kmlStr.value = beforeStr + lastPoint + Placemark + afterStr |
| | | } |
| | | |
| | | const del = () => {} |
| | | |
| | | const edit = (settingParmas: any = {}, keyName?: string, isKeyWpml: boolean = false) => { |
| | | Object.keys(settingParmas).forEach((key: string) => { |
| | |
| | | const regxVal: any = getKmlParams(kmlStr.value, true, { |
| | | name: 'height', |
| | | findRegx: '([\\s\\S]*?)', |
| | | mode: 'g' |
| | | mode: 'g', |
| | | }) |
| | | regxVal.forEach((heightStr: string) => { |
| | | const rstr = generateKmlFormat({ height: settingParmas[key] }) |
| | |
| | | } |
| | | |
| | | const save = () => { |
| | | console.log(kmlStr.value) |
| | | JsZip.file('wpmz/template.kml', kmlStr.value) |
| | | kmzFile.value.file('wpmz/template.kml', kmlStr.value) |
| | | JsZip.generateAsync({ type: 'blob' }).then((content) => { |
| | | saveAs(content, '新建航线-' + new Date().toLocaleString() + '.kmz') |
| | | }) |
| | | } |
| | | |
| | | return { |
| | | init, |
| | | create, |
| | | write, |
| | | // write, |
| | | writePoint, |
| | | del, |
| | | edit, |
| | | save, |