import { Factor } from "./Factor";
|
import calculate from "@/utils/map/calculate";
|
|
/**
|
*
|
*/
|
function FactorDatas(options) {
|
// 时间
|
this.times = [];
|
// 原始经纬度(GPS)
|
this.lnglats_GPS = [];
|
// 高德经纬度
|
this.lnglats_GD = [];
|
// (高德地图)转换后的3d地图绘制坐标
|
this.coors_GD = [];
|
// 监测因子数据,Map<String, Factor>
|
this.factor = new Map();
|
|
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;
|
}
|
}
|
|
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) {
|
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();
|
this.factor[v.factorId] = f;
|
}
|
f.pushData(v, drawMode == undefined ? 0 : drawMode);
|
});
|
});
|
|
|
|
this.convertGPS(this.lnglats_GPS, callback);
|
},
|
|
// 新增一个新数据
|
addData: function (dataList, drawMode, callback) {
|
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.factor[key].setRange(range);
|
},
|
|
// 重置绘图范围
|
resetRange: function (key) {
|
this.factor[key].clearRange();
|
},
|
|
// 设置为标准绘图范围
|
standardRange: function (key) {
|
this.factor[key].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
|
});
|
},
|
|
// 获取数据长度
|
length: function () {
|
return this.lnglats_GD.length;
|
},
|
};
|
|
export { FactorDatas };
|