import SatelliteEntity from '@/js/SatelliteEntity' import { difference } from 'lodash' import { useEntity } from '@/hooks/entity' import { useTree } from '@/utils/tree' import { getSatellite } from '@/api/Satellite' // import CreateFrustum from '@/js/Sensor' interface ISatellite { name: string id: string tle: string } interface IBaseFilterParam { treeData: Array params: Array paramName: string } const { filterTreeNodeByField } = useTree() const satelliteList = ref([]) const checkedKeys = ref>([]) const { satelliteMap, showOrHideLoad, satellitePayloadShowMap } = useEntity() const showPoint = ref(true) function showPointUnderSat(id?: string) { if (id) { satelliteMap.get(id).underPoint = true } else { ;[...satelliteMap.values()].forEach(satellite => { satellite.underPoint = showPoint.value }) } } export function useSatellite() { function addSatellites(ids: Array) { const addIds = difference(ids, [...satelliteMap.keys()]) const removeIds = difference([...satelliteMap.keys()], ids) removeIds.forEach(id => { removeSatellite(id) }) if (addIds.length > 0) { const nodes = filterTreeNodeByField({ treeData: satelliteList.value, params: addIds, paramName: 'id', }) nodes.forEach(node => { const entity = addSatellite(node) satelliteMap.set(node.id, entity) if (showPoint.value) { showPointUnderSat(node.id) } }) } } // 创建satellite entity 实例 function addSatellite({ id, tle }: ISatellite) { const satellite = new SatelliteEntity(tle) const cesiumSateEntity = satellite.createSatelliteEntity() // const result = viewer.entities.add(cesiumSateEntity) setTimeout(() => { // satellite.sensorType = Math.random() > 0.5 ? 'conic' : 'rectangle' const satPayload = satellitePayloadShowMap.get(id) if (satPayload && satPayload.detectingPayload) { satPayload.detectingPayload.radius && (satellite.sensorRadius = satPayload.detectingPayload.radius) satPayload.detectingPayload.angle && (satellite.sensorAngle = satPayload.detectingPayload.angle) satPayload.detectingPayload.show && (satellite.sensor = true) } }, 1000) // viewer.clock.multiplier = 100 return satellite // let heading = 0 // let pitch = 0 // let roll = 0 // let hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll) // let orientation = Cesium.Quaternion.fromHeadingPitchRoll(hpr) // // 创建视锥体 // console.log( // viewer.scene.canvas.clientWidth / viewer.scene.canvas.clientHeight, // 'viewer.scene.canvas.clientWidth / viewer.scene.canvas.clientHeight' // ) // let createFrustum = new CreateFrustum({ // position: origin, // orientation: orientation, // fov: 30, // near: 0.1, // far: 10000, // aspectRatio: // viewer.scene.canvas.clientWidth / viewer.scene.canvas.clientHeight, // }) } function removeSatellite(id: string | number) { if (satelliteMap.has(id)) { const satellite = satelliteMap.get(id) satellite.destroy() satelliteMap.delete(id) } } return { satelliteList, checkedKeys, getSatelliteList, addSatellites, showPoint, showPointUnderSat, } } // function filterTreeNodeByField({ // treeData, // params, // paramName, // }: IBaseFilterParam): Array { // return treeData.reduce((acc, node) => { // if (params.includes(node[paramName]) && !node.children) { // acc.push(node) // } // if (node.children) { // acc = acc.concat( // filterTreeNodeByField({ // treeData: node.children, // params, // paramName, // }) // ) // } // return acc // }, []) // } async function getSatelliteList() { const checked = JSON.parse(JSON.stringify(checkedKeys.value)) const sateRes = await getSatellite() const { data, code } = sateRes if (code === '200') { checkedKeys.value = [] satelliteList.value = data getAllNodesToPayload() nextTick(() => { checkedKeys.value = checked }) } // console.log('data,code', data, code) } function getAllNodesToPayload() { // const mbList = getLeafNodeIds(satelliteList.value, 'dataId') satelliteList.value.forEach(satellite => { if (satellite.extendInfo) { const { detectingPayload, communicationPayload } = satellite.extendInfo const detectingShow = satellitePayloadShowMap.get(satellite.id)?.detectingPayload?.show || false const communicationShow = satellitePayloadShowMap.get(satellite.id)?.communicationPayload?.show || false satellitePayloadShowMap.set satellitePayloadShowMap.set(satellite.id, { detectingPayload: detectingPayload ? { ...detectingPayload, show: detectingShow } : null, communicationPayload: communicationPayload ? { ...communicationPayload, show: communicationShow } : null, }) } }) console.log('satellitePayloadShowMap', satellitePayloadShowMap) }