import { Legend } from './Legend'; const _hMap = { 19: [0, 1000], //NO 1: [0, 1000], //NO2 2: [0, 2000], //CO 3: [0, 1000], //H2S 4: [0, 1000], //SO2 5: [0, 1000], //O3 6: [0, 1000], //PM2.5 7: [0, 1000], //PM10 8: [0, 100], //TEMPERATURE 9: [0, 100], //HUMIDITY 10: [0, 500], //VOC 11: [0, 1000] //NOI }; const _hRange = [0, 1000]; function getFactorHeight(type, data, _range) { var range = _range == undefined ? _hMap.get(type) : _range; var min = range[0]; var max = range[1]; var scale = max - min == 0 ? 0 : (_hRange[1] - _hRange[0]) / (max - min); var offset = min; // console.log("height:" + (data - offset) * scale * 10); if (data < range[0]) { return (range[0] - offset) * scale * 10; } else if (data > range[1]) { return (range[1] - offset) * scale * 10; } else { return (data - offset) * scale * 10; } } /** * 监测因子类 * 存储某一类型的监测因子数据,提供3d地图绘制高度换算,绘图范围设定等功能 */ function Factor(options) { /** * {factorData: 43.209 factorId: "1" factorName: "NO2" physicalQuantity: 211.1 sensorId: null statusList: null} */ this.datas = []; // 原始数据 // this.lnglats = [] //3d地图当前展示坐标点数组 this.factorName; this.factorId; this.heights = []; //3d地图当前展示坐标点对应的高度数组 this.colors = []; // 3d地图当前展示坐标点对应的颜色数组 this.bottomColors = []; //最小值对应的图例色数组 this.bottomColor; //最小值对应的图例色 this.min = -1; // 当前显示的最小值 this.max = -1; // 当前显示的最大值 this.originMin = -1; // 原始数据中的最小值 this.originMax = -1; // 原始数据中的最大值 this.standardMin = -1; //监测因子类型对应的标准最小值 this.standardMax = -1; //监测因子类型对应的标准最大值 // this.legendType = Legend.S_TYPE; //图例模式 this.legendType = Legend.D_TYPE; //图例模式 if (options != undefined) { this.datas = options.datas; this.heights = options.heights; this.min = options.min; this.max = options.max; this.originMin = options.originMin; this.originMax = options.originMax; this.factorName = options.factorName; this.factorId = options.factorId; this.colors = options.colors; this.bottomColors = options.bottomColors; this.bottomColor = options.bottomColor; this.standardMin = options.standardMin; this.standardMax = options.standardMax; } } Factor.prototype = { // drawMode: 绘制模式,0:自动模式,自动计算当前数据的范围,绘制合适的比例;1:手动模式,根据页面设置的绘图范围进行绘制 pushData: function (data, drawMode) { if (this.factorName == undefined) { this.factorName = data.factorName; this.factorId = data.factorId; } else { if (this.factorName != data.factorName) { console.log( '错误: Factor中插入的数据前后名称不一致,原因子:' + this.factorName + ',新因子:' + data.factorName ); } } this.datas.push(data); this.getRange(data, drawMode); if (this.standardMin == -1) { var range = Legend.getStandardRange(this.factorName); this.standardMin = range[0]; this.standardMax = range[1]; } }, getRange: function (data, drawMode) { if (this.min == -1) { this.min = data.factorData; this.max = data.factorData; } if (this.originMin == -1) { this.originMin = data.factorData; this.originMax = data.factorData; } if (drawMode == 0) { this.min = Math.min(this.min, data.factorData); this.max = Math.max(this.max, data.factorData); // this.min = this.standardMin // this.max = this.standardMax } this.originMin = Math.min(this.originMin, data.factorData); this.originMax = Math.max(this.originMax, data.factorData); }, getHeight: function () { this.heights = []; this.colors = []; this.datas.forEach((d) => { let h = getFactorHeight(d.factorId, d.factorData, [this.min, this.max]); if (d.factorData == -1) { h = -1; } this.heights.push(h); const c = Legend.getColor( this.factorName, this.legendType, d.factorData, this.min, this.max ); this.colors.push(c); const b = Legend.getPreviousColor(this.factorName, this.legendType, c); this.bottomColors.push(b); // this.heights.push(d.factorData) }); this.bottomColor = Legend.getColor( this.factorName, this.legendType, this.standardMin, this.min, this.max ); // console.log(this.factorName + ':' + this.bottomColor); }, setRange: function (range) { this.min = range[0]; this.max = range[1]; this.legendType = Legend.C_TYPE; this.getHeight(); }, clearRange: function () { this.min = this.originMin; this.max = this.originMax; this.legendType = Legend.D_TYPE; this.getHeight(); }, standardRange: function () { this.min = this.originMin; this.max = this.originMax; // this.min = this.standardMin // this.max = this.standardMax this.legendType = Legend.S_TYPE; this.getHeight(); }, // 根据开始和结束下标获取对应位置数据集 getByIndex: function (s, e) { var d = this.datas.slice(s, e); var h = this.heights.slice(s, e); return new Factor({ datas: d, heights: h, min: this.min, max: this.max, originMin: this.originMin, originMax: this.originMax, factorName: this.factorName, colors: this.colors, bottomColors: this.bottomColors, bottomColor: this.bottomColor, standardMin: this.standardMin, standardMax: this.standardMax }); }, // 新增数据同时插帧 insertFrame: function (factor, count, isDraw) { var d1 = this.datas[this.datas.length - 1]; var d2 = factor.datas[0]; if (d1 == undefined || d2 == undefined) { return; } let diffValue = d2.factorData - d1.factorData; // 对于风向矢量来说,动画的变化应该从两个风向夹角较小的那一侧进行变化 if (this.factorName == 'WIND_DIRECTION') { // 风向角度差 if (diffValue > 180) { diffValue -= 360; } else if (diffValue < -180) { diffValue += 360; } } // 单帧数据值的差值 const dValue = { factorData: diffValue / count // physicalQuantity: (d2.physicalQuantity - d2.physicalQuantity) / count }; // 风向矢量修正 const correct = (v) => { if (this.factorName == 'WIND_DIRECTION') { if (v < 0) { return 360 + v; } else if (v > 360) { return v - 360; } else { return v; } } else { return v; } }; for (let i = 0; i < count - 1; i++) { var _data = { factorData: correct(d1.factorData + dValue.factorData * (i + 1)), factorId: d1.factorId, factorName: d1.factorName, // physicalQuantity: // d1.physicalQuantity + dValue.physicalQuantity * (i + 1), sensorId: d1.sensorId, statusList: d1.statusList }; if (!isDraw) { _data.factorData = -1; // _data.physicalQuantity = -1; } this.datas.push(_data); } // this.datas.push(d2) } }; export { Factor };