From 1d552a3bad95caae4af15322df28e6240b797693 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Thu, 13 Aug 2026 15:32:06 +0800
Subject: [PATCH] feat: app视频封面图

---
 applications/drone-command/src/utils/cesium/publicCesium.js |  108 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 61 insertions(+), 47 deletions(-)

diff --git a/applications/drone-command/src/utils/cesium/publicCesium.js b/applications/drone-command/src/utils/cesium/publicCesium.js
index 94c734e..dd8d318 100644
--- a/applications/drone-command/src/utils/cesium/publicCesium.js
+++ b/applications/drone-command/src/utils/cesium/publicCesium.js
@@ -20,7 +20,6 @@
 } = getBaseConfig()
 
 import { addBlueFilter } from '@/utils/cesium/common'
-import { useBoundary } from '@/utils/cesium/useBoundary'
 
 let smallMpaCenterDistance = null
 let curCameraHpr = null
@@ -114,8 +113,10 @@
 		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)
 	}
 
@@ -127,13 +128,7 @@
 			layerMode = 17,
 			contour = true,
 			flyToContour = false,
-			multiple = 1.4,
-			dockOptions = {},
-			boundaryChange,
 			terrainLoadCallback,
-			boundaryColor = '#00F9EC',
-			dockRangeType = 1,
-			useDockHeight = false
 		} = options
 		Cesium.Camera.DEFAULT_VIEW_FACTOR = -0.45
 		// 西南东北,默认显示中国
@@ -163,36 +158,19 @@
 		this.viewer.shadows = false
 		this.viewer.shadowMap.darkness = 0.5
 
-		let time = new Date()
-		time.setHours(12, 0, 0, 0)
-		let utc = Cesium.JulianDate.fromDate(new Date(time))
+		this.setFixedNoonLighting()
 
-		this.viewer.clockViewModel.currentTime = Cesium.JulianDate.addHours(utc, 0, new Cesium.JulianDate())
-
-		// 边界,机巢
-		this.boundary = useBoundary(this.viewer, { multiple, dockOptions, boundaryChange, boundaryColor, dockRangeType, useDockHeight })
 		this.viewer?.imageryLayers.removeAll()
 		this.viewer._cesiumWidget._creditContainer.style.display = 'none'
 		handler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
 
 		this.viewer?.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) // 禁用双击
 
-		if (terrain) {
-			// 使用公司地形
-			Cesium.CesiumTerrainProvider.fromUrl(`${import.meta.env.VITE_APP_TERRAIN_URL}ja_terrain`, {
-				requestVertexNormals: true, // 启用地形法线增强立体感
-				requestWaterMask: true, // 启用水体遮罩效果
-			}).then(terrainProvider => {
-				this.viewer.terrainProvider = terrainProvider
-				terrainLoadCallback?.()
-			})
-		}
+		this.setTerrainVisible(terrain, terrainLoadCallback)
 
 		this.viewer.scene.screenSpaceCameraController.maximumZoomDistance = 4500000
 		this.switchLayers(layerMode)
 		this.switchFlatMode(flatMode)
-		this.switchContour(contour)
-		flyToContour && this.flyToContour(contour)
 
 		if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
 			let dpr = window.devicePixelRatio
@@ -203,6 +181,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}/360000`,
+			{
+				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
@@ -253,25 +265,6 @@
 			cesiumContainer.remove() // 移除与地图相关的DOM元素
 			this.viewerDom = null
 		}
-	}
-
-	setShowDock (sns) {
-		this.boundary?.setShowDock(sns)
-	}
-	setDockCoverColor (sns) {
-		this.boundary?.setDockCoverColor(sns)
-	}
-	// 切换轮廓显示
-	async switchContour (open) {
-		if (open) {
-			await this.boundary?.openContour()
-		} else {
-			this.boundary?.closeContour()
-		}
-	}
-	// 飞向轮廓居中
-	flyToContour () {
-		this.boundary?.flyToBoundary()
 	}
 
 	// 飞行 flyto
@@ -876,4 +869,25 @@
 			this.viewer?.imageryLayers.remove(imageryLayers)
 		}
 	}
-}
\ No newline at end of file
+
+	setFixedNoonLighting (utcOffsetHours = 8) {
+		if (!this.viewer) return
+		const now = new Date()
+		const utcNoon = Date.UTC(
+			now.getUTCFullYear(),
+			now.getUTCMonth(),
+			now.getUTCDate(),
+			12 - Number(utcOffsetHours || 0),
+			0,
+			0,
+			0
+		)
+		const julian = Cesium.JulianDate.fromDate(new Date(utcNoon))
+		this.viewer.clock.currentTime = julian
+		this.viewer.clockViewModel.currentTime = julian
+		this.viewer.clock.shouldAnimate = false
+		this.viewer.clock.multiplier = 0
+		this.viewer.clockViewModel.multiplier = 0
+		this.viewer.scene.requestRender()
+	}
+}

--
Gitblit v1.9.3