Weather_wev8.js
11.5 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
if(typeof(Mobile_NS) == 'undefined'){
Mobile_NS = {};
}
Mobile_NS.showCurrentCityWeather = function (theId,mecJson){
Mobile_NS.getCurrentPosition(function(result){
var status = result["status"];
if(status == "1"){
var city = "Shanghai";
Mobile_NS.initWeather(theId,city);
}
});
}
Mobile_NS.initWeather = function(theId,cityname,mecJson) {
var GaoDeWeatherUrl = "https://restapi.amap.com/v3/weather/weatherInfo?key=fbbb3b85bc2133d171a6540deb92ca21&extensions=all&city=";
var selectedCity = "shanghai";
var placeholder = "";
var unit = "c";
if(typeof(cityname)=="string"&&cityname!=""){
selectedCity = cityname;
}else{
if(mecJson){
selectedCity = mecJson["city"];
}else{
var showCity = $("#weathercity_"+theId).val();
if(typeof(showCity)=="string"&&showCity!=""){
selectedCity = showCity;
}
}
}
$("#weathercity_"+theId).val(selectedCity);
getWoeid(selectedCity,theId);
$("#weathercity_"+theId).keypress(function() {
if (event.which == 13) {
selectedCity = $("#weathercity_"+theId).val();
getWoeid(selectedCity,theId);
$("#weathercity_"+theId).blur();
}
});
$("#weathercity_"+theId).focus(function(event) {
placeholder = $("#weathercity_"+theId).val();
$("#weathercity_"+theId).val("");
});
$("#weathercity_"+theId).blur(function(event) {
if ($("#weathercity_"+theId).val() == "") {
$("#weathercity_"+theId).val(placeholder);
}
});
function getWoeid(weathercity,theId) {
var woeid = WeatherCityCode[weathercity.toLowerCase()];
if(woeid&&!isNaN(woeid)){
getWeatherInfo(woeid,theId);
}else{
var jsonURL = GaoDeWeatherUrl + weathercity;
showLoading(theId);
$.getJSON(jsonURL, function(data){
woeidDownloaded(data,theId);
});
}
}
function showLoading(theId){
var weatherContainer = $("#weatherContainer_"+theId);
var city = $("#weathercity_"+theId);
var cityspan = $("#weathercity_"+theId+"_span");
var topDiv = city.parent();
var h = topDiv.height();
if(cityspan.length==0){
topDiv.append("<div style='color: white;padding-top:15px;va;font-size: 14px;display:none;' id='weathercity_"+theId+"_span' >正在加载天气...</div>");
}
var bot = $(".bot",weatherContainer);
var top = $(".top",weatherContainer);
bot.css("height",(bot.height()-20)+"px");
$("#weathercity_"+theId+"_span").css("height",(top.height()-30-15)+"px");;
$("#weathercity_"+theId+"_span").show();
$(".bot li img",weatherContainer).hide();
$(".bot li p",weatherContainer).hide();
$("#deg_"+theId).hide();
city.hide();
cityspan.show();
}
function hideLoading(theId){
var weatherContainer = $("#weatherContainer_"+theId);
var city = $("#weathercity_"+theId);
var cityspan = $("#weathercity_"+theId+"_span");
var bot = $(".bot",weatherContainer);
bot.css("height","");
$(".bot li img",weatherContainer).show();
$(".bot li p",weatherContainer).show();
$("#deg_"+theId).show();
city.show();
cityspan.hide();
}
function woeidDownloaded(data,theId) {
var woeid = null;
if (data.count <= 0) {
$("#weathercity_"+theId).val("No city found");
$("#deg_"+theId).html("");
setImage("未知", $("#big_"+theId)[0]);
for (var i = 0; i <= 2; i++) {
$('#forecast' + i+"_"+theId).html("");
setImage("未知", $("#forecastimg" + i+"_"+theId)[0]);
$('#forecastdeg' + i+"_"+theId).html("");
}
return;
} else if (data.count == 1) {
woeid = data.forecasts[0].adcode;
} else {
woeid = data.forecasts[0].adcode;
}
getWeatherInfo(woeid,theId);
}
function getWeatherInfo(woeid,theId) {
var jsonURL = GaoDeWeatherUrl + woeid;
$.getJSON(jsonURL,function(data){
weaterInfoDownloaded(data,theId);
});
}
function weaterInfoDownloaded(data,theId) {
$("#weathercity_"+theId).val(data.forecasts[0].city);
$("#deg_"+theId).html((parseInt(data.forecasts[0].casts[0].daytemp) + parseInt(data.forecasts[0].casts[0].nighttemp)) / 2 + "°" + unit.toUpperCase());
setImage(data.forecasts[0].casts[0].dayweather, $("#big_"+theId)[0]);
for (var i = 0; i <= 2; i++) {
var fc = data.forecasts[0].casts[i+1];
$('#forecast' + i+"_"+theId).html(fc.date);
setImage(fc.dayweather, $("#forecastimg" + i+"_"+theId)[0]);
$('#forecastdeg' + i+"_"+theId).html((parseInt(fc.daytemp) + parseInt(fc.nighttemp)) / 2 + " °" + unit.toUpperCase());
}
$("#weatherContainer_"+theId).find(".bot img").css("visibility","visible");
hideLoading(theId);
}
function setImage(code, image) {
image.src = "/mobilemode/images/weathericon/";
switch (code) {
case "晴":
image.src += "Sun.png"
break;
case "少云":
image.src += "Cloud.png"
break;
case "晴间多云":
image.src += "Cloud-Sun.png"
break;
case "多云":
image.src += "Cloud.png"
break;
case "阴":
image.src += "Cloud.png"
break;
case "有风":
image.src += "Wind.png"
break;
case "平静":
image.src += "Wind.png"
break;
case "微风":
image.src += "Wind.png"
break;
case "和风":
image.src += "Wind.png"
break;
case "清风":
image.src += "Wind.png"
break;
case "强风劲风":
image.src += "Wind.png"
break;
case "疾风":
image.src += "Wind.png"
break;
case "大风":
image.src += "Wind.png"
break;
case "烈风":
image.src += "Wind.png"
break;
case "风暴":
image.src += "Cloud-Lightning.png"
break;
case "狂爆风":
image.src += "Wind.png"
break;
case "飓风":
image.src += "Wind.png"
break;
case "热带风暴":
image.src += "Cloud-Lightning.png"
break;
case "阵雨":
image.src += "Cloud-Drizzle-Alt.png"
break;
case "雷阵雨":
image.src += "Cloud-Lightning.png"
break;
case "雷阵雨并伴有冰雹":
image.src += "Cloud-Lightning.png"
break;
case "小雨":
image.src += "Cloud-Drizzle-Alt.png"
break;
case "中雨":
image.src += "Cloud-Drizzle.png"
break;
case "大雨":
image.src += "Cloud-Rain.png"
break;
case "暴雨":
image.src += "Cloud-Hail-Alt.png"
break;
case "大暴雨":
image.src += "Cloud-Hail-Alt.png"
break;
case "特大暴雨":
image.src += "Cloud-Hail-Alt.png"
break;
case "强阵雨":
image.src += "Cloud-Hail-Alt.png"
break;
case "强雷阵雨":
image.src += "Cloud-Lightning.png"
break;
case "极端降雨":
image.src += "Cloud-Hail-Alt.png"
break;
case "毛毛雨/细雨":
image.src += "Cloud-Drizzle-Alt.png"
break;
case "雨":
image.src += "Cloud-Drizzle.png"
break;
case "小雨-中雨":
image.src += "Cloud-Drizzle.png"
break;
case "中雨-大雨":
image.src += "Cloud-Rain.png"
break;
case "大雨-暴雨":
image.src += "Cloud-Rain.png"
break;
case "暴雨-大暴雨":
image.src += "Cloud-Hail-Alt.png"
break;
case "大暴雨-特大暴雨":
image.src += "Cloud-Hail-Alt.png"
break;
case "雨雪天气":
image.src += "Cloud-Snow-Alt.png"
break;
case "雨夹雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "阵雨夹雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "冻雨":
image.src += "Cloud-Drizzle.png"
break;
case "雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "阵雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "小雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "中雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "大雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "暴雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "小雪-中雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "中雪-大雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "大雪-暴雪":
image.src += "Cloud-Snow-Alt.png"
break;
case "浮尘":
image.src += "Cloud-Fog.png"
break;
case "扬沙":
image.src += "Cloud-Fog.png"
break;
case "沙尘暴":
image.src += "Cloud-Fog.png"
break;
case "强沙尘暴":
image.src += "Cloud-Fog.png"
break;
case "龙卷风":
image.src += "Tornado.png"
break;
case "雾":
image.src += "Cloud-Fog.png"
break;
case "浓雾":
image.src += "Cloud-Fog.png"
break;
case "强浓雾":
image.src += "Cloud-Fog.png"
break;
case "轻雾":
image.src += "Cloud-Fog.png"
break;
case "大雾":
image.src += "Cloud-Fog.png"
break;
case "特强浓雾":
image.src += "Cloud-Fog.png"
break;
case "霾":
image.src += "Cloud-Fog.png"
break;
case "中度霾":
image.src += "Cloud-Fog.png"
break;
case "重度霾":
image.src += "Cloud-Fog.png"
break;
case "严重霾":
image.src += "Cloud-Fog.png"
break;
case "热":
image.src += "Sun.png"
break;
case "冷":
image.src += "Thermometer-Zero.png"
break;
case "未知":
image.src += "Moon-New.png"
break;
default:
image.src += "Moon-New.png"
break;
}
}
}