riku
2024-12-27 1c31659852f8360cc0fdfac26aff51e54b8b8b67
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { FrameAnimation } from '@/model/FrameAnimation';
import { map } from '@/utils/map/index_old';
import SatelliteProxy from '@/views/satellitetelemetry/SatelliteProxy';
import { unref } from 'vue';
 
function GridAnimation() {
  // 帧动画控制工具
  this.frameAnimation = new FrameAnimation();
  this.frameAnimation.fps = 4;
  this.frameAnimation.timeout = 1000;
  // 地图绘制图形缓存
  this.mapViews = {};
  // 两天之间的卫星遥测动画播放时间
  this.duration = 4;
  // 地图网格相关对象
  this.mapViews = undefined;
}
 
GridAnimation.prototype = {
  /**
   * 开始动画
   * @param {Array} datas 一组卫星遥测网格数据
   */
  startAnimation(data, drawAnimation) {
    // const frameData = this.dataPrepare(data);
    this.nextAnimation(data, drawAnimation);
  },
  /**
   *
   * @param {*} data
   * @param {*} startIndex
   * @param {*} endIndex
   * @returns
   */
  nextAnimation(data, drawAnimation) {
    if (data == undefined) return;
    // for (let i = startIndex; i < data.length - 1; i++) {
    //   // 终点
    //   if (i == endIndex || i == data.length - 1) {
    //     break;
    //   }
    //   const animationData = data.slice(i, i + 2)
    //   // 数据插帧计算
    //   const { count, frameData } = this.dataPrepare(animationData);
    //   // 加入帧动画任务
    //   this.frameAnimation.addTask(count, frameData, drawAnimation);
    // }
    // 数据插帧计算
    const { count, frameData } = this.dataPrepare(data);
    // 加入帧动画任务
    this.frameAnimation.addTask(count, frameData, drawAnimation);
 
    this.start();
  },
  /**
   * 数据准备
   * 对数据进行插帧处理,插入每一帧对应的颜色和数值
   */
  dataPrepare(data) {
    const frameData = [];
    const count = this.duration * this.frameAnimation.fps;
 
    for (let i = 0; i < data.length; i++) {
      // 最后一组数据直接插入
      if (i == data.length - 1) {
        frameData.push(unref(data[i]));
      }
      // 其他数据进行插帧计算
      else {
        const d1 = unref(data[i]);
        const d2 = unref(data[i + 1]);
        const offsets = [];
        d1.forEach((value, i) => {
          let d = 0;
          if (
            typeof d2[i].pm25 === 'number' &&
            typeof value.pm25 === 'number'
          ) {
            d = (d2[i].pm25 - value.pm25) / count;
          }
          offsets.push(d);
        });
        frameData.push(d1);
        // d2 在下一次循环作为 d1 插入动画数据组里
        for (let t = 1; t < count; t++) {
          const tmpData = d1.map((v, i) => {
            const newData = { ...v };
            if (typeof newData.pm25 === 'number') {
              newData.pm25 += offsets[i] * t;
            }
            newData.pm25 = Math.round(newData.pm25 * 100) / 100;
            return newData;
          });
          frameData.push(unref(tmpData));
        }
      }
    }
 
    return { frameData, count: count * (data.length - 1) };
  },
 
  // drawAnimation(data, index, count) {
  //   SatelliteProxy.clearText(this.mapViews);
  //   this.mapViews.textViews = SatelliteProxy.drawDataText(
  //     this.mapViews.points,
  //     this.gridData,
  //     this.mapViews.textViews
  //   );
  //   SatelliteProxy.drawColor(this.mapViews.gridViews, gridData);
  // },
 
  /*******************************动画任务逻辑 -start ******************************/
  start: function () {
    if (this.frameAnimation.isStop) {
      // sector.clearSector();
    }
    this.frameAnimation.start();
  },
  changeSpeed: function (speed) {
    this.frameAnimation.changeSpeed(speed);
  },
  pause: function () {
    this.frameAnimation.pause();
  },
  stop: function () {
    // this.factorDatas = undefined;
    this.frameAnimation.addOnNextTasks(undefined);
    // this.OnEachFrameCallback = undefined;
    // this.OnEachTaskEndCallback = undefined;
    this.frameAnimation.stop();
    // this._clearMap();
  },
  setOnStopCallback: function (callback) {
    this.frameAnimation.setOnStopCallback(
      function () {
        callback();
      }.bind(this)
    );
  },
 
  runStatus() {
    return this.frameAnimation.runStatus();
  },
 
  /**
   * 设置是否开启动态绘制速度
   */
  setDynamicSpeed(b, sec) {
    if (b) {
      this.frameAnimation.dynamicSpeed = true;
      this.frameAnimation.taskPeriod = sec;
    } else {
      this.frameAnimation.dynamicSpeed = false;
      this.frameAnimation.taskPeriod = sec;
    }
  }
};
 
export { GridAnimation };