From e7be05464134cb01ee3a9da428cada4758acd227 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Sat, 27 Sep 2025 15:53:54 +0800
Subject: [PATCH] feat:地形加载方式调整
---
src/utils/cesium/publicCesium.js | 28 ++++++++++++++++++++++++----
1 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/utils/cesium/publicCesium.js b/src/utils/cesium/publicCesium.js
index 97b0f8a..7af504f 100644
--- a/src/utils/cesium/publicCesium.js
+++ b/src/utils/cesium/publicCesium.js
@@ -143,8 +143,28 @@
this.viewer?.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) // 禁用双击
if (terrain) {
+ // 正则:第一位非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)
+ }
+ }
+
try {
- Cesium.CesiumTerrainProvider.fromUrl(`${import.meta.env.VITE_APP_TERRAIN_URL}`, {
+ Cesium.CesiumTerrainProvider.fromUrl(`${import.meta.env.VITE_APP_TERRAIN_URL}${result}`, {
requestVertexNormals: true, // 启用地形法线增强立体感
requestWaterMask: true, // 启用水体遮罩效果
}).then(terrainProvider => {
@@ -209,7 +229,7 @@
async switchContour (open) {
if (open) {
await this.boundary?.openContour()
-
+
} else {
this.boundary?.closeContour()
}
@@ -752,7 +772,7 @@
Cesium.Cartesian3.subtract(a, this.viewer?.camera.position, a),
Cesium.Cartesian3.normalize(r, r),
Cesium.Cartesian3.normalize(a, a)) : (r = c.direction,
- a = h.direction)
+ a = h.direction)
let d = Cesium.Cartesian3.dot(r, a)
, p = 0
return d < 1 && (p = Math.acos(d)),
@@ -781,7 +801,7 @@
, r = Cesium.Math.acosClamped(-e)
a > 0 && a > r && (a = r - Cesium.Math.EPSILON4),
r = Cesium.Math.acosClamped(e),
- a < 0 && -a > r && (a = -r + Cesium.Math.EPSILON4)
+ a < 0 && -a > r && (a = -r + Cesium.Math.EPSILON4)
}
return a
}
--
Gitblit v1.9.3