From 73a564604a256f2d3be4ac061433b4e8b75d8e47 Mon Sep 17 00:00:00 2001
From: husq <931347610@qq.com>
Date: Sun, 08 Oct 2023 16:30:49 +0800
Subject: [PATCH] 2 3维切换
---
src/hooks/use-cesium-tsa.ts | 29 ++++++++++++++++++++++++++++-
src/components/cesiumMap/cesium.vue | 15 +++++++++------
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/src/components/cesiumMap/cesium.vue b/src/components/cesiumMap/cesium.vue
index ac94a02..95931bf 100644
--- a/src/components/cesiumMap/cesium.vue
+++ b/src/components/cesiumMap/cesium.vue
@@ -12,11 +12,11 @@
>
</a-auto-complete>
</div>
- <!-- <div class="switch">
- <div class="2d" v-if="dimension === 3" @click="switchModel('2D')">2D</div>
- <div class="3d" v-else @click="switchModel('3D')">3D</div>
- </div> -->
-</template>
+ <div class="switch">
+ <div class="2d" v-if="dimension === 2" @click="switchDimension('3D')">2D</div>
+ <div class="3d" v-else @click="switchDimension('2D')">3D</div>
+ </div>
+</template>\
<script setup lang="ts">
import { ref, } from 'vue'
@@ -57,7 +57,7 @@
}
}
const searchLocation = _.debounce(search, 500)
-const { flyTo, addPoint, removeById } = cesiumOperation()
+const { flyTo, addPoint, removeById, switchModel, dimension } = cesiumOperation()
const enter = (e:string) => {
removeById('key')
const filterItem = resultList.value.find(v => v.value === e)
@@ -86,6 +86,9 @@
addPoint({ ...pointParams, ...params })
flyTo(params)
}
+const switchDimension = (type:string) => {
+ switchModel(type)
+}
</script>
<style scoped lang="scss">
diff --git a/src/hooks/use-cesium-tsa.ts b/src/hooks/use-cesium-tsa.ts
index 9a81920..4ed342b 100644
--- a/src/hooks/use-cesium-tsa.ts
+++ b/src/hooks/use-cesium-tsa.ts
@@ -32,6 +32,7 @@
var viewer: Cesium.Viewer | null = null
export function cesiumOperation () {
let handler: Cesium.ScreenSpaceEventHandler
+ const dimension = ref(3)
const _init = () => {
if (viewer) return
// Cesium Token
@@ -135,6 +136,30 @@
duration
})
}
+
+ // 二维三维切换
+ // 切换为二三维模式
+ const switchModel = (type: string) => {
+ switch (type) {
+ case '2D':
+ viewer?.scene.camera.setView({
+ orientation: {
+ pitch: Cesium.Math.toRadians(-60),
+ heading: Cesium.Math.toRadians(0),
+ }
+ })
+ dimension.value = 2
+ break
+ case '3D':
+ viewer?.scene.camera.setView({
+ orientation: {
+ pitch: Cesium.Math.toRadians(-90),
+ heading: Cesium.Math.toRadians(0),
+ }
+ })
+ dimension.value = 3
+ }
+ }
onMounted(() => {
if (viewer) return
_init()
@@ -151,6 +176,8 @@
addPoint,
removeAllPoint,
flyTo,
- removeById
+ removeById,
+ switchModel,
+ dimension
}
}
--
Gitblit v1.9.3