wangjuncheng
2025-05-27 27fe8d3da9d8fea525656d82c28e10f0c2f5935d
src/utils/water.js
@@ -21,7 +21,11 @@
 * @param {boolean} options.colorRender - 是否启用颜色渲染
 */
export function createWaterPrimitive(options = {}) {
  const { baseUrl = "/simu/c2h1dc", interval = 1000, colorRender = true } = options;
  const {
    baseUrl = "/simu/c2h1dc",
    interval = 1000,
    colorRender = true,
  } = options;
  water = earthCtrl.simulate.createWaterSimulateLayer({
    baseUrl,
@@ -29,6 +33,7 @@
    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" },
@@ -39,11 +44,14 @@
      { height: 4.0, color: "#feb652" },
      { height: 5.0, color: "#fd7f06" },
      { height: 10.0, color: "#fe2b07" },
      { height: 30.0, color: "#4d0a08" },
    ],
    colorRender, // 控制是否启用颜色渲染
  });
  console.log(`Water simulation started with baseUrl: ${baseUrl}, interval: ${interval}ms, colorRender: ${colorRender}`);
  console.log(
    `仿真模拟参数: 请求路径 ${baseUrl}, 帧间间隔 ${interval}ms, 是否开启专题渲染 ${colorRender}`
  );
}
/**
 * 初始化水体模拟视图
@@ -62,7 +70,7 @@
    },
  };
  viewer.scene.camera.flyTo(view);
  console.log("Camera view initialized for water simulation.");
  // console.log("Camera view initialized for water simulation.");
}
/**
@@ -71,7 +79,7 @@
export function pauseWaterSimulation() {
  if (water) {
    water.pause();
    console.log("Water simulation paused.");
    console.log("暂停仿真");
  } else {
    console.warn("No water simulation to pause.");
  }
@@ -83,7 +91,7 @@
export function resumeWaterSimulation() {
  if (water) {
    water.resume();
    console.log("Water simulation resumed.");
    console.log("继续仿真");
  } else {
    console.warn("No water simulation to resume.");
  }
@@ -101,9 +109,10 @@
      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}]`);
    // 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.");
@@ -117,7 +126,7 @@
export function toggleWaterColorRender(enabled) {
  if (water) {
    water.colorRender = enabled;
    console.log(`Water color render set to: ${enabled}`);
    console.log(`是否开启专题渲染 ${enabled}`);
  } else {
    console.warn("No water simulation to toggle color rendering.");
  }
@@ -129,4 +138,4 @@
 */
function timeCallback(timeStamp) {
  // console.log(`Current timestamp: ${timeStamp}`);
}
}