2025-02-19 08:06:46 +00:00
|
|
|
import { ref, nextTick } from 'vue'
|
2025-01-13 08:45:08 +00:00
|
|
|
import { Subscriber } from 'cesium-extends'
|
2024-12-09 06:44:52 +00:00
|
|
|
import { parseWKT } from '@/utils/parseWKT'
|
|
|
|
import { cesiumTime2Format } from '@/utils/date'
|
|
|
|
import { difference } from 'lodash'
|
2025-02-19 08:06:46 +00:00
|
|
|
import { getMubiao, getMubiaoPos, sendCheckedTargetIds } from '@/api/Mubiao'
|
2024-12-09 06:44:52 +00:00
|
|
|
import { useTree } from '@/utils/tree'
|
|
|
|
import { useMubiaoPopup } from './mubiaoPopup'
|
2025-01-06 01:18:58 +00:00
|
|
|
import { useEntity } from '@/hooks/entity'
|
|
|
|
// import { useEntity } from '@/stores/entity'
|
|
|
|
// import { storeToRefs } from 'pinia'
|
2024-12-09 06:44:52 +00:00
|
|
|
interface IMubiaoNode {
|
|
|
|
country: string
|
|
|
|
targetName: string
|
|
|
|
targetType: string
|
|
|
|
id: string
|
|
|
|
extendInfo: Record<string, any>
|
|
|
|
}
|
|
|
|
interface IMubiao {
|
|
|
|
dataId: string
|
|
|
|
data: IMubiaoNode
|
|
|
|
nodeName: string
|
|
|
|
children?: IMubiao[]
|
|
|
|
}
|
|
|
|
|
2025-02-19 08:06:46 +00:00
|
|
|
const checkedKeys = ref<Array<string | number>>([])
|
|
|
|
|
2024-12-09 06:44:52 +00:00
|
|
|
const data = ref<Record<string, any>[]>([])
|
|
|
|
|
2025-02-19 08:06:46 +00:00
|
|
|
const {
|
|
|
|
mubiaoMap,
|
|
|
|
getMBEntityOpt,
|
2025-04-17 07:49:17 +00:00
|
|
|
getEllipsoidEntity,
|
|
|
|
getMBEntityOptOther,
|
2025-02-19 08:06:46 +00:00
|
|
|
createMBConicSensor,
|
|
|
|
mubiaoConicMap,
|
|
|
|
mbPayloadShowMap,
|
|
|
|
} = useEntity()
|
2025-01-06 01:18:58 +00:00
|
|
|
// const { mubiaoMap } = storeToRefs(entity)
|
|
|
|
// const mubiaoMap = ref<Map<string, any>>(new Map())
|
|
|
|
|
2024-12-09 06:44:52 +00:00
|
|
|
let subscriber: Subscriber | null = null
|
|
|
|
|
2025-02-19 08:06:46 +00:00
|
|
|
const { filterTreeNodeByField, getLeafNode } = useTree()
|
2024-12-09 06:44:52 +00:00
|
|
|
|
|
|
|
const { popupMap, createPopup } = useMubiaoPopup()
|
|
|
|
export const useMubiao = () => {
|
|
|
|
const addMubiao = async (ids: Array<string | number>) => {
|
|
|
|
subscriber = new Subscriber(viewer, {
|
|
|
|
pickResult: {
|
|
|
|
enable: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
postCheckedIds(ids)
|
|
|
|
// console.log(subscriber, 'subscriber')
|
|
|
|
// const ids = data.map(item => item.id)
|
|
|
|
const addIds = difference(ids, [...mubiaoMap.keys()])
|
|
|
|
const removeIds = difference([...mubiaoMap.keys()], ids)
|
|
|
|
|
2025-02-19 10:35:06 +00:00
|
|
|
// 删除
|
|
|
|
if (removeIds.length > 0) {
|
|
|
|
removeIds.forEach(id => {
|
|
|
|
removeMubiao(id)
|
|
|
|
})
|
|
|
|
}
|
2024-12-09 06:44:52 +00:00
|
|
|
// 添加
|
|
|
|
if (addIds.length > 0) {
|
|
|
|
const nodes = filterTreeNodeByField({
|
|
|
|
treeData: data.value,
|
|
|
|
params: addIds,
|
|
|
|
paramName: 'dataId',
|
|
|
|
})
|
|
|
|
|
|
|
|
const targetIdList = nodes.map(({ dataId }: IMubiao) => dataId)
|
|
|
|
// 获取目标坐标
|
|
|
|
const mbPos = await getMubiaoCurPos(targetIdList)
|
|
|
|
|
2025-01-20 01:42:19 +00:00
|
|
|
// console.log('mbPos', mbPos)
|
2024-12-09 06:44:52 +00:00
|
|
|
|
2025-02-25 02:43:57 +00:00
|
|
|
nodes.forEach(async ({ data, dataId: id }: IMubiao) => {
|
2024-12-09 06:44:52 +00:00
|
|
|
const { target_time, target_geom } =
|
|
|
|
mbPos.find(item => item.target_id === id) ?? {}
|
|
|
|
const pos = parseWKT(target_geom).coordinates
|
|
|
|
|
2025-04-17 07:49:17 +00:00
|
|
|
const [ellipsoidEntity,otherOptEntity] = await addMubiaoEntity({
|
2025-01-13 08:45:08 +00:00
|
|
|
id,
|
|
|
|
position: pos,
|
|
|
|
target_time,
|
2025-02-25 02:43:57 +00:00
|
|
|
country: data.country,
|
2025-01-13 08:45:08 +00:00
|
|
|
targetType: data.targetType,
|
2025-02-19 08:06:46 +00:00
|
|
|
extendInfo: data.extendInfo,
|
2025-01-13 08:45:08 +00:00
|
|
|
})
|
2025-04-17 07:49:17 +00:00
|
|
|
if(ellipsoidEntity){
|
|
|
|
addEventSub(`${id}_model`, ellipsoidEntity, data)
|
|
|
|
mubiaoMap.set(`${id}_model`, ellipsoidEntity)
|
|
|
|
}
|
2024-12-09 06:44:52 +00:00
|
|
|
// console.log(mbEntity, 'mbEntity')
|
2025-04-17 07:49:17 +00:00
|
|
|
|
|
|
|
addEventSub(id, otherOptEntity, data)
|
|
|
|
mubiaoMap.set(id, otherOptEntity)
|
2024-12-09 06:44:52 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function postCheckedIds(ids: Array<string | number>) {
|
|
|
|
const res = await sendCheckedTargetIds(ids)
|
|
|
|
}
|
|
|
|
|
2025-02-25 02:43:57 +00:00
|
|
|
const addMubiaoEntity = async ({
|
2024-12-09 06:44:52 +00:00
|
|
|
id,
|
|
|
|
position,
|
2025-02-25 02:43:57 +00:00
|
|
|
country,
|
2024-12-09 06:44:52 +00:00
|
|
|
target_time,
|
2025-01-13 08:45:08 +00:00
|
|
|
targetType,
|
2025-02-19 08:06:46 +00:00
|
|
|
extendInfo,
|
2024-12-09 06:44:52 +00:00
|
|
|
}: Record<string, string | number | number[]>) => {
|
|
|
|
// 添加目标实体
|
2025-01-13 08:45:08 +00:00
|
|
|
// console.log(window.settings, targetType, '-----')
|
2025-04-17 07:49:17 +00:00
|
|
|
// const mbEntityOpt = await getMBEntityOpt({
|
|
|
|
// id,
|
|
|
|
// country,
|
|
|
|
// targetType,
|
|
|
|
// extendInfo,
|
|
|
|
// })
|
|
|
|
|
|
|
|
// const mubiaoEntity = viewer.entities.add({
|
|
|
|
// name: id,
|
|
|
|
// position: Cesium.Cartesian3.fromDegrees(
|
|
|
|
// ...(position as number[]),
|
|
|
|
// targetType === '甲' ? 20000 : 0
|
|
|
|
// ),
|
|
|
|
// ...mbEntityOpt,
|
|
|
|
// })
|
|
|
|
let ellipsoid=null;
|
|
|
|
let ellipsoidEntity=null;
|
|
|
|
|
|
|
|
if(extendInfo?.detectingPayload){
|
|
|
|
ellipsoid = await getEllipsoidEntity({
|
|
|
|
id,
|
|
|
|
country,
|
|
|
|
targetType,
|
|
|
|
extendInfo,
|
|
|
|
})
|
|
|
|
ellipsoidEntity = viewer.entities.add({
|
|
|
|
name: id,
|
|
|
|
position: Cesium.Cartesian3.fromDegrees(
|
|
|
|
...(position as number[]),
|
|
|
|
targetType === '甲' ? 20000 : 0
|
|
|
|
),
|
|
|
|
...ellipsoid,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const otherOpt = await getMBEntityOptOther({
|
2025-02-25 02:43:57 +00:00
|
|
|
id,
|
|
|
|
country,
|
|
|
|
targetType,
|
|
|
|
extendInfo,
|
|
|
|
})
|
2025-04-17 07:49:17 +00:00
|
|
|
const otherOptEntity = viewer.entities.add({
|
2024-12-09 06:44:52 +00:00
|
|
|
name: id,
|
2025-02-19 08:06:46 +00:00
|
|
|
position: Cesium.Cartesian3.fromDegrees(
|
|
|
|
...(position as number[]),
|
|
|
|
targetType === '甲' ? 20000 : 0
|
|
|
|
),
|
2025-04-17 07:49:17 +00:00
|
|
|
...otherOpt,
|
2024-12-09 06:44:52 +00:00
|
|
|
})
|
2025-04-17 07:49:17 +00:00
|
|
|
// const mubiaoEntity = viewer.entities.add({
|
|
|
|
// name: id,
|
|
|
|
// position: Cesium.Cartesian3.fromDegrees(
|
|
|
|
// ...(position as number[]),
|
|
|
|
// targetType === '甲' ? 20000 : 0
|
|
|
|
// ),
|
|
|
|
// ...mbEntityOpt,
|
|
|
|
// })
|
|
|
|
// console.log( mubiaoEntity.position.getValue(),'===== mubiaoEntity.position.getValue()')
|
|
|
|
// console.log( mubiaoEntity.properties.zhName.getValue(),'===== mubiaoEntity.position.getValue()')
|
|
|
|
// console.log( mubiaoEntity.model.show.getValue(),'===== mubiaoEntity.model.show.getValue())')
|
|
|
|
|
2025-02-19 08:06:46 +00:00
|
|
|
|
2025-04-17 07:49:17 +00:00
|
|
|
// const zhNameEntity = viewer.entities.add({
|
|
|
|
// position: new Cesium.CallbackProperty(() => mubiaoEntity.position.getValue(), false),
|
|
|
|
// label: {
|
|
|
|
// text: new Cesium.CallbackProperty(() =>
|
|
|
|
// mubiaoEntity.properties.zhName.getValue(), false
|
|
|
|
// ),
|
|
|
|
// show: new Cesium.CallbackProperty(() =>
|
|
|
|
// mubiaoEntity.model.show.getValue(), false // 与模型显示状态同步
|
|
|
|
// ),
|
|
|
|
// font: '12pt 黑体',
|
|
|
|
// fillColor: Cesium.Color.WHITE,
|
|
|
|
// outlineColor: Cesium.Color.BLACK,
|
|
|
|
// pixelOffset: new Cesium.Cartesian2(40, -40), // 在模型右上方
|
|
|
|
// scaleByDistance: new Cesium.NearFarScalar(7000000, 1.0, 18000000, 0.4)
|
|
|
|
// }
|
|
|
|
// });
|
2025-02-19 08:06:46 +00:00
|
|
|
if (extendInfo?.detectingPayload?.angle) {
|
|
|
|
const conic = createMBConicSensor({
|
2025-04-17 07:49:17 +00:00
|
|
|
entity: otherOptEntity,
|
2025-02-25 02:43:57 +00:00
|
|
|
radius: extendInfo?.detectingPayload?.radius,
|
|
|
|
|
2025-02-19 08:06:46 +00:00
|
|
|
angle: extendInfo?.detectingPayload?.angle,
|
2025-02-25 02:43:57 +00:00
|
|
|
heading: extendInfo?.detectingPayload?.heading,
|
|
|
|
pitch: extendInfo?.detectingPayload?.pitch,
|
2025-02-19 08:06:46 +00:00
|
|
|
show: mbPayloadShowMap.get(id).detectingPayload.show,
|
|
|
|
})
|
|
|
|
mubiaoConicMap.set(id, conic)
|
|
|
|
}
|
2025-04-17 07:49:17 +00:00
|
|
|
return [ellipsoidEntity,otherOptEntity]
|
2024-12-09 06:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const addEventSub = (
|
|
|
|
id: string | number,
|
|
|
|
entity: Cesium.Entity,
|
|
|
|
mbData: Record<string, any>
|
|
|
|
) => {
|
|
|
|
subscriber &&
|
|
|
|
subscriber.add(
|
|
|
|
entity,
|
|
|
|
(movement, entity) => {
|
|
|
|
// console.log(movement, 'movement')
|
|
|
|
// console.log(entity, 'entity')
|
|
|
|
|
|
|
|
createPopup(id, entity, mbData)
|
|
|
|
},
|
|
|
|
'LEFT_CLICK'
|
|
|
|
)
|
|
|
|
// console.log(subscriber, '-------')
|
|
|
|
}
|
|
|
|
|
|
|
|
const removeMubiao = (id: string | number) => {
|
|
|
|
if (mubiaoMap.has(id)) {
|
|
|
|
subscriber && subscriber.remove(mubiaoMap.get(id), 'LEFT_CLICK')
|
|
|
|
|
|
|
|
viewer.entities.remove(mubiaoMap.get(id))
|
|
|
|
mubiaoMap.delete(id)
|
|
|
|
}
|
|
|
|
if (popupMap.has(id)) {
|
|
|
|
popupMap.get(id).windowClose()
|
|
|
|
popupMap.delete(id)
|
|
|
|
}
|
2025-02-19 08:06:46 +00:00
|
|
|
if (mubiaoConicMap.has(id)) {
|
|
|
|
viewer.entities.remove(mubiaoConicMap.get(id))
|
|
|
|
mubiaoConicMap.delete(id)
|
|
|
|
}
|
2024-12-09 06:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const updateMubiaoPos = async (
|
|
|
|
mbs: Array<Record<string, string | number>>
|
|
|
|
) => {
|
|
|
|
// const existsIds = [...mubiaoMap.keys()]
|
|
|
|
if (mbs.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
mbs.forEach(
|
|
|
|
({
|
|
|
|
target_id: id,
|
|
|
|
target_lon: lon,
|
|
|
|
target_lat: lat,
|
|
|
|
target_direction,
|
|
|
|
}) => {
|
|
|
|
if (mubiaoMap.has(id)) {
|
|
|
|
const entity = mubiaoMap.get(id)
|
|
|
|
const position = Cesium.Cartesian3.fromDegrees(lon, lat)
|
|
|
|
entity.position = position
|
2025-02-14 08:33:28 +00:00
|
|
|
// console.log(target_direction)
|
|
|
|
entity.billboard.rotation = Cesium.Math.toRadians(
|
|
|
|
360 - target_direction + 90
|
|
|
|
)
|
2024-12-09 06:44:52 +00:00
|
|
|
entity.orientation = getOrientation({
|
|
|
|
position,
|
|
|
|
heading: target_direction as number,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const getOrientation = ({
|
|
|
|
position,
|
|
|
|
heading,
|
|
|
|
pitch = 0,
|
|
|
|
roll = 0,
|
|
|
|
}: Record<string, number>) => {
|
|
|
|
//模型朝向
|
|
|
|
const h = Cesium.Math.toRadians(heading - 90)
|
|
|
|
const p = Cesium.Math.toRadians(pitch)
|
|
|
|
const r = Cesium.Math.toRadians(roll)
|
|
|
|
const hpr = new Cesium.HeadingPitchRoll(h, p, r)
|
|
|
|
const orientation = Cesium.Transforms.headingPitchRollQuaternion(
|
|
|
|
position,
|
|
|
|
hpr
|
|
|
|
)
|
|
|
|
return orientation
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
data,
|
2025-02-19 08:06:46 +00:00
|
|
|
checkedKeys,
|
|
|
|
getMubiaoData,
|
2024-12-09 06:44:52 +00:00
|
|
|
addMubiao,
|
|
|
|
updateMubiaoPos,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getMubiaoCurPos(ids: Array<string | number>) {
|
|
|
|
const time = cesiumTime2Format(viewer.clock.currentTime)
|
|
|
|
// 获取当前目标位置
|
|
|
|
const { code, data } = await getMubiaoPos({ ids, current: time })
|
|
|
|
if (code === '200') {
|
|
|
|
return data
|
|
|
|
} else {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
}
|
2025-02-19 08:06:46 +00:00
|
|
|
|
|
|
|
async function getMubiaoData() {
|
|
|
|
const checked = JSON.parse(JSON.stringify(checkedKeys.value))
|
|
|
|
// console.log(checked)
|
|
|
|
const { code, data: resData } = await getMubiao()
|
|
|
|
if (code === '200') {
|
|
|
|
data.value = [resData]
|
|
|
|
checkedKeys.value = []
|
|
|
|
getAllNodesToPayload()
|
|
|
|
nextTick(() => {
|
|
|
|
checkedKeys.value = checked
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllNodesToPayload() {
|
|
|
|
const mbList = getLeafNode(data.value[0])
|
|
|
|
mbList.forEach(node => {
|
|
|
|
const { dataId, data: nodeData } = node
|
|
|
|
const { extendInfo } = nodeData
|
|
|
|
const detectingShow =
|
2025-04-17 07:49:17 +00:00
|
|
|
mbPayloadShowMap.get(dataId)?.detectingPayload?.show || false;
|
2025-02-19 08:06:46 +00:00
|
|
|
if (extendInfo) {
|
|
|
|
mbPayloadShowMap.set(dataId, {
|
|
|
|
data: toRaw(nodeData),
|
|
|
|
detectingPayload: { ...extendInfo, show: detectingShow },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
console.log('mbPayloadShowMap', mbPayloadShowMap)
|
|
|
|
}
|