From 1afdd3e3a60a0e05648196e27497cfaddb360004 Mon Sep 17 00:00:00 2001
From: wangzhibo <wangzhibo@shsening.com>
Date: 星期四, 30 九月 2021 11:27:47 +0800
Subject: [PATCH] add weather widget
---
widgetsTS/weather/view.css | 13 +++
widgetsTS/weather/view.html | 74 ++++++++++++++++++
widgetsTS/weather/widget.js | 99 ++++++++++++++++++++++++
3 files changed, 186 insertions(+), 0 deletions(-)
diff --git a/widgetsTS/weather/view.css b/widgetsTS/weather/view.css
new file mode 100644
index 0000000..150a7b9
--- /dev/null
+++ b/widgetsTS/weather/view.css
@@ -0,0 +1,13 @@
+.append_weather {
+ position: absolute;
+ top: 10px;
+ left:450px;
+ z-index: 999;
+ padding:0px;
+ color: #ffffff;
+ width:150px;
+ height: 50px;
+ background-color: rgba(63, 72, 84, 0.7);
+ border: none;
+ border-radius: 6px;
+}
\ No newline at end of file
diff --git a/widgetsTS/weather/view.html b/widgetsTS/weather/view.html
new file mode 100644
index 0000000..09ab883
--- /dev/null
+++ b/widgetsTS/weather/view.html
@@ -0,0 +1,74 @@
+<div id="weather_simple" class="input-group input-group-lg append_weather">
+ <span style="width: 100px;padding-left:5px;" class="fa input-group-addon dropdown-toggle" data-toggle="dropdown"><img
+ id="weather_icon" src="./img/qweather/100.svg" width="30" height="30">
+ <span> </span>
+ <span id="weather_text" style="width: 50px;"></span>
+ <span> </span>
+ <span id="weather_temp" style="width: 50px;"></span>掳C
+ </span>
+
+ <ul class="dropdown-menu">
+ <div class="c-city-weather-current__bg">
+ <table class="table c-city-weather-current__basic" style="color: white;">
+ <tbody>
+ <tr>
+ <td>
+ <div class="now-basic-container">
+ <img src="./img/qweather/wind--night.png">
+ <div class="basic-item">
+ <div class="basic-item__value"><span id="weather_windScale">0</span>绾�</div>
+ <div class="basic-item__type"><span id="weather_windDir">涓滃崡椋�</span></div>
+ </div>
+ </div>
+ </td>
+ <td>
+ <div class="now-basic-container">
+ <img src="./img/qweather/uv--night.png" >
+ <div class="basic-item">
+ <div class="basic-item__value"><span id="weather_feelsLike">0</span>掳C</div>
+ <div class="basic-item__type">浣撴劅娓╁害</div>
+ </div>
+ </div>
+ </td>
+ <td>
+ <div class="now-basic-container">
+ <img src="./img/qweather/hum--night.png" >
+ <div class="basic-item">
+ <div class="basic-item__value"><span id="weather_humidity">0</span>%</div>
+ <div class="basic-item__type">鐩稿婀垮害</div>
+ </div>
+ </div>
+ </td>
+ <td class="hidden-740">
+ <div class="now-basic-container">
+ <img src="./img/qweather/pressure--night.png" >
+ <div class="basic-item">
+ <div class="basic-item__value"><span id="weather_pressure">0</span>hPa</div>
+ <div class="basic-item__type">澶ф皵鍘�</div>
+ </div>
+ </div>
+ </td>
+ <td class="hidden-740">
+ <div class="now-basic-container">
+ <img src="./img/qweather/pcpn--night.png" >
+ <div class="basic-item">
+ <div class="basic-item__value"><span id="weather_precip">0.0</span>mm</div>
+ <div class="basic-item__type">闄嶆按閲�</div>
+ </div>
+ </div>
+ </td>
+ <td class="hidden-740">
+ <div class="now-basic-container">
+ <img src="./img/qweather/vis--night.png" >
+ <div class="basic-item">
+ <div class="basic-item__value"><span id="weather_vis">0</span>KM</div>
+ <div class="basic-item__type">鑳借搴�</div>
+ </div>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </ul>
+</div>
\ No newline at end of file
diff --git a/widgetsTS/weather/widget.js b/widgetsTS/weather/widget.js
new file mode 100644
index 0000000..dea7a58
--- /dev/null
+++ b/widgetsTS/weather/widget.js
@@ -0,0 +1,99 @@
+'use script'; //寮�鍙戠幆澧冨缓璁紑鍚弗鏍兼ā寮�
+
+(function (window, mars3d) {
+ //鍒涘缓widget绫伙紝闇�瑕佺户鎵緽aseWidget
+ class MyWidget extends mars3d.widget.BaseWidget {
+ //澶栭儴璧勬簮閰嶇疆
+ get resources() {
+ return ['view.css']
+ }
+ //椤甸潰閰嶇疆锛� append鏄坊鍔燚OM鑺傜偣鍒癶tml涓殑鏂瑰紡
+ 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() {
+ $.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')
+ }
+ }
+
+ //娉ㄥ唽鍒皐idget绠$悊鍣ㄤ腑銆�
+ mars3d.widget.bindClass(MyWidget)
+
+ //姣忎釜widet涔嬮棿閮芥槸鐩存帴寮曞叆鍒癷ndex.html涓紝浼氬瓨鍦ㄥ郊姝ゅ懡鍚嶅啿绐侊紝鎵�浠ラ棴鍖呭鐞嗕笅銆�
+})(window, mars3d)
--
Gitblit v1.9.1