riku
2024-03-13 9130536f57daccec183fa203fe2d666667fd42e1
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
function ComplaintLayer2(options) {
  //时间选择器
  this.timePicker;
  //分析结果
  this.epwResult;
  //网格绘制信息
  this.points = [];
  this.factor = 'VOC'
 
  this.gridAnalysis = new GridAnalysis();
}
 
ComplaintLayer2.prototype = {
  init: function () {
    this.searchBox();
  },
  enable: function () {
    this.isEnable = true;
    this.uiChange(true);
  },
  disable: function () {
    this.isEnable = false;
    this.uiChange(false);
  },
  /**
   * UI显示隐藏变化
   */
  uiChange: function (isShow) {
    if (isShow) {
      $('#epw_model').slideDown('fast');
    }
  },
 
  searchBox: function () {
    var that = this;
 
    this.timePicker = DPicker.timePicker(
      'epw_date_2',
      function (startTime, endTime) {
        $('#epw_starttime_text').text(startTime);
        $('#epw_endtime_text').text(endTime);
      }
    );
    var m = moment();
    var now = m.format('YYYY-MM-DD HH:mm:ss');
    var hourago = m.add(-1, 'hours').format('YYYY-MM-DD HH:mm:ss');
    $('#epw_starttime_text').text(hourago);
    $('#epw_endtime_text').text(now);
    this.timePicker.setStartDate(hourago);
    this.timePicker.setEndDate(now);
 
    //选择显示的因子
    $('.epw_f_radio_2').on('click', function () {
      if (that.factor != this.value) {
        that.factor = this.value;
        if (that.searched) {
          that.refreshEPW();
        }
      }
    });
    //开始分析
    $('#btn_search_epw_2').on('click', function () {
      that.searched = true;
      that.getEPWResult();
    });
    //清空分析结果
    $('#btn_clear_epw_2').on('click', function () {
      that.gridAnalysis.clear()
    });
    //网格透明度切换
    $('#epw_transparent_grid').on('click', function () {
      if (this.checked) {
        that.gridAnalysis.changeOpacity(false)
      } else {
        that.gridAnalysis.changeOpacity(true)
      }
    })
    //文本显示切换
    $('#epw_text').on('click', function () {
      if (this.checked) {
        that.gridAnalysis.toggleText(true)
      } else {
        that.gridAnalysis.toggleText(false)
      }
    })
    //获取设备编号
    HttpService.getDeviceInfo(function (data) {
      var s = $('#epw_device_code');
      s.empty();
      data.forEach((element) => {
        var op = $('<option></option>');
        op.text(element.deviceCode);
        s.append(op);
      });
    });
  },
 
  getEPWResult: function () {
    var that = this;
    var st = $('#epw_starttime_text').text();
    var et = $('#epw_endtime_text').text();
    var deviceCode = $('#epw_device_code').val();
 
    DataUtil.toggleProcessing();
    HttpService.getGridEPWResult(deviceCode, st, et, 100.0, function (data) {
        DataUtil.toggleProcessing();
        if (data.length == 0) {
          alert('无数据');
        } else {
          that.epwResult = data;
          that.refreshEPW(true);
        }
      }.bind(this)
    );
  },
 
  refreshEPW: function (force) {
    var centerData = this.epwResult[(this.epwResult.length - 1) / 2 - 1];
    MapUtil.setCenter([centerData.ciLongitude, centerData.ciLatitude]);
 
    if (force || this.points.length == 0) {
      this.points = []
      this.epwResult.forEach((r) => {
        this.points.push({
          c: [r.ciLongitude, r.ciLatitude],
          lb: [r.lb.first, r.lb.second],
          rt: [r.rt.first, r.rt.second],
          factor: this.factor,
          value: r.result[this.factor],
          level: r.level[this.factor],
        });
      });
    } else {
      for (let i = 0; i < this.epwResult.length; i++) {
        const r = this.epwResult[i];
        this.points[i].factor = this.factor;
        this.points[i].value = r.result[this.factor];
        this.points[i].level = r.level[this.factor];
      }
    }
    this.gridAnalysis.drawRectangle(this.points);
  },
};