qinbo
2022-01-21 e8af50a22b2c521416d85eb9926904dc377daa97
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
'use script'; //开发环境建议开启严格模式
 
(function (window, mars3d) {
  //创建widget类,需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //外部资源配置
    get resources() {
      return ['view.css']
    }
    //页面配置, append是添加DOM节点到html中的方式
    get view() {
      return {
        type: 'append',
        url: 'view.html',
        parent: "#centerDiv"
      }
    }
 
    //初始化[仅执行1次]
    create() {
      this.config = this.config?.params || {}; //传入过来的参数
    }
    //每个窗口创建完成后调用
    winCreateOK(viewopt, html) {
      if (viewopt.type != "append") {
        return;
      }
      this.reloadData();
    }
 
    reloadData(params) {
      $.getJSON(mars3d.global_variables.nodejs_url_predix + "dataapi/Bdata?bid=get_weather_" + mars3d.global_variables.queryDataType + "&datatime=" + mars3d.global_variables.queryDataTStart + "&siteid=" + mars3d.global_variables.weathercitycode, (result) => {
        if (result.data.result.length > 0 && mars3d.global_variables.queryDataType == "hour"){
          var current_weather = result.data.result[0];
        //var current_weather = { "temp": "25", "feelsLike": "29", "icon": "150", "text": "晴", "wind360": "90", "windDir": "东风", "windScale": "0", "windSpeed": "0", "humidity": "88", "precip": "0.0", "pressure": "1009", "vis": "16", "cloud": "3", "dew": "23" };
        $("#weather_temp").html(current_weather.temp);
        $("#weather_text").html(current_weather.text);
        $("#weather_icon").attr('src', './img/qweather/' + current_weather.icon + '.svg');
        $("#weather_windScale").html(current_weather.windscale);
        $("#weather_windDir").html(current_weather.winddir);
        $("#weather_feelsLike").html(current_weather.feelslike);
        $("#weather_humidity").html(current_weather.humidity);
        $("#weather_pressure").html(current_weather.pressure);
        $("#weather_precip").html(current_weather.precip);
        $("#weather_vis").html(current_weather.vis);
        $("#weather_dew").html(current_weather.dew);
 
        mars3d.global_variables.wind360 = current_weather.wind360;
        mars3d.global_variables.windSpeed = current_weather.windSpeed==0?1:current_weather.windspeed;
 
        var wind = this.map.getLayerById(2001);
        wind.data = this.createWindData();
        }else if(result.data.result.length > 0 && mars3d.global_variables.queryDataType == "day"){
          var current_weather = result.data.result[0];
          $("#weather_temp").html(current_weather.temp);
          $("#weather_text").html(current_weather.textday);
          $("#weather_icon").attr('src', './img/qweather/' + current_weather.iconday + '.svg');
          $("#weather_windScale").html(current_weather.windscaleday);
          $("#weather_windDir").html(current_weather.winddirday);
          $("#weather_feelsLike").html(current_weather.feelslike);
          $("#weather_humidity").html(current_weather.humidity);
          $("#weather_pressure").html(current_weather.pressure);
          $("#weather_precip").html(current_weather.precip);
          $("#weather_vis").html(current_weather.vis);
          $("#weather_dew").html(current_weather.dew);
 
          mars3d.global_variables.wind360 = current_weather.wind360day;
          mars3d.global_variables.windSpeed = current_weather.windSpeed==0?1:current_weather.windspeedday;
 
          var wind = this.map.getLayerById(2001);
          wind.data = this.createWindData();
        }
 
        
        
      });
    }
 
    createWindData() {
      var arrU = [];
      var arrV = [];
      // 风向是以y轴正方向为零度顺时针转,0度表示北风。90度表示东风。
      // u表示经度方向上的风,u为正,表示西风,从西边吹来的风。
      // v表示纬度方向上的风,v为正,表示南风,从南边吹来的风。
      var u = mars3d.WindUtil.getU(mars3d.global_variables.windSpeed, mars3d.global_variables.wind360);
      var v = mars3d.WindUtil.getV(mars3d.global_variables.windSpeed, mars3d.global_variables.wind360);
      for (let i = 0; i < 9; i++) {
        arrU.push(u);
        arrV.push(v);
      }
      return {
        xmin: 120,
        xmax: 122,
        ymax: 32,
        ymin: 30,
        rows: 3,
        cols: 3,
        udata: arrU, //横向风速
        vdata: arrV, //纵向风速
      };
    }
 
 
 
    //激活插件
    activate() {
 
    }
 
    //释放插件
    disable() {
      //toastr.info('释放插件_example_append')
    }
  }
 
  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget)
 
  //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d)