riku
2025-03-12 42f42dc88214f283b43c422f37e10ab45c5c5578
src/model/Factor.js
@@ -1,6 +1,7 @@
import { Legend } from './Legend';
const _hMap = {
  19: [0, 1000], //NO
  1: [0, 1000], //NO2
  2: [0, 2000], //CO
  3: [0, 1000], //H2S
@@ -34,7 +35,6 @@
/**
 * 监测因子类
 * 存储某一类型的监测因子数据,提供3d地图绘制高度换算,绘图范围设定等功能
 * 用于3d地图绘制
 */
function Factor(options) {
  /**
@@ -51,6 +51,7 @@
  this.factorId;
  this.heights = []; //3d地图当前展示坐标点对应的高度数组
  this.colors = []; // 3d地图当前展示坐标点对应的颜色数组
  this.bottomColors = []; //最小值对应的图例色数组
  this.bottomColor; //最小值对应的图例色
  this.min = -1; // 当前显示的最小值
  this.max = -1; // 当前显示的最大值
@@ -60,21 +61,32 @@
  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;
  if (typeof options === 'object') {
    for (const key in options) {
      if (Object.prototype.hasOwnProperty.call(options, key)) {
        const value = options[key];
        this[key] = value;
      }
    }
    this.factorName = options.factorName;
    this.factorId = options.factorId;
    this.colors = options.colors;
    this.bottomColor = options.bottomColor;
    this.standardMin = options.standardMin;
    this.standardMax = options.standardMax;
    // 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;
    // this.legendType = options.legendType;
  }
}
@@ -125,12 +137,12 @@
    this.heights = [];
    this.colors = [];
    this.datas.forEach((d) => {
      var h = getFactorHeight(d.factorId, d.factorData, [this.min, this.max]);
      let h = getFactorHeight(d.factorId, d.factorData, [this.min, this.max]);
      if (d.factorData == -1) {
        h = -1;
      }
      this.heights.push(h);
      var c = Legend.getColor(
      const c = Legend.getColor(
        this.factorName,
        this.legendType,
        d.factorData,
@@ -138,6 +150,8 @@
        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(
@@ -182,6 +196,7 @@
      originMax: this.originMax,
      factorName: this.factorName,
      colors: this.colors,
      bottomColors: this.bottomColors,
      bottomColor: this.bottomColor,
      standardMin: this.standardMin,
      standardMax: this.standardMax
@@ -194,24 +209,49 @@
    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;
      }
    }
    // 单帧数据值的差值
    var dValue = {
      factorData: (d2.factorData - d1.factorData) / count,
      physicalQuantity: (d2.physicalQuantity - d2.physicalQuantity) / count
    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: d1.factorData + dValue.factorData * (i + 1),
        factorData: correct(d1.factorData + dValue.factorData * (i + 1)),
        factorId: d1.factorId,
        factorName: d1.factorName,
        physicalQuantity:
          d1.physicalQuantity + dValue.physicalQuantity * (i + 1),
        // physicalQuantity:
        //   d1.physicalQuantity + dValue.physicalQuantity * (i + 1),
        sensorId: d1.sensorId,
        statusList: d1.statusList
      };
      if (!isDraw) {
        _data.factorData = -1;
        _data.physicalQuantity = -1;
        // _data.physicalQuantity = -1;
      }
      this.datas.push(_data);
    }