| | |
| | | * 创建水体模拟层 |
| | | * @param {Object} options - 可选参数 |
| | | * @param {number} options.interval - 水体模拟的时间间隔(单位:毫秒) |
| | | * @param {string} options.baseUrl - 仿真服务地址 |
| | | * @param {boolean} options.colorRender - 是否启用颜色渲染 |
| | | */ |
| | | export function createWaterPrimitive(options = {}) { |
| | | const { baseUrl = "/simu/c2h1dc", interval = 1000 } = options; // 默认 baseUrl 和 interval |
| | | |
| | | water = earthCtrl.simulate.createWaterSimulateLayer({ |
| | | baseUrl, // 仿真服务 URL |
| | | interval, // 动态设置 interval |
| | | color: new SmartEarth.Cesium.Color.fromCssColorString("#D4F2E7"), |
| | | loop: false, // 是否循环播放 |
| | | callback: timeCallback, // 回调函数 |
| | | }); |
| | | console.log(`Water simulation started with baseUrl: ${baseUrl}, interval: ${interval}ms`); |
| | | } |
| | | const { baseUrl = "/simu/c2h1dc", interval = 1000, colorRender = true } = options; |
| | | |
| | | water = earthCtrl.simulate.createWaterSimulateLayer({ |
| | | baseUrl, |
| | | interval, |
| | | color: new SmartEarth.Cesium.Color.fromCssColorString("#D4F2E7"), |
| | | loop: false, |
| | | callback: timeCallback, |
| | | 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" }, |
| | | ], |
| | | colorRender, // 控制是否启用颜色渲染 |
| | | }); |
| | | |
| | | console.log(`Water simulation started with baseUrl: ${baseUrl}, interval: ${interval}ms, colorRender: ${colorRender}`); |
| | | } |
| | | /** |
| | | * 初始化水体模拟视图 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 跳转到某个时间点的水面状态 |
| | | * @param {number} closestIndex - 目标时间戳索引 |
| | | */ |
| | | export function setTimeForWaterSimulation(closestIndex) { |
| | | console.log(closestIndex,'index'); |
| | | |
| | | if (water) { |
| | | const imageList = water.getTimeList(); // 获取所有可用时间戳 |
| | | if (imageList.length === 0) { |
| | | const imageList = water.getTimeList(); |
| | | |
| | | if (!imageList.length) { |
| | | console.warn("No timestamps available for water simulation."); |
| | | return; |
| | | } |
| | | const idx = Math.floor(Math.random() * imageList.length); // 随机选择一个时间戳 |
| | | console.log( |
| | | `Jumping to timestamp: count:[${imageList.length}], index:[${idx}]` |
| | | ); |
| | | |
| | | water.setTime(imageList[closestIndex]); // 设置时间戳,跳转到对应时刻 |
| | | |
| | | const idx = Math.floor(Math.random() * imageList.length); |
| | | console.log(`Jumping to timestamp: count:[${imageList.length}], index:[${closestIndex}]`); |
| | | water.setTime(imageList[closestIndex]); |
| | | } else { |
| | | console.warn("No water simulation to set time for."); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置或关闭颜色渲染 |
| | | * @param {boolean} enabled |
| | | */ |
| | | export function toggleWaterColorRender(enabled) { |
| | | if (water) { |
| | | water.colorRender = enabled; |
| | | console.log(`Water color render set to: ${enabled}`); |
| | | } else { |
| | | console.warn("No water simulation to toggle color rendering."); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 时间戳回调函数 |
| | | * @param {number} timeStamp - 当前时间戳 |
| | | */ |