170 lines
4.7 KiB
JavaScript
170 lines
4.7 KiB
JavaScript
import { useEntity } from '@/hooks/entity'
|
|
import { getDirection } from '@/utils/pos'
|
|
import { useDetectionLoad } from './useDetectionLoad'
|
|
export function useMultiZBTraj() {
|
|
return {
|
|
multiZBTrajMap,
|
|
addMultiZBTraj,
|
|
removeAllMultiZBTraj,
|
|
ZBPayloadStatusMap,
|
|
changeZBPayloadStatus,
|
|
}
|
|
}
|
|
|
|
const multiZBTrajMap = new Map()
|
|
|
|
const { getMBEntityOpt } = useEntity()
|
|
|
|
// 添加多目标目标和轨迹
|
|
function addMultiZBTraj(zbList) {
|
|
removeAllMultiZBTraj()
|
|
Object.keys(zbList).forEach(async id => {
|
|
if (!multiZBTrajMap.has(id)) {
|
|
const { info, list: trajList } = zbList[id]
|
|
const { targetType, country, extendInfo } = info
|
|
const ZBOpt = await getMBEntityOpt({
|
|
id,
|
|
targetType,
|
|
country,
|
|
extendInfo: null,
|
|
})
|
|
|
|
const startTime = trajList[0].target_time
|
|
const endTime = trajList.at(-1).target_time
|
|
|
|
const positions = getPositions(trajList, targetType)
|
|
|
|
ZBOpt.billboard.rotation = new Cesium.CallbackProperty(currentTime => {
|
|
const point1 = positions.position.getValue(currentTime)
|
|
const nextTime = Cesium.JulianDate.addSeconds(
|
|
currentTime,
|
|
2,
|
|
new Cesium.JulianDate()
|
|
)
|
|
const point2 = positions.position.getValue(nextTime)
|
|
if (point2 && point1) {
|
|
const heading = getDirection(point1, point2)
|
|
|
|
const angleDegrees = Cesium.Math.toDegrees(heading)
|
|
return Cesium.Math.toRadians(angleDegrees)
|
|
}
|
|
}, false)
|
|
Object.assign(ZBOpt, {
|
|
...getPositions(trajList, targetType),
|
|
...getPath(startTime, endTime),
|
|
// ...getAvailability(startTime, endTime),
|
|
})
|
|
|
|
console.log('ZBOpt', ZBOpt)
|
|
|
|
const ZBEntity = viewer.entities.add(ZBOpt)
|
|
|
|
// ZBEntity.billboard.show = false
|
|
// ZBEntity.model.show = true
|
|
addPayload(id, extendInfo, ZBEntity)
|
|
multiZBTrajMap.set(id, ZBEntity)
|
|
}
|
|
})
|
|
}
|
|
|
|
const { addSectorDetectionLoad, addConicDetectionLoad } = useDetectionLoad()
|
|
|
|
const payloadMap = new Map()
|
|
const ZBPayloadStatusMap = ref(new Map())
|
|
|
|
function addPayload(id, extendInfo, ZBEntity) {
|
|
extendInfo?.radarPayload &&
|
|
extendInfo.radarPayload.forEach(item => {
|
|
const radar = addSectorDetectionLoad({
|
|
id: `${item.id}`,
|
|
bindEntity: ZBEntity,
|
|
...item,
|
|
})
|
|
payloadMap.set(id, [...(payloadMap.get(id) || []), radar])
|
|
})
|
|
extendInfo?.airplaneConicPayload &&
|
|
extendInfo.airplaneConicPayload.forEach(item => {
|
|
const conic = addConicDetectionLoad({
|
|
id: `${item.id}`,
|
|
bindEntity: ZBEntity,
|
|
...item,
|
|
})
|
|
payloadMap.set(id, [...(payloadMap.get(id) || []), conic])
|
|
})
|
|
// console.log(payloadMap, 'payloadMap')
|
|
ZBPayloadStatusMap.value.set(id, true)
|
|
}
|
|
function changeZBPayloadStatus(id, status) {
|
|
payloadMap.get(id)?.forEach(item => {
|
|
item.show = status
|
|
})
|
|
}
|
|
|
|
function getPositions(trajList, targetType) {
|
|
const positionProperty = new Cesium.SampledPositionProperty()
|
|
|
|
trajList.forEach(({ target_time, target_lon, target_lat }, index) => {
|
|
const time = Cesium.JulianDate.fromDate(new Date(target_time))
|
|
const position = Cesium.Cartesian3.fromDegrees(
|
|
target_lon,
|
|
target_lat,
|
|
window.settings.mbDict[targetType].height
|
|
)
|
|
positionProperty.addSample(time, position)
|
|
// viewer.entities.add({
|
|
// position,
|
|
// point: {
|
|
// pixelSize: 3,
|
|
// color: Cesium.Color.RED,
|
|
// },
|
|
// })
|
|
})
|
|
positionProperty.setInterpolationOptions({
|
|
interpolationDegree: 2,
|
|
interpolationAlgorithm: Cesium.HermitePolynomialApproximation,
|
|
})
|
|
|
|
return {
|
|
position: positionProperty,
|
|
orientation: new Cesium.VelocityOrientationProperty(positionProperty),
|
|
}
|
|
}
|
|
|
|
function getPath(startTime, endTime) {
|
|
console.log(new Date(startTime).getTime() - new Date(endTime).getTime())
|
|
return {
|
|
path: new Cesium.PathGraphics({
|
|
width: 0.5,
|
|
// show: true,
|
|
resolution: 1,
|
|
leadTime: new Date(startTime).getTime() - new Date(endTime).getTime(),
|
|
trailTime: new Date(startTime).getTime() - new Date(endTime).getTime(),
|
|
material: Cesium.Color.fromRandom().withAlpha(1),
|
|
}),
|
|
}
|
|
}
|
|
|
|
function getAvailability(startTime, endTime) {
|
|
const start = Cesium.JulianDate.fromDate(new Date(startTime))
|
|
const stop = Cesium.JulianDate.fromDate(new Date(endTime))
|
|
return {
|
|
availability: new Cesium.TimeIntervalCollection([
|
|
new Cesium.TimeInterval({ start: start, stop: stop }),
|
|
]),
|
|
}
|
|
}
|
|
|
|
function removeAllMultiZBTraj() {
|
|
for (let [key, entity] of multiZBTrajMap.entries()) {
|
|
viewer.entities.remove(entity)
|
|
multiZBTrajMap.delete(key)
|
|
}
|
|
|
|
for (let [key, entity] of payloadMap.entries()) {
|
|
entity.forEach(item => {
|
|
viewer.entities.remove(item)
|
|
})
|
|
payloadMap.delete(key)
|
|
}
|
|
}
|