基于北京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
88
89
90
91
const mapPlan = {
  planListData: null,
  planStart: false,
  planIndex: null,
  planStopTime: null,
  planTimeOut: null,
  startTime: null,
  stopTime: null,
  Init(res) {
    if (!res.children || res.children == 0) return;
    if (this.planStart) {
      this.closed();
    }
    this.planIndex = 0;
    this.planListData = res.children;
    this.planStart = true;
    this.setPlanFlyStart();
    this.startTime = this.formatDate();
  },
  closed() {
    this.planStart = false;
    if (this.planTimeOut) {
      clearTimeout(this.planTimeOut);
      this.planTimeOut = null;
    }
    this.planIndex = 0;
    this.planListData = null;
    this.stopTime = this.formatDate();
    console.log("开始时间: " + this.startTime + "结束时间: " + this.stopTime);
  },
  setPlanFlyStart() {
    const obj = this.planListData[this.planIndex];
    this.planStopTime = obj.time;
    if (this.planTimeOut) {
      clearTimeout(this.planTimeOut);
      this.planTimeOut = null;
    }
    const that = this;
 
    try {
      earthCtrl.camera.flyTo(
        obj.lon,
        obj.lat,
        obj.alt,
        obj.height,
        obj.pitch,
        obj.roll,
        null,
        () => {
          this.setPlanFlyNext();
        }
      );
    } catch (e) {
      if (window.widget._showRenderLoopErrors) {
        var title =
          "开始时间: " + this.startTime + "结束时间: " + this.formatDate();
        window.widget.showErrorPanel(title, undefined, e);
      }
    }
  },
  setPlanFlyNext() {
    this.planIndex++;
    const time = this.planStopTime * 1000;
    this.planIndex =
      this.planIndex == this.planListData.length ? 0 : this.planIndex;
    if (this.planStart == true) {
      var that = this;
      this.planTimeOut = setTimeout(() => {
        that.setPlanFlyStart();
      }, time);
    }
  },
  formatDate(time) {
    //时间戳转日期
    let date = new Date();
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? "0" + MM : MM;
    let d = date.getDate();
    d = d < 10 ? "0" + d : d;
    let h = date.getHours();
    h = h < 10 ? "0" + h : h;
    let m = date.getMinutes();
    m = m < 10 ? "0" + m : m;
    let s = date.getSeconds();
    s = s < 10 ? "0" + s : s;
    return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
  }
};
 
export default mapPlan;