| | |
| | | import { ref, getCurrentInstance } from 'vue' |
| | | import { analyzeKmzFile, getKmlParams, generateKmlFormat } from '/@/utils/cesium/kmz' |
| | | import { |
| | | analyzeKmzFile, |
| | | getKmlParams, |
| | | generateKmlFormat, |
| | | XMLToJSON, |
| | | JSONToXML |
| | | } from '/@/utils/cesium/kmz' |
| | | import JSZIP from 'jszip' |
| | | import { saveAs } from 'file-saver' |
| | | import { point } from '@turf/turf' |
| | | |
| | | const JsZip = new JSZIP() |
| | | |
| | |
| | | }) |
| | | const kmlStr = ref('') |
| | | const kmzFile = ref<any>(null) |
| | | |
| | | const template = ref({ |
| | | author: '', |
| | | createTime: '', |
| | | updateTime: '', |
| | | missionConfig: { |
| | | flyToWaylineMode: 'safely', |
| | | finishAction: 'goHome', |
| | | exitOnRCLost: 'goContinue', |
| | | executeRCLostAction: 'goBack', |
| | | takeOffSecurityHeight: 20, |
| | | takeOffRefPoint: '0.000000,0.000000,0.000000', |
| | | takeOffRefPointAGLHeight: 0, |
| | | globalTransitionalSpeed: 15, |
| | | globalRTHHeight: 80, |
| | | droneInfo: { |
| | | droneEnumValue: 0, |
| | | droneSubEnumValue: 0, |
| | | }, |
| | | payloadInfo: { |
| | | payloadEnumValue: 0, |
| | | payloadSubEnumValue: 0, |
| | | payloadPositionIndex: 0, |
| | | }, |
| | | }, |
| | | Folder: { |
| | | templateType: 'waypoint', |
| | | useGlobalTransitionalSpeed: 0, |
| | | templateId: 0, |
| | | waylineCoordinateSysParam: { |
| | | coordinateMode: 'WGS84', |
| | | heightMode: 'EGM96', |
| | | globalShootHeight: 50, |
| | | positioningType: 'GPS', |
| | | surfaceFollowModeEnable: 1, |
| | | surfaceRelativeHeight: 100, |
| | | }, |
| | | autoFlightSpeed: 7, |
| | | gimbalPitchMode: 'usePointSetting', |
| | | globalWaypointHeadingParam: { |
| | | waypointHeadingMode: 'followWayline', |
| | | waypointHeadingAngle: 0, |
| | | waypointPoiPoint: '0.000000,0.000000,0.000000', |
| | | waypointHeadingPathMode: 'followBadArc', |
| | | }, |
| | | globalWaypointTurnMode: 'toPointAndStopWithDiscontinuityCurvature', |
| | | globalUseStraightLine: 0, |
| | | Placemark: [ |
| | | { |
| | | Point: { |
| | | coordinates: '', |
| | | }, |
| | | index: 0, |
| | | ellipsoidHeight: 0, |
| | | height: 0, |
| | | useGlobalHeight: 0, |
| | | useGlobalSpeed: 0, |
| | | useGlobalHeadingParam: 1, |
| | | useGlobalTurnParam: 0, |
| | | gimbalPitchAngle: 0, |
| | | actionGroup: { |
| | | actionGroupId: 0, |
| | | actionGroupStartIndex: 1, |
| | | actionGroupEndIndex: 1, |
| | | actionGroupMode: 'sequence', |
| | | actionTrigger: { |
| | | actionTriggerType: 'reachPoint', |
| | | }, |
| | | action: [], |
| | | }, |
| | | }, |
| | | ], |
| | | }, |
| | | }) |
| | | const waylines = ref({ |
| | | missionConfig: { |
| | | flyToWaylineMode: 'safely', |
| | | finishAction: 'goHome', |
| | | exitOnRCLost: 'goContinue', |
| | | executeRCLostAction: 'hover', |
| | | takeOffSecurityHeight: 20, |
| | | globalTransitionalSpeed: 10, |
| | | distance: 0, |
| | | duration: 0, |
| | | droneInfo: { |
| | | droneEnumValue: 67, |
| | | droneSubEnumValue: 0, |
| | | }, |
| | | payloadInfo: { |
| | | payloadEnumValue: 52, |
| | | payloadSubEnumValue: 0, |
| | | payloadPositionIndex: 0, |
| | | }, |
| | | }, |
| | | Folder: { |
| | | templateId: 0, |
| | | executeHeightMode: 'WGS84', |
| | | waylineId: 0, |
| | | autoFlightSpeed: 10, |
| | | Placemark: [ |
| | | { |
| | | Point: { |
| | | coordinates: '0.000000, 0.000000', |
| | | }, |
| | | index: 0, |
| | | executeHeight: 116.57, |
| | | waypointSpeed: 10, |
| | | waypointHeadingParam: { |
| | | waypointHeadingMode: 'followWayline', |
| | | }, |
| | | waypointTurnParam: { |
| | | waypointTurnMode: 'toPointAndStopWithDiscontinuityCurvature', |
| | | waypointTurnDampingDist: 0, |
| | | }, |
| | | useStraightLine: 1, |
| | | actionGroup: [], |
| | | }, |
| | | ], |
| | | }, |
| | | }) |
| | | |
| | | // 点位参数 |
| | | const placemark: any = { |
| | |
| | | const useKmzTsa = () => { |
| | | const init = async (fileUrl: string, fileContent?: string) => { |
| | | const fileRes = await analyzeKmzFile(fileUrl) |
| | | kmzFile.value = fileRes.file |
| | | const kmzRes = await fileRes.content |
| | | kmzFile.value = fileRes.zip |
| | | const kmzRes = await fileRes.fileInfoObj['wpmz/template.kml'] |
| | | if (fileContent) { |
| | | kmlStr.value = fileContent |
| | | return false |
| | |
| | | kmlStr.value = kmzRes |
| | | return kmzRes |
| | | } |
| | | |
| | | const create = () => { |
| | | const nowTime = new Date().getTime() |
| | | const str = ` |
| | |
| | | ` |
| | | kmlStr.value = str |
| | | } |
| | | |
| | | // const write = (settingParmas: any = {}, name: string) => { |
| | | // } |
| | | const writePoint = (settingParmas: any = {}, place: string, pointNumber: number = 0) => { |
| | | Object.keys(settingParmas).forEach((key: string) => { |
| | | placemark[key] = settingParmas[key] |
| | |
| | | }) |
| | | } |
| | | } |
| | | |
| | | const del = () => {} |
| | | |
| | | const edit = (settingParmas: any = {}, keyName?: string, isKeyWpml: boolean = false) => { |
| | | Object.keys(settingParmas).forEach((key: string) => { |
| | | const regxVal: any = getKmlParams(kmlStr.value, true, { |
| | |
| | | // 文件中的海拔高度 |
| | | const takeOffRefPointAGLHeightRegxStr = getKmlParams(kmlStr.value, true, { |
| | | name: 'takeOffRefPointAGLHeight', |
| | | findRegx: '([\\s\\S]*?)' |
| | | findRegx: '([\\s\\S]*?)', |
| | | }) || ['', '0'] |
| | | const posterHeight = Number(takeOffRefPointAGLHeightRegxStr[1]) |
| | | // 获取每个点是否使用全局高度 |
| | |
| | | name: 'height', |
| | | findRegx: '([\\s\\S]*?)', |
| | | }) |
| | | console.log(heightRegxVal) |
| | | } |
| | | }) |
| | | } |
| | |
| | | } |
| | | |
| | | const save = () => { |
| | | 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') |
| | | }) |
| | | console.log('存在问题') |
| | | } |
| | | |
| | | return { |
| | |
| | | create, |
| | | // write, |
| | | writePoint, |
| | | del, |
| | | edit, |
| | | save, |
| | | } |