From 7abab3d5474858f58ddd96bebbdf0379ddd1aa77 Mon Sep 17 00:00:00 2001
From: husq <931347610@qq.com>
Date: Tue, 17 Oct 2023 15:17:00 +0800
Subject: [PATCH] 飞机起飞时实时位置更新
---
src/hooks/use-cesium-tsa.ts | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/hooks/use-cesium-tsa.ts b/src/hooks/use-cesium-tsa.ts
index d2153cc..bbf48af 100644
--- a/src/hooks/use-cesium-tsa.ts
+++ b/src/hooks/use-cesium-tsa.ts
@@ -27,6 +27,9 @@
billboard?: billboardSetting
label?: labelSetting
id?: string
+ heading?: number
+ pitch?: number
+ roll?: number
}
// 定义全局的viewer变量防止重复生成
// eslint-disable-next-line no-var
@@ -140,12 +143,15 @@
// 添加标记点
const addPoint = (pointOption: pointOption) => {
if (!pointOption.longitude && !pointOption.latitude) return
+ const position = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude)
+ const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, new Cesium.HeadingPitchRoll(pointOption.heading, pointOption.pitch, pointOption.roll))
viewer?.entities.add({
position: Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude),
billboard: pointOption.billboard,
point: pointOption.point,
label: pointOption.label,
id: pointOption.id,
+ orientation
})
}
@@ -157,7 +163,24 @@
viewer?.entities.remove(pointEntity)
}
}
-
+ // 通过点ID获取实体
+ function getEntityById (id:string) {
+ const pointEntity = viewer?.entities.getById(id)
+ return pointEntity
+ }
+ // 更新实体位置
+ function updateEntityPosition (longitude:number, latitude:number, id:string, params?:any) {
+ const entity = getEntityById(id) as Cesium.Entity
+ const position = Cesium.Cartesian3.fromDegrees(longitude, latitude)
+ const heading = Cesium.Math.toRadians(params.heading)
+ const pitch = Cesium.Math.toRadians(params.pitch)
+ const roll = Cesium.Math.toRadians(params.roll)
+ const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, new Cesium.HeadingPitchRoll(heading, pitch, roll))
+ if (Cesium.defined(entity)) {
+ entity.position = position
+ entity.orientation = orientation
+ }
+ }
// 飞行 flyto
const flyTo = (pointOption: pointOption, time: number = 4) => {
if (!pointOption.longitude && !pointOption.latitude) return
@@ -256,6 +279,8 @@
zoonIn,
zoonOut,
roadPattern,
- patternMap
+ patternMap,
+ getEntityById,
+ updateEntityPosition
}
}
--
Gitblit v1.9.3