From 7217e02e098b94e421b5a85ec13e0cd2ed35fbeb Mon Sep 17 00:00:00 2001 From: wangjuncheng <1> Date: 星期五, 06 六月 2025 17:28:23 +0800 Subject: [PATCH] 1 --- src/utils/water.js | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/utils/water.js b/src/utils/water.js index e32c0dc..c9c543d 100644 --- a/src/utils/water.js +++ b/src/utils/water.js @@ -1,5 +1,8 @@ import { cartesianToXY } from "@/utils/map"; - +import { useSimStore } from "@/store/simulation"; +import { storeToRefs } from "pinia"; +const simStore = useSimStore(); +const { waterLegendData } = storeToRefs(simStore); let water = null; /** @@ -25,32 +28,49 @@ baseUrl = "/simu/c2h1dc", interval = 1000, colorRender = true, + minFlowRate = 0.1, // 鏂板鍙傛暟 + maxFlowRate = 12 // 鏂板鍙傛暟 } = options; + // 瀹氫箟姘存繁棰滆壊鏄犲皠鐨勮壊鏍� + const colorStops = [ + "#09a2dc", "#58c196", "#bedf74", "#d7f06e", + "#ffe930", "#fdd10a", "#feb652", "#fd7f06", + "#fe2b07", "#4d0a08" + ]; + // 鏋勯�� waterHeightLevels锛氫粠 min 鍒� max 浣跨敤鎸囨暟澧為暱锛岀‘淇濆皬鍊煎尯鍩熸洿瀵嗛泦 + const levelCount = colorStops.length; // 淇濇寔鍜岄鑹叉暟閲忎竴鑷� + const waterHeightLevels = []; + // 鎸囨暟澧為暱鍏紡锛歽 = base^x + const base = Math.exp(Math.log(maxFlowRate / minFlowRate) / (levelCount - 1)); + for (let i = 0; i < levelCount; i++) { + const ratio = i / (levelCount - 1); // 0 ~ 1 + // 浣跨敤鎸囨暟鎻掑�硷紝淇濊瘉浣庡�煎尯鍩熸洿瀵嗛泦 + const height = minFlowRate * Math.pow(base, i); + const color = colorStops[i]; + + waterHeightLevels.push({ + height: height.toFixed(2), // 鍙�夛細淇濈暀涓や綅灏忔暟 + color + }); + } + waterLegendData.value = waterHeightLevels + console.log(waterLegendData.value,'鍥鹃噷鏁版嵁'); + + // 鍒涘缓鍥惧眰 water = earthCtrl.simulate.createWaterSimulateLayer({ baseUrl, interval, color: new SmartEarth.Cesium.Color.fromCssColorString("#D4F2E7"), loop: false, callback: timeCallback, - alphaByDepth: -0.3, //娣卞害琛板噺锛屽�艰秺澶э紝姘撮潰瓒婇�忔槑. - waterHeightLevels: [ - { height: 0.5, color: "#09a2dc" }, - { height: 1.0, color: "#58c196" }, - { height: 1.5, color: "#bedf74" }, - { height: 2.0, color: "#d7f06e" }, - { height: 2.5, color: "#ffe930" }, - { height: 3.0, color: "#fdd10a" }, - { height: 4.0, color: "#feb652" }, - { height: 5.0, color: "#fd7f06" }, - { height: 10.0, color: "#fe2b07" }, - { height: 30.0, color: "#4d0a08" }, - ], - colorRender, // 鎺у埗鏄惁鍚敤棰滆壊娓叉煋 + alphaByDepth: -0.3, + waterHeightLevels, + colorRender, }); console.log( - `浠跨湡妯℃嫙鍙傛暟锛� 璇锋眰璺緞 ${baseUrl}, 甯ч棿闂撮殧 ${interval}ms, 鏄惁寮�鍚笓棰樻覆鏌� ${colorRender}` + `浠跨湡妯℃嫙鍙傛暟锛氳姹傝矾寰� ${baseUrl}, 甯ч棿闂撮殧 ${interval}ms, 鏄惁寮�鍚笓棰樻覆鏌� ${colorRender},鍥句緥鍙傛暟${waterHeightLevels}` ); } /** -- Gitblit v1.9.3