import * as Cesium from 'cesium' import { appointroutePlanning } from '@/api/RoutePlanning' import { analyzeKmzFile, XMLToJSON } from '@/utils/cesium/kmz.js' import { getLnglatAltitude } from '@/utils/cesium/mapUtil' import cesiumOperation from '@/utils/cesium-tsa' const { removeAllPoint, removeLeftClickEvent, flyTo } = cesiumOperation() import { getCenterPoint, getLnglatDist, cartesian3Convert, } from '@/utils/cesium/mapUtil.js' export default { data () { return { //机场坐标信息 droneCoordinates: null, switchSaving: false, clampToGroundshow: true, } }, watch: { '$store.state.drone.selectedWorkSpaceId': { handler (wId) { this.switchSaving = true this.droneCoordinates = null }, deep: true, immediate: true, }, '$store.state.drone.deviceState': { handler (data) { if (this.switchSaving) return (this.switchSaving = false) if (this.droneCoordinates) return const deviceSn = data?.currentSn || '' const dockInfo = data?.dockInfo || '' const { longitude, latitude, height } = dockInfo[deviceSn]?.basic_osd || '' if (!longitude) return if (this.lastlongitude == longitude) return this.lastlongitude = longitude getLnglatAltitude(longitude, latitude, global.$viewer).then((res) => { this.droneCoordinates = Cesium.Cartesian3.fromDegrees( Number(longitude), Number(latitude), Number(res.height), ) }) }, deep: true, immediate: true, }, '$store.state.common.mapSetting.visual': { handler (mode) { removeLeftClickEvent() this.taskBoxis = false this.clampToGroundshow = mode === '2D' ? true : false if (!this.activeRow) return let tempRow = this.activeRow this.activeRow = null this.rowTriggerFn(tempRow) }, deep: true, immediate: true, }, //当选择航线规划数据时,任务列表不选中数据 '$store.state.revokeTaskSelection': { handler (task) { removeAllPoint() this.activeRow = null this.taskBoxis = false if (!this.$refs.myTable) return this.$refs.myTable.setCurrentRow() }, deep: true, immediate: false, }, }, methods: { // 判断是面状还是航线 async judgeWaylineMode (route) { this.workspaceId = this.wId const { data: waylineUrl } = await appointroutePlanning( this.workspaceId, route.id, ) if (waylineUrl.code !== 0) return this._showMessage.error(waylineUrl.message) const { fileInfoObj } = await analyzeKmzFile( `${waylineUrl.data}?_t=${new Date().getTime()}`, ) const xmlStr = await fileInfoObj['wpmz/template.kml'] const xmlJson = XMLToJSON(xmlStr)?.['Document'] const placemark = xmlJson.Folder.Placemark if (placemark?.Polygon) { return 'planar' } else { return 'point' } }, // 在机场和第一个点直接增加一个中间转折点 addTurnPoint (firstPoint, SecondPoint) { const dronePosition = cartesian3Convert(firstPoint, global.$viewer) const firstPosition = cartesian3Convert(SecondPoint, global.$viewer) return new Cesium.Cartesian3.fromDegrees( dronePosition?.longitude, dronePosition?.latitude, firstPosition?.height, ) }, // 指向该区域 flyToRouterShow (waylinePosition) { let cartesianlengthArr = waylinePosition.map((cartesian) => { return [ cartesian3Convert(cartesian, global.$viewer).longitude, cartesian3Convert(cartesian, global.$viewer).latitude, ] }) const centerpoint = getCenterPoint(cartesianlengthArr) let maxlength = 0 cartesianlengthArr.forEach((item, index) => { let banseTwoPoints = getLnglatDist( item[0], item[1], centerpoint.lng, centerpoint.lat, ) if (banseTwoPoints > maxlength) { maxlength = banseTwoPoints } }) let flyNum = this.clampToGroundshow ? 7 : 12 flyTo( { longitude: centerpoint.lng, latitude: centerpoint.lat }, 3, maxlength * flyNum, ) }, }, }