riku
2025-07-10 2cffd9c7db5c3191cf172641c800e5a328d6f3af
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import { Factor } from './Factor';
import calculate from '@/utils/map/calculate';
import { Legend } from './Legend';
import moment from 'moment';
 
/**
 *
 */
function FactorDatas(options) {
  // 时间
  this.times = [];
  // 原始经纬度(GPS)
  this.lnglats_GPS = [];
  // 高德经纬度
  this.lnglats_GD = [];
  // (高德地图)转换后的3d地图绘制坐标
  this.coors_GD = [];
  // 监测因子数据,Map<String, Factor>
  this.factor = new Map();
 
  this.legendType = Legend.S_TYPE; //图例模式
 
  // if (options != undefined) {
  //   this.times = options.times;
  //   this.lnglats_GPS = options.lnglats_GPS;
  //   this.lnglats_GD = options.lnglats_GD;
  //   this.coors_GD = options.coors_GD;
  //   this.factor = options.factor;
  //   this.legendType = options.legendType;
  // }
 
  if (typeof options === 'object') {
    for (const key in options) {
      if (Object.prototype.hasOwnProperty.call(options, key)) {
        const value = options[key];
        this[key] = value;
      }
    }
  }
}
 
FactorDatas.prototype = {
  /**
     * @param drawMode 绘制模式,0:自动模式,自动计算当前数据的范围,绘制合适的比例;1:手动模式,根据页面设置的绘图范围进行绘制
     * @param  dataList 结构如下
     * [{
        "time": "2021-04-21 21:11:59",
        "deviceCode": "0a",
        "lng": 121.229385,
        "lat": 30.828487
        "values": [
            {
            "factorId": "1",
            "factorName": "NO2",
            "sensorId": null,
            "factorData": 65.4,
            "physicalQuantity": 215.39,
            "statusList": null
            },
        ],
        }]
        */
  setData: function (dataList, drawMode, callback) {
    if (dataList.length == 0) {
      return;
    }
    this.clearData();
 
    dataList.forEach((d) => {
      this.times.push(d.time);
      this.lnglats_GPS.push([d.lng, d.lat]);
      d.values.forEach((v) => {
        var f = this.factor[v.factorId];
        if (f == undefined) {
          f = new Factor({
            legendType: this.legendType
          });
          this.factor[v.factorId] = f;
        }
        f.pushData(v, drawMode == undefined ? 0 : drawMode);
      });
    });
 
    this.convertGPS(this.lnglats_GPS, callback);
  },
 
  // 新增一个新数据
  addData: function (dataList, drawMode, callback) {
    if (dataList.length == 0) {
      return;
    }
 
    var newGps = [];
    dataList.forEach((data) => {
      this.times.push(data.time);
      this.lnglats_GPS.push([data.lng, data.lat]);
      newGps.push([data.lng, data.lat]);
      // this.coors_GD: 3d地图的坐标通过第一次绘制之后获得
      data.values.forEach((d) => {
        var f = this.factor[d.factorId];
        if (f == undefined) {
          f = new Factor();
          this.factor[d.factorId] = f;
        }
        f.pushData(d, drawMode == undefined ? 0 : drawMode);
      });
    });
    this.convertGPS(newGps, callback);
  },
 
  convertGPS: function (gpsList, callback) {
    var that = this;
    calculate.convertFromGPS(gpsList, function (result) {
      var gd = that.lnglats_GD;
      gd.push.apply(gd, result);
 
      var coor_GD = calculate.lngLatToGeodeticCoord(result);
      var coor = that.coors_GD;
      coor.push.apply(coor, coor_GD);
 
      if (typeof callback === 'function') {
        callback();
      }
    });
  },
 
  clearData: function () {
    this.times = [];
    this.lnglats_GPS = [];
    this.lnglats_GD = [];
    this.coors_GD = [];
    this.factor = new Map();
  },
 
  // 设置绘图范围
  setRange: function (key, range) {
    this.legendType = Legend.C_TYPE;
    if (key != undefined) {
      this.factor[key].setRange(range);
    } else {
      for (const k in this.factor) {
        this.factor[k].setRange(range);
      }
    }
  },
 
  // 重置绘图范围
  resetRange: function (key) {
    this.legendType = Legend.D_TYPE;
    if (key != undefined) {
      this.factor[key].clearRange();
    } else {
      for (const k in this.factor) {
        this.factor[k].clearRange();
      }
    }
  },
 
  // 设置为标准绘图范围
  standardRange: function (key) {
    this.legendType = Legend.S_TYPE;
    if (key != undefined) {
      this.factor[key].standardRange();
    } else {
      for (const k in this.factor) {
        this.factor[k].standardRange();
      }
    }
  },
 
  // 根据当前绘图范围重新计算绘图高度
  refreshHeight: function (key) {
    if (key != undefined) {
      this.factor[key].getHeight();
    } else {
      for (const k in this.factor) {
        this.factor[k].getHeight();
      }
    }
  },
 
  // 根据开始和结束下标获取对应位置数据集
  getByIndex: function (s, e) {
    var t = this.times.slice(s, e);
    var l = this.lnglats_GPS.slice(s, e);
    var l_GD = this.lnglats_GD.slice(s, e);
    var c = this.coors_GD.slice(s, e);
    var f = new Map();
    for (const key in this.factor) {
      if (Object.hasOwnProperty.call(this.factor, key)) {
        const element = this.factor[key];
        f[key] = element.getByIndex(s, e);
      }
    }
    return new FactorDatas({
      times: t,
      lnglats_GPS: l,
      lnglats_GD: l_GD,
      coors_GD: c,
      factor: f
    });
  },
 
  getByDate(s, e) {
    const sTime = moment(s).format('YYYY-MM-DD HH:mm:ss');
    const eTime = moment(e).format('YYYY-MM-DD HH:mm:ss');
    const sIndex = this.times.findIndex((v) => {
      return v == sTime;
    });
    const eIndex = this.times.findIndex((v) => {
      return v == eTime;
    });
    if (sIndex != -1 && eIndex != -1) {
      return this.getByIndex(sIndex, eIndex);
    }
  },
 
  // 获取数据长度
  length: function () {
    return this.lnglats_GD.length;
  }
};
 
export { FactorDatas };