2025-01-13 08:45:08 +00:00
|
|
|
import { getMubiaoHisTraj } from '@/api/Mubiao'
|
2025-01-06 01:18:58 +00:00
|
|
|
|
|
|
|
const baseMap = new Map()
|
|
|
|
const mubiaoMap = new Map()
|
|
|
|
const satelliteMap = new Map()
|
|
|
|
export const useEntity = () => {
|
|
|
|
return {
|
|
|
|
baseMap,
|
|
|
|
mubiaoMap,
|
|
|
|
satelliteMap,
|
2025-01-13 08:45:08 +00:00
|
|
|
showEntity,
|
|
|
|
getHisTraj,
|
|
|
|
getMBEntityOpt,
|
|
|
|
changeIconOrModel,
|
2025-01-06 01:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
2025-01-13 08:45:08 +00:00
|
|
|
|
|
|
|
function showEntity(show: boolean) {
|
|
|
|
;[...mubiaoMap.values()].forEach(entity => {
|
|
|
|
entity.show = show
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getHisTraj({
|
|
|
|
id,
|
|
|
|
timeRange,
|
|
|
|
}: {
|
|
|
|
id: string
|
|
|
|
timeRange: string[]
|
|
|
|
}) {
|
|
|
|
const [timeBegin, timeEnd] = timeRange
|
|
|
|
const { code, data: result } = await getMubiaoHisTraj({
|
|
|
|
target_id: id,
|
|
|
|
timeBegin,
|
|
|
|
timeEnd,
|
|
|
|
})
|
|
|
|
if (code !== '200') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const timeArray = result.map(item => {
|
|
|
|
return new Date(item.time).getTime()
|
|
|
|
})
|
|
|
|
const posArray = result.map(item => item.position).flat(Infinity)
|
|
|
|
const points = result.reduce<TPoints>((acc, point, index, array) => {
|
|
|
|
const { time, position } = point
|
|
|
|
const cartesian3 = Cesium.Cartesian3.fromDegrees(...position)
|
|
|
|
if (index === 0) {
|
|
|
|
acc.push({ time: 0, position: cartesian3 })
|
|
|
|
} else {
|
|
|
|
acc.push({
|
|
|
|
time:
|
|
|
|
(new Date(time).getTime() - new Date(array[0].time).getTime()) / 1000,
|
|
|
|
position: cartesian3,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return acc
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return { points, posArray, timeArray }
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMBEntityOpt({
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
targetType,
|
|
|
|
}: {
|
|
|
|
id: string
|
|
|
|
name?: string
|
|
|
|
targetType: string
|
|
|
|
}) {
|
|
|
|
const mubiaoDict = window.settings.mbDict[targetType]
|
|
|
|
|
|
|
|
return {
|
|
|
|
label: {
|
|
|
|
text: `${id}`,
|
|
|
|
font: '12pt sans-serif',
|
|
|
|
fillColor: Cesium.Color.YELLOW,
|
|
|
|
outlineColor: Cesium.Color.BLACK,
|
|
|
|
outlineWidth: 2,
|
|
|
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
|
|
pixelOffset: new Cesium.Cartesian2(20, -20),
|
|
|
|
pixelOffsetScaleByDistance: new Cesium.NearFarScalar(
|
|
|
|
7000000,
|
|
|
|
1.0,
|
|
|
|
18000000,
|
|
|
|
0.4
|
|
|
|
),
|
|
|
|
scaleByDistance: new Cesium.NearFarScalar(7000000, 1.0, 18000000, 0.4),
|
|
|
|
},
|
|
|
|
billboard: {
|
|
|
|
show: true,
|
|
|
|
image: mubiaoDict.icon,
|
|
|
|
width: 30,
|
|
|
|
height: 30,
|
|
|
|
color: Cesium.Color.fromCssColorString(mubiaoDict.color),
|
|
|
|
scaleByDistance: new Cesium.NearFarScalar(7000000, 1.0, 18000000, 0.4),
|
|
|
|
},
|
|
|
|
model: {
|
|
|
|
show: false,
|
|
|
|
uri: mubiaoDict.model,
|
|
|
|
scale: 1000,
|
|
|
|
minimumPixelSize: 50,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeIconOrModel() {
|
|
|
|
;[...mubiaoMap.values()].forEach(entity => {
|
|
|
|
entity.model.show = !entity.model.show._value
|
|
|
|
entity.billboard.show = !entity.billboard.show._value
|
|
|
|
})
|
|
|
|
}
|