var jsonmap = null; var arr = document.getElementById('js_focn').getAttribute('data').split(/[=&]/); var show_type = arr[1]; var cid = arr[3]; var foid_wea = { 0: "Clear", 1: "Cloudy", 2: "Overcast", 3: "Shower", 4: "Thundershower", 5: "Thundershower with hail", 6: "Sleet", 7: "Light rain", 8: "Moderate rain", 9: "Heavy rain", 10: "Rainstorm", 11: "Heavy rainstorm", 12: "Extraordinary rainstorm", 13: "Snow shower", 14: "Light snow", 15: "Moderate snow", 16: "Heavy snow", 17: "Blizzard", 18: "Fog", 19: "Freezing rain", 20: "Sandstorm", 21: "Light to moderate rain", 22: "Moderate to heavy rain", 23: "Heavy rain to rainstorm", 24: "Rainstorm to heavy rainstorm", 25: "Heavy rainstorm to extraordinary rainstorm", 26: "Light to moderate snow", 27: "Moderate to heavy snow", 28: "Heavy snow to blizzard", 29: "Floating dust", 30: "Sand blowing", 31: "Strong sandstorm", 53: "Haze" }; var foid_wd = [{ "id": "0", "wd": "Static", "wf": "Breeze" }, { "id": "1", "wd": "Northeast", "wf": "Grade 3-4" }, { "id": "2", "wd": "East", "wf": "Grade 4-5" }, { "id": "3", "wd": "Southeast", "wf": "Grade 5-6" }, { "id": "4", "wd": "South", "wf": "Grade 6-7" }, { "id": "5", "wd": "Southwest", "wf": "Grade 7-8" }, { "id": "6", "wd": "Western", "wf": "Grade 8-9" }, { "id": "7", "wd": "Northwest", "wf": "Grade 9-10" }, { "id": "8", "wd": "North", "wf": "Grade 10-11" }, { "id": "9", "wd": "Rotation, variable", "wf": "Grade 12" }]; $(function () { //百度地图-国内七天预报 //$.getJSON("weather/data/fore/focn_1630-44.js", function (json) { // if (json) { // jsonmap = json; //addInfoWindow(cid, jsonmap); if (show_type == "map") MapCity(cid); if (show_type == "tab") CheckTbCity(cid); // } //}); //sqinyang //搜索 $("#area_key_text_id").keydown(function (event) { if (event.keyCode == "13") { searchArea($(this).val()); } }) $("#area_key_btn_id").click(function () { searchArea($("#area_key_text_id").val()); }) //视图切换 $(".map_type_tb").click(function () { location.href = "focn.aspx?T=map&cid="+$(this).attr("val-sid"); //CheckTbCity($(this).attr("val-sid")); //$(".map_type").hide(); //$(".map_type_map").show(); }) $(".map_type_map").click(function () { location.href = "focn.aspx?T=tab&cid=" + $(this).attr("val-sid"); //CheckMapCity($(this).attr("val-sid")); //$(".map_type").hide(); //$(".map_type_tb").show(); }) //end }); function CheckMapCity(id) { if (show_type == "map") MapCity(id); if (show_type == "tab") CheckTbCity(id); } function MapCity(id) { $.getJSON("/weather/data/fore/focn_1630-" + id.substr(0, 2) + ".js", function (json) { if (json) { jsonmap = json; addInfoWindow(id, jsonmap); } }); $("#map_7day").css({ height: "490px" }); ChangeId(id); $(".map_type").hide(); $(".map_type_map").show(); } function addInfoWindow(index, json) { if (json) { var map = new BMap.Map("map_7day"); //var s = []; //s.push('
==选择地区天气预报==
'); //document.getElementById("r-result").innerHTML = s.join(""); map.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用 map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件 } } //sqinyang function CheckTbCity(id) { $.getJSON("/weather/data/fore/focn_1630-" + id.substr(0, 2) + ".js", function (json) { if (json) { jsonmap = json; addInfoTable(id, jsonmap); //if ($(".sevenday").height() > 490) $("#map_7day").css({ height: "auto" }); ChangeId(id); $(".map_type").hide(); $(".map_type_tb").show(); } }); } function addInfoTable(index, json) { if (json) { var map = $("#map_7day"); var json_mu = json["mu"]; var k = 0; var infoBoxs = ""; var isSf = true; var hr_num,hr_type; $.each(json_mu, function (key, value) { if (key < 1) { hr_num = 1; } else { hr_type = "r"; } var JsMu = key; var mid = json_mu[key]["mid"]; if (index.substr(2) === "00") isSf = false; if (mid != index && index.substr(2) !== "00") return; var json_su = json_mu[key]["su"]; $.each(json_su, function (key, value) { var name = json_su[key]["sn_en"];//监测站 var longitude = json_su[key]["longitude"];//经度 var latitude = json_su[key]["latitude"];//纬度 if (longitude == "" && latitude == "") return; var arrv = json_su[key]["v"]; if (arrv[0][0] == null && arrv[0][1] == null && arrv[0][2] == null && arrv[0][3] == null && arrv[0][4] == null && arrv[0][5] == null) return; if (hr_num == 1) { if (isSf) infoBoxs += "

" + json["pn_en"] + "-" + name + " Seven days forecast

"; else infoBoxs += "

" + json["pn_en"] + " Seven days forecast

"; infoBoxs += ""; $.each(arrv, function (key, value) { if ((key + 2) % 2 == 0) { var datetime = new Date(value[5].replace(/-/g, "/")); //转换成Data(); infoBoxs += ""; } }); infoBoxs += ""; infoBoxs += ""; infoBoxs += ""; infoBoxs += ""; infoBoxs += ""; infoBoxs += ""; infoBoxs += ""; infoBoxs += ""; infoBoxs += ""; } if (hr_num % 2 == 0) infoBoxs += ""; else infoBoxs += ""; var fx_wd = ""; var fs_wd = ""; $.each(arrv, function (key, value) { if ((key + 2) % 2 == 0) { infoBoxs += ""; //如果风向风速无变化,则只显示一个值 var thisFx = fx_wd; var thisFs = fs_wd; if (fx_wd != foid_wd[value[4]]["wd"]) thisFx = fx_wd + "→" + foid_wd[value[4]]["wd"]; if (fs_wd != foid_wd[value[4]]["wf"]) thisFs = fs_wd + "→" + foid_wd[value[4]]["wf"]; infoBoxs += ""; //if (fx_wd == "0" && fs_wd==0&&value[3] == "0" && value[4] == 0) // infoBoxs += ""; //else { //} } }); infoBoxs += ""; hr_num++; }) if (json_mu.length==1) infoBoxs += "
" + datetime.Format('MM-dd') + "
WeatherWind direction / speedWeatherWind direction / speedWeatherWind direction / speedWeatherWind direction / speedWeatherWind direction / speedWeatherWind direction / speedWeatherWind direction / speed

" + name + "

" + name + "

" + foid_wea[value[2]] + ""; fx_wd = foid_wd[value[4]]["wd"]; fs_wd = foid_wd[value[4]]["wf"]; } else { infoBoxs += "" + foid_wea[value[2]] + "" + value[0] + "~" + value[1] + "

" + thisFx + "/" + thisFs + "

--/--
"; else { if(JsMu==json_mu.length-1) infoBoxs += ""; } }) map.html(infoBoxs); } } function ChangeId(id) { $(".map_type_tb").attr("val-sid",id); $(".map_type_map").attr("val-sid", id); } //sqinyang function searchArea(area_key) { if (area_key != "" && area_key != "Quick Search") { var hasBool = false; for (ik = 0; ik < PCAC.length; ik++) { var city_len = PCAC[ik].length - 1;//获取城市数 for (ik2 = 1; ik2 < city_len; ik2++) { if (PCAC[ik][ik2].indexOf(area_key) >= 0)//遍历判断是否包含 { CheckMapCity(PCACID[ik][ik2]); hasBool = true; break; } } } if (!hasBool) alert("Can not find the city"); } else { alert("Please enter the correct city name"); } } //end //日期 Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }