From 89380e6260a75d1d3b94de687ebcc2f50d50659d Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Tue, 03 Feb 2026 15:44:33 +0800
Subject: [PATCH] feat:环境变量配置调整
---
applications/drone-command/src/utils/cesium/publicCesium.js | 86 +++++++++++++++++++-----------------------
1 files changed, 39 insertions(+), 47 deletions(-)
diff --git a/applications/drone-command/src/utils/cesium/publicCesium.js b/applications/drone-command/src/utils/cesium/publicCesium.js
index 7fb65d2..234d0e5 100644
--- a/applications/drone-command/src/utils/cesium/publicCesium.js
+++ b/applications/drone-command/src/utils/cesium/publicCesium.js
@@ -114,6 +114,9 @@
this.handlerRightEvents = { handler: null }
this.handlerMouseMoveEvents = { handler: null }
this.viewer = null
+ this.terrainProvider = null
+ this.terrainLoading = null
+ this.terrainEnabled = false
this.globalBaseMapLayers = []
this.boundary = null
this.init(options)
@@ -177,52 +180,7 @@
this.viewer?.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) // 禁用双击
- if (terrain) {
- try {
- const noTerrainMechanism = ['1962779164650135554']
- if (noTerrainMechanism.includes(store.state.user.userInfo?.deptId)) {
- // 使用Cesium World Terrain
- Cesium.createWorldTerrainAsync({
- requestWaterMask: false, // 请求水域效果
- requestVertexNormals: true // 请求光照和地形法线
- }).then(terrainProvider => {
- this.viewer.terrainProvider = terrainProvider
- terrainLoadCallback?.()
- })
- } else {
- /*// 正则:第一位非0,第二位任意数字,后10位都是0
- const re = /^[1-9]\d0{10}$/
-
- let result = null
-
- // 1️⃣先判断 areaCode
- if (re.test(store.state.user.userInfo.detail.areaCode)) {
- result = store.state.user.userInfo.detail.areaCode.slice(0, 6)
- } else {
- // 2️⃣如果不满足,从 ancestors 里找
- const matchedItems = store.state.user.userInfo.detail.ancestors
- .split(',')
- .filter(item => re.test(item)) // 过滤出符合条件的
-
- // 取第一个符合条件的前6位(可以改成 last one 看需求)
- if (matchedItems.length > 0) {
- result = matchedItems[0].slice(0, 6)
- }
- }
-
- // 使用公司地形
- Cesium.CesiumTerrainProvider.fromUrl(`${import.meta.env.VITE_APP_TERRAIN_URL}${result}`, {
- requestVertexNormals: true, // 启用地形法线增强立体感
- requestWaterMask: true, // 启用水体遮罩效果
- }).then(terrainProvider => {
- this.viewer.terrainProvider = terrainProvider
- terrainLoadCallback?.()
- })*/
- }
- } catch (error) {
- console.error('地形加载失败:', error)
- }
- }
+ this.setTerrainVisible(terrain, terrainLoadCallback)
this.viewer.scene.screenSpaceCameraController.maximumZoomDistance = 4500000
this.switchLayers(layerMode)
@@ -239,6 +197,40 @@
getViewer () {
return this.viewer
+ }
+
+ async ensureTerrainProvider () {
+ if (this.terrainProvider) return this.terrainProvider
+ if (this.terrainLoading) return this.terrainLoading
+ this.terrainLoading = Cesium.CesiumTerrainProvider.fromUrl(
+ `${import.meta.env.VITE_APP_TERRAIN_URL}ja_terrain`,
+ {
+ requestVertexNormals: true, // 启用地形法线增强立体感
+ requestWaterMask: true, // 启用水体遮罩效果
+ }
+ ).then(provider => {
+ this.terrainProvider = provider
+ return provider
+ })
+ return this.terrainLoading
+ }
+
+ async setTerrainVisible (visible, terrainLoadCallback) {
+ if (!this.viewer) return
+ if (!visible) {
+ this.viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider()
+ this.terrainEnabled = false
+ return
+ }
+ try {
+ const provider = await this.ensureTerrainProvider()
+ if (!this.viewer) return
+ this.viewer.terrainProvider = provider
+ this.terrainEnabled = true
+ terrainLoadCallback?.()
+ } catch (error) {
+ this.terrainEnabled = false
+ }
}
// 销毁viewer
@@ -912,4 +904,4 @@
this.viewer?.imageryLayers.remove(imageryLayers)
}
}
-}
\ No newline at end of file
+}
--
Gitblit v1.9.3