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'
|
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
|
|
|
|
}
|
|
|
|
const satelliteList = ref<ISatellite[]>([])
|
|
|
|
|
2025-01-06 01:18:58 +00:00
|
|
|
const { satelliteMap } = 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)
|
|
|
|
|
|
|
|
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-01-20 01:42:19 +00:00
|
|
|
if (showPoint.value) {
|
|
|
|
showPointUnderSat(node.id)
|
|
|
|
}
|
2024-12-09 06:44:52 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
removeIds.forEach(id => {
|
|
|
|
removeSatellite(id)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// 创建satellite entity 实例
|
|
|
|
function addSatellite({ tle }: ISatellite) {
|
|
|
|
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-01-13 08:45:08 +00:00
|
|
|
satellite.sensor = true
|
|
|
|
}, 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-01-20 01:42:19 +00:00
|
|
|
return { satelliteList, addSatellites, showPoint, showPointUnderSat }
|
2024-12-09 06:44:52 +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
|
|
|
|
}, [])
|
|
|
|
}
|