基于北京SDK的方案预演功能
suerprisePlus
2024-06-13 28de79b44655118b1deffb5c9a8b06ec2904905b
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
import configTool from "@/assets/js/tool/configTool";
import store from "@/store";
const palyTools = {
  playIndex: 0,
  isPlay: false,
  data: null,
  time: null,
  depthTestAgainstTerrain: null,
  Init(res) {
    if (res.sourceType != "demoAnimation") return;
    this.data = res.animationDatas;
    this.playIndex = 0;
    this.isPlay = true;
    this.playStart();
    this.depthTestAgainstTerrain = Viewer.scene.globe.depthTestAgainstTerrain;
    if (this.depthTestAgainstTerrain) {
      Viewer.scene.globe.depthTestAgainstTerrain = false;
    }
  },
  stop() {
    clearTimeout(this.time);
    this.time = null;
    this.playIndex = 0;
    this.isPlay = false;
    Viewer.scene.globe.depthTestAgainstTerrain = this.depthTestAgainstTerrain;
    this.depthTestAgainstTerrain = null;
  },
  playStart() {
    if (this.playIndex > this.data.length - 1) {
      this.stop();
      return;
    } else if (!this.isPlay) {
      return;
    }
 
    let thisPlay = this.data[this.playIndex];
 
    if (thisPlay.type === "位置") {
      let position = thisPlay.view;
      Viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(
          position.lon,
          position.lat,
          position.height
        ),
        orientation: {
          heading: Cesium.Math.toRadians(position.heading),
          pitch: Cesium.Math.toRadians(position.pitch),
          roll: 0,
        },
      });
    } else if (thisPlay.type === "操作") {
      let show;
      if (thisPlay.actionType === "显示对象") {
        show = true;
      } else if (thisPlay.actionType === "隐藏对象") {
        show = false;
      }
      store.state.setAnimation = {
        info: thisPlay.selectInfo,
        show: show,
      };
    }
    let time = 0;
    if (thisPlay.type === "位置") {
      time = 3;
    }
    if (thisPlay.time) {
      this.timeOut(() => {
        // 定时
        this.playIndex++;
        this.playStart();
      }, thisPlay.time + time);
    } else {
      this.timeOut(() => {
        // 定时
        this.playIndex++;
        this.playStart();
      }, time);
    }
  },
  timeOut(callback, time) {
    clearTimeout(this.time);
    this.time = setTimeout(callback, time * 1000);
  },
};
export default palyTools;