From 54849757852f6ab40eb17afbd03d1d839b60a38d Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 13 Nov 2023 17:09:15 +0800
Subject: [PATCH] 重复定时和连续执行
---
src/hooks/use-cesium-tsa.ts | 47 ++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/src/hooks/use-cesium-tsa.ts b/src/hooks/use-cesium-tsa.ts
index 7b03f6d..057c3e7 100644
--- a/src/hooks/use-cesium-tsa.ts
+++ b/src/hooks/use-cesium-tsa.ts
@@ -20,13 +20,22 @@
outlineWidth: number,
[key: string]: any
}
+interface polyline {
+ width?: number
+ material?: Cesium.Color
+ [key: string]: any
+}
interface pointOption {
longitude: number
latitude: number
point?: pointSetting
billboard?: billboardSetting
+ polyline?: polyline
label?: labelSetting
id?: string
+ heading?: number
+ pitch?: number
+ roll?: number
}
// 定义全局的viewer变量防止重复生成
// eslint-disable-next-line no-var
@@ -140,11 +149,20 @@
// 添加标记点
const addPoint = (pointOption: pointOption) => {
if (!pointOption.longitude && !pointOption.latitude) return
+ const position = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude)
viewer?.entities.add({
- position: Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude),
+ position,
billboard: pointOption.billboard,
point: pointOption.point,
label: pointOption.label,
+ id: pointOption.id,
+ })
+ }
+
+ // 添加线段
+ const addPolyline = (pointOption: pointOption) => {
+ viewer?.entities.add({
+ polyline: pointOption.polyline,
id: pointOption.id,
})
}
@@ -157,11 +175,25 @@
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)
+ if (Cesium.defined(entity)) {
+ entity.position = position
+ entity.billboard.rotation = heading
+ }
+ }
// 飞行 flyto
- const flyTo = (pointOption: pointOption, time: number = 4) => {
+ const flyTo = (pointOption: pointOption, time: number = 4, height:number = 3000) => {
if (!pointOption.longitude && !pointOption.latitude) return
- const destination = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude, 3000)
+ const destination = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude, height)
const duration = time
viewer?.camera.flyTo({
destination,
@@ -220,7 +252,6 @@
// 切换不同背景图层
const patternMap = () => {
const imageryLayers = viewer?.scene.imageryLayers
- console.log(imageryLayers, 'imageryLayers')
// 切换为标准图层
if (store.state.common.mapSetting.mode === 0) {
const tdtImg_c = imageryLayers?._layers.find(v => v.imageryProvider._layer === 'tdtImg_c')
@@ -230,7 +261,6 @@
} else {
const tdtStand_c = imageryLayers?._layers.find(v => v.imageryProvider.credit.html === 'stand_tc')
const tdtStand_zj = imageryLayers?._layers.find(v => v.imageryProvider.credit.html === 'stand_zj')
- console.log(tdtStand_c, tdtStand_zj, '===========================')
viewer?.imageryLayers.remove(tdtStand_c)
viewer?.imageryLayers.remove(tdtStand_zj)
}
@@ -258,6 +288,9 @@
zoonIn,
zoonOut,
roadPattern,
- patternMap
+ patternMap,
+ getEntityById,
+ updateEntityPosition,
+ addPolyline
}
}
--
Gitblit v1.9.3