2024-12-09 06:44:52 +00:00
|
|
|
import SatelliteEntity from '@/js/SatelliteEntity'
|
|
|
|
import { difference } from 'lodash'
|
2025-01-06 01:18:58 +00:00
|
|
|
import { useEntity } from '@/hooks/entity'
|
2025-02-19 08:06:46 +00:00
|
|
|
import { useTree } from '@/utils/tree'
|
|
|
|
import { getSatellite } from '@/api/Satellite'
|
2025-02-25 07:59:30 +00:00
|
|
|
import { Beam } from '@/js/Beam'
|
2025-02-19 08:06:46 +00:00
|
|
|
|
2024-12-09 06:44:52 +00:00
|
|
|
// import CreateFrustum from '@/js/Sensor'
|
|
|
|
|
|
|
|
interface ISatellite {
|
|
|
|
name: string
|
2025-01-20 01:42:19 +00:00
|
|
|
id: string
|
2024-12-09 06:44:52 +00:00
|
|
|
tle: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IBaseFilterParam {
|
|
|
|
treeData: Array<any>
|
|
|
|
params: Array<string | number>
|
|
|
|
paramName: string
|
|
|
|
}
|
2025-02-19 08:06:46 +00:00
|
|
|
const { filterTreeNodeByField } = useTree()
|
2024-12-09 06:44:52 +00:00
|
|
|
const satelliteList = ref<ISatellite[]>([])
|
2025-02-19 08:06:46 +00:00
|
|
|
const checkedKeys = ref<Array<string | number>>([])
|
2024-12-09 06:44:52 +00:00
|
|
|
|
2025-02-25 07:59:30 +00:00
|
|
|
const { mubiaoMap, satelliteMap, satelliteBeamMap, satellitePayloadShowMap } =
|
|
|
|
useEntity()
|
2025-01-20 01:42:19 +00:00
|
|
|
|
|
|
|
const showPoint = ref(true)
|
|
|
|
function showPointUnderSat(id?: string) {
|
|
|
|
if (id) {
|
|
|
|
satelliteMap.get(id).underPoint = true
|
|
|
|
} else {
|
|
|
|
;[...satelliteMap.values()].forEach(satellite => {
|
|
|
|
satellite.underPoint = showPoint.value
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-12-09 06:44:52 +00:00
|
|
|
export function useSatellite() {
|
|
|
|
function addSatellites(ids: Array<string | number>) {
|
|
|
|
const addIds = difference(ids, [...satelliteMap.keys()])
|
|
|
|
const removeIds = difference([...satelliteMap.keys()], ids)
|
2025-02-19 10:35:06 +00:00
|
|
|
removeIds.forEach(id => {
|
|
|
|
removeSatellite(id)
|
|
|
|
})
|
2024-12-09 06:44:52 +00:00
|
|
|
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)
|
2025-03-03 09:31:58 +00:00
|
|
|
//console.log(satelliteMap, '卫星')
|
2025-01-20 01:42:19 +00:00
|
|
|
if (showPoint.value) {
|
|
|
|
showPointUnderSat(node.id)
|
|
|
|
}
|
2024-12-09 06:44:52 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 创建satellite entity 实例
|
2025-02-19 08:06:46 +00:00
|
|
|
function addSatellite({ id, tle }: ISatellite) {
|
2024-12-09 06:44:52 +00:00
|
|
|
const satellite = new SatelliteEntity(tle)
|
|
|
|
const cesiumSateEntity = satellite.createSatelliteEntity()
|
|
|
|
// const result = viewer.entities.add(cesiumSateEntity)
|
|
|
|
|
2025-01-13 08:45:08 +00:00
|
|
|
setTimeout(() => {
|
2025-01-20 01:42:19 +00:00
|
|
|
// satellite.sensorType = Math.random() > 0.5 ? 'conic' : 'rectangle'
|
2025-02-19 08:06:46 +00:00
|
|
|
const satPayload = satellitePayloadShowMap.get(id)
|
|
|
|
if (satPayload && satPayload.detectingPayload) {
|
2025-02-25 02:43:57 +00:00
|
|
|
satPayload.detectingPayload.radius &&
|
|
|
|
(satellite.sensorRadius = satPayload.detectingPayload.radius)
|
2025-02-19 08:06:46 +00:00
|
|
|
satPayload.detectingPayload.angle &&
|
|
|
|
(satellite.sensorAngle = satPayload.detectingPayload.angle)
|
|
|
|
satPayload.detectingPayload.show && (satellite.sensor = true)
|
|
|
|
}
|
2025-02-25 07:59:30 +00:00
|
|
|
|
|
|
|
createSatelliteCommunicationPayload(id)
|
2025-01-13 08:45:08 +00:00
|
|
|
}, 1000)
|
2025-01-20 01:42:19 +00:00
|
|
|
|
2024-12-09 06:44:52 +00:00
|
|
|
// viewer.clock.multiplier = 100
|
|
|
|
|
2025-01-13 08:45:08 +00:00
|
|
|
return satellite
|
2024-12-09 06:44:52 +00:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
2025-01-13 08:45:08 +00:00
|
|
|
satellite.destroy()
|
2024-12-09 06:44:52 +00:00
|
|
|
satelliteMap.delete(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-19 08:06:46 +00:00
|
|
|
return {
|
|
|
|
satelliteList,
|
|
|
|
checkedKeys,
|
|
|
|
getSatelliteList,
|
|
|
|
addSatellites,
|
|
|
|
showPoint,
|
|
|
|
showPointUnderSat,
|
|
|
|
}
|
2024-12-09 06:44:52 +00:00
|
|
|
}
|
|
|
|
|
2025-02-25 07:59:30 +00:00
|
|
|
function createSatelliteCommunicationPayload(satId: string) {
|
|
|
|
if (
|
|
|
|
!satelliteMap.has(satId) ||
|
|
|
|
!satellitePayloadShowMap.get(satId)?.communicationPayload ||
|
|
|
|
satellitePayloadShowMap.get(satId)?.communicationPayload?.show
|
|
|
|
) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
removeSatelliteCommunicationPayload(satId)
|
|
|
|
// console.log(satellitePayloadShowMap.get(id)?.communicationPayload)
|
|
|
|
satellitePayloadShowMap
|
|
|
|
.get(satId)
|
|
|
|
?.communicationPayload?.target.forEach((mbId: string) => {
|
|
|
|
console.log(mbId, 'mbId')
|
|
|
|
if (mubiaoMap.has(mbId)) {
|
|
|
|
const beam = new Beam({
|
|
|
|
topEntity: satelliteMap.get(satId),
|
|
|
|
bottomEntity: mubiaoMap.get(mbId),
|
|
|
|
})
|
|
|
|
|
|
|
|
beam.create()
|
|
|
|
|
|
|
|
console.log(beam)
|
|
|
|
|
|
|
|
if (!satelliteBeamMap.has(satId)) {
|
|
|
|
satelliteBeamMap.set(satId, new Map())
|
|
|
|
}
|
|
|
|
|
|
|
|
const beamMap = satelliteBeamMap.get(satId)
|
|
|
|
beamMap.set(mbId, beam)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeSatelliteCommunicationPayload(satId: string) {
|
|
|
|
if (!satelliteBeamMap.has(satId)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const beamMap = satelliteBeamMap.get(satId)
|
|
|
|
;[...beamMap.keys()].forEach((mbId: string) => {
|
|
|
|
beamMap.get(mbId)?.remove()
|
|
|
|
beamMap.delete(mbId)
|
|
|
|
})
|
|
|
|
|
|
|
|
satelliteBeamMap.delete(satId)
|
|
|
|
}
|
|
|
|
|
2025-02-19 08:06:46 +00:00
|
|
|
// function filterTreeNodeByField({
|
|
|
|
// treeData,
|
|
|
|
// params,
|
|
|
|
// paramName,
|
|
|
|
// }: IBaseFilterParam): Array<ISatellite> {
|
|
|
|
// 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
|
2025-02-25 07:59:30 +00:00
|
|
|
? { target: communicationPayload, show: communicationShow }
|
2025-02-19 08:06:46 +00:00
|
|
|
: null,
|
|
|
|
})
|
2024-12-09 06:44:52 +00:00
|
|
|
}
|
2025-02-19 08:06:46 +00:00
|
|
|
})
|
|
|
|
console.log('satellitePayloadShowMap', satellitePayloadShowMap)
|
2024-12-09 06:44:52 +00:00
|
|
|
}
|