'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 ){
|
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();
|
}
|
|
});
|
}
|
|
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)
|