| | |
| | | */ |
| | | export function destoryWaterPrimitive() { |
| | | if (water) { |
| | | enableWaterArrowFlow(false); |
| | | water.destroy(); |
| | | water = null; |
| | | console.log("Water simulation destroyed."); |
| | |
| | | * @param {string} options.baseUrl - 仿真服务地址 |
| | | * @param {boolean} options.colorRender - 是否启用颜色渲染 |
| | | */ |
| | | export function createWaterPrimitive(options = {}) { |
| | | export async function createWaterPrimitive(options = {}) { |
| | | const { |
| | | baseUrl = "/simu/c2h1dc", |
| | | interval = 1000, |
| | | colorRender = true, |
| | | minFlowRate = 0.1, // 新增参数 |
| | | maxFlowRate = 12 // 新增参数 |
| | | minFlowRate = 0.1, // 新增参数 |
| | | maxFlowRate = 12, // 新增参数 |
| | | } = options; |
| | | |
| | | // 定义水深颜色映射的色标 |
| | | const colorStops = [ |
| | | "#09a2dc", "#58c196", "#bedf74", "#d7f06e", |
| | | "#ffe930", "#fdd10a", "#feb652", "#fd7f06", |
| | | "#fe2b07", "#4d0a08" |
| | | "#09a2dc", |
| | | "#58c196", |
| | | "#bedf74", |
| | | "#d7f06e", |
| | | "#ffe930", |
| | | "#fdd10a", |
| | | "#feb652", |
| | | "#fd7f06", |
| | | "#fe2b07", |
| | | "#4d0a08", |
| | | ]; |
| | | |
| | | const levelCount = colorStops.length; |
| | | const minAllowed = 0.01; // 最小允许值 |
| | | const threshold = 1; // 小值与大值分界点 |
| | | const minAllowed = 0.005; // 最小允许值 |
| | | const threshold = 1; // 小值与大值分界点 |
| | | |
| | | let effectiveMin = Math.max(minFlowRate, minAllowed); // 最小不能小于 0.01 |
| | | |
| | |
| | | |
| | | waterHeightLevels.push({ |
| | | height: parseFloat(height.toFixed(2)), // 保留两位小数 |
| | | color: colorStops[i] |
| | | color: colorStops[i], |
| | | }); |
| | | } |
| | | |
| | | waterLegendData.value = waterHeightLevels; |
| | | console.log(waterLegendData.value, '图例数据'); |
| | | console.log(waterLegendData.value, "图例数据"); |
| | | |
| | | // 创建图层 |
| | | water = earthCtrl.simulate.createWaterSimulateLayer({ |
| | | water = await earthCtrl.simulate.createWaterSimulateLayer({ |
| | | baseUrl, |
| | | interval, |
| | | color: SmartEarth.Cesium.Color.fromCssColorString("#D4F2E7"), |
| | |
| | | alphaByDepth: -0.3, |
| | | waterHeightLevels, |
| | | colorRender, |
| | | sizeIndex:0, |
| | | sizeIndex: 0, |
| | | }); |
| | | |
| | | enableWaterArrowFlow(true); |
| | | toggleWaterShadow(false); |
| | | console.log( |
| | | `仿真模拟参数:请求路径 ${baseUrl}, 帧间间隔 ${interval}ms, 是否开启专题渲染 ${colorRender}` |
| | | ); |
| | |
| | | console.warn("No water simulation to toggle color rendering."); |
| | | } |
| | | } |
| | | // ==================【SDK 新增功能 - 箭头流向 & 阴影控制】================== |
| | | |
| | | /** |
| | | * 开启/关闭箭头流向动画 |
| | | * @param {boolean} enabled - 是否启用箭头动画 |
| | | */ |
| | | export function enableWaterArrowFlow(enabled) { |
| | | if (water) { |
| | | water.arrowEnabled = enabled; // 假设 SDK 支持此属性 |
| | | console.log(`箭头流向动画已${enabled ? "开启" : "关闭"}`); |
| | | } else { |
| | | console.warn("未找到水体模拟图层,请先启动洪水模拟"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 开启/关闭全局阴影效果 |
| | | * @param {boolean} enabled - 是否启用阴影 |
| | | */ |
| | | export function toggleWaterShadow(enabled) { |
| | | if (!viewer) { |
| | | console.warn("Cesium Viewer 未初始化,无法设置阴影"); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | earthCtrl.shadows = enabled; |
| | | if (enabled) { |
| | | earthCtrl.shadowMap.maximumDistance = 10000.0; //最大距离 |
| | | earthCtrl.shadowMap.pointLightRadius = 50.0; //点光源半径 |
| | | } |
| | | console.log(`阴影效果已${enabled ? "开启" : "关闭"}`); |
| | | } catch (error) { |
| | | console.error("设置阴影失败:", error); |
| | | } |
| | | } |
| | | |
| | | // ================================================== |
| | | /** |
| | | * 时间戳回调函数 |
| | | * @param {number} timeStamp - 当前时间戳 |
| | | */ |