import { cartesianToXY } from "@/utils/map"; let water = null; /** * 销毁水体模拟层 */ export function destoryWaterPrimitive() { if (water) { water.destroy(); water = null; console.log("Water simulation destroyed."); } } /** * 创建水体模拟层 * @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, 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(`仿真模拟参数: 请求路径 ${baseUrl}, 帧间间隔 ${interval}ms, 是否开启专题渲染 ${colorRender}`); } /** * 初始化水体模拟视图 */ export function initeWaterPrimitiveView() { let view = { destination: { x: -2173603.2294639186, y: 4338938.333124211, z: 4128027.401463165, }, orientation: { pitch: -0.6208443477400212, roll: 0.000049799989940702005, heading: 3.6294612473618644, }, }; viewer.scene.camera.flyTo(view); // console.log("Camera view initialized for water simulation."); } /** * 暂停水体模拟 */ export function pauseWaterSimulation() { if (water) { water.pause(); console.log("暂停仿真"); } else { console.warn("No water simulation to pause."); } } /** * 恢复水体模拟 */ export function resumeWaterSimulation() { if (water) { water.resume(); console.log("继续仿真"); } else { console.warn("No water simulation to resume."); } } /** * 跳转到某个时间点的水面状态 * @param {number} closestIndex - 目标时间戳索引 */ export function setTimeForWaterSimulation(closestIndex) { if (water) { 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:[${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(`是否开启专题渲染 ${enabled}`); } else { console.warn("No water simulation to toggle color rendering."); } } /** * 时间戳回调函数 * @param {number} timeStamp - 当前时间戳 */ function timeCallback(timeStamp) { // console.log(`Current timestamp: ${timeStamp}`); }