1
wangjuncheng
2025-04-29 50a7a0eda3810e97bb19f9b989b727d834bcc24c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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 - 水体模拟的时间间隔(单位:毫秒)
 */
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`);
}
 
/**
 * 初始化水体模拟视图
 */
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("Water simulation paused.");
  } else {
    console.warn("No water simulation to pause.");
  }
}
 
/**
 * 恢复水体模拟
 */
export function resumeWaterSimulation() {
  if (water) {
    water.resume();
    console.log("Water simulation resumed.");
  } else {
    console.warn("No water simulation to resume.");
  }
}
 
/**
 * 跳转到某个时间点的水面状态
 */
export function setTimeForWaterSimulation(closestIndex) {
  console.log(closestIndex,'index');
  
  if (water) {
    const imageList = water.getTimeList(); // 获取所有可用时间戳
    if (imageList.length === 0) {
      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]); // 设置时间戳,跳转到对应时刻
  } else {
    console.warn("No water simulation to set time for.");
  }
}
 
/**
 * 时间戳回调函数
 * @param {number} timeStamp - 当前时间戳
 */
function timeCallback(timeStamp) {
  // console.log(`Current timestamp: ${timeStamp}`);
}