$(function () {
Sugis.InitMap();
Sugis.Init();
Sugis.Dingwei();
})
var Sugis = {
postUrl: "/Sugis/Handler.aspx",
TQList_josn: null,
map_dqck: null,
curr_grade: null,//当前的级数
currDataTime: "",//当前时间戳
StationList: new Dictionary(),//需要显示的站点
ListSnum: Array(),//时间序列数据分区key
dicListData: new Dictionary(),//时间序列数据分区数组
c_i:0,
Init: function () {
var tqysControl = $("#tqysControl");
tqysControl.bind("click", function () {
if ($(this).attr('checked') != undefined) {
$("input:radio[name='tqys']").removeAttr("disabled")
Sugis.TQYS_chang(true);
}
else {
$("input:radio[name='tqys']").attr("disabled", true)
Sugis.TQYS_chang(false);
}
})
$("input:[name='tqys']").bind("click", function () {
Sugis.TQYS_chang(true);
})
//时间选择区域
var timeChoseArea = [2, 8, 14, 20];
for (var i = 1; i >= 0; i--) {
var timeChoseArea_html_li = $("
")
},
CreateMarker: function () {
var zoom = map_dqck.getZoom();
if (zoom <= 4) {
Sugis.CreateInfoBox("c");//只显示直辖省市
}
else if (zoom <= 9) {
Sugis.CreateInfoBox("d");//显示地级市
}
else if (zoom <= 11) {
Sugis.CreateInfoBox("x1");//显示区、县级
}
else {//(zoom >= 12) {/
Sugis.CreateInfoBox("x");//显示县级
}
},
//创建覆盖物
CreateInfoBox: function (grade) {
var bs = map_dqck.getBounds(); //获取可视区域
var bssw = bs.getSouthWest(); //可视区域左下角
var bsne = bs.getNorthEast(); //可视区域右上角
var lngmin = bssw.lng;
var latmin = bssw.lat;
var lngmax = bsne.lng;
var latmax = bsne.lat;
//console.log("当前地图可视范围是:" + bssw.lng + "," + bssw.lat + "到" + bsne.lng + "," + bsne.lat);
map_dqck.clearOverlays()//清除地图上所有覆盖物
/*天气要素的控制*/
var tqysControl = $("#tqysControl").attr('checked') != undefined ? true : false;//天气要素显示控制
var tqys = $("input:[name='tqys']:checked").val();//显示的天气要素
var tx_wd_sname_checked = $("input:checkbox[name='tqys']:checked");
var txshow = function (vldVal) {
for (var i = 0; i < tx_wd_sname_checked.length; i++) {
if (tx_wd_sname_checked[i].value == vldVal) {
return true;
break;
}
}
}
var tx_tx_status = txshow("tx") ? "block" : "none";//天象是否显示
var tx_wd_status = txshow("wd") ? "block" : "none";//风是否显示
var tx_snam_status = txshow("sname") ? "block" : "none";//站点是否显示
Sugis.c_i = 0;
Sugis.StationList = new Dictionary();
$.each(TQList_josn, function (index, content) {
if (content.territory_grade.indexOf(grade) != -1 || content.territory_grade == 'gw') {
//判断是否在可视经纬度范围内:
if ((content.lo >= lngmin && content.lo <= lngmax) &&
(content.la >= latmin && content.la <= latmax)) {
//console.log(content.name+" 可视:" + content.lo + "," + content.la);
//国外站点,3-6显示 grad 1-2 zoom>7显示 全部
if (content.territory_grade == 'gw' && map_dqck.getZoom() <= 6) {
if (content.grade != "1" && content.grade != "2")
return true;
}
var _sid = content.sid;
var _sid_sort = _sid.substr(0, 1);//站点id第一位作为key,
var _StationList = Sugis.StationList.get(_sid_sort);
if (_StationList == undefined) {
_StationList = new Array();
_StationList.push(_sid);
Sugis.StationList.put(_sid_sort, _StationList);
} else {
_StationList.push(_sid);
// Sugis.StationList.put(_sid_sort, _StationList);
}
if (Sugis.ListSnum.indexOf(_sid_sort) == -1) {
Sugis.ListSnum.push(_sid_sort);
}
}
}
})
//加载分区数据
$.each(Sugis.ListSnum, function (index, value) {
var _List_josn = Sugis.dicListData.get(value);//从缓存获取区数据
if (_List_josn == undefined) {
$.getJSON("/Sugis/data/" + value + "xing24.js", function (jsondayList) {
Sugis.dicListData.put(value, jsondayList);
Sugis.CreateMarkerInfo(jsondayList, tx_snam_status, tx_wd_status, tx_tx_status, tqys, Sugis.StationList.get(value));
});
} else {
Sugis.CreateMarkerInfo(_List_josn, tx_snam_status, tx_wd_status, tx_tx_status, tqys, Sugis.StationList.get(value));
}
})
if (tx_wd_status == "block")
this.wf_translate();
if (tx_tx_status == "none") {
$(".BMap_Marker").hide();
}
},
CreateMarkerInfo: function (TQdayList_josn, tx_snam_status, tx_wd_status, tx_tx_status, tqys,_stationList) {
$.each(TQList_josn, function (index, content) {
if (_stationList.indexOf(content.sid) == -1) {
return true;
}
//创建标注 --天象
var tqicon = 100;
tqicon = Surfrecord.getPhImgindex(content.ww, content.cn);
var myIcon = new BMap.Icon("/images/surf/" + tqicon + ".gif", new BMap.Size(25, 20));
var point = new BMap.Point(content.lo, content.la);
var markerjt01 = new BMap.Marker(point, { icon: myIcon }); // 创建标注
markerjt01.setTitle(content.sid)
map_dqck.addOverlay(markerjt01); // 将标注添加到地图中
var lable_style = {
color: "red",
fontSize: "11px",
height: "15px",
lineHeight: "15px",
backgroundColor: "none",
border: "none",
display: "",
fontWeight: 'bold'
};
// 创建文本标注对象
var opts = {
position: point, // 指定文本标注所在的地理位置
offset: new BMap.Size(-10, 10) //设置文本偏移量
}
//气压-p 气温-temp 湿度-rh 6小时降水-rain
var tqys_Array = ["p", "temp", "rh", "rain"];//天气要素
var tqysColor_Array = ["Purple", "red", "green", "blue"];
for (var i = 0; i < tqys_Array.length; i++) {
var label = new BMap.Label(content["" + tqys_Array[i] + ""], opts);
lable_style.color = tqysColor_Array[i];
lable_style.display = tqys_Array[i] == tqys ? "block" : "none";
if (!tqysControl)
lable_style.display = "none";
label.setStyle(lable_style);
label.setTitle(tqys_Array[i])
map_dqck.addOverlay(label);
}
// 创建文本标注对象
var opts = {
position: point, // 指定文本标注所在的地理位置
offset: new BMap.Size(0, 0) //设置文本偏移量
}
//天象 风 站名
var tx_wd_sname = $("input:checkbox[name='tqys']");
function p(x, y) {
this.x = x;
this.y = y;
return this;
}
for (var i = 0; i < tx_wd_sname.length; i++) {
switch (tx_wd_sname[i].value) {
case "wd"://风
var wf = !isNaN(content.wf) ? parseInt(content.wf) : 2;
if (wf > 40)
wf = "40g"
else {
wf = wf % 2 == 0 ? wf : wf + 1;
wf = wf == 0 ? 2 : wf;
}
var wfImg = "
";
var opts_wd = opts;
opts_wd.offset = new BMap.Size(-13, -32)
var label = new BMap.Label(wfImg, opts_wd);
lable_style.height = "61px";
lable_style.width = "25px";
// lable_style.color = tqysColor_Array[i];
//lable_style.display = "block";
lable_style.display = tx_wd_status;
label.setStyle(lable_style);
label.setTitle("wd")
map_dqck.addOverlay(label);
Sugis.c_i++;
break;
case "sname":
//站名
var opts_sname = opts;
opts_sname.offset = new BMap.Size(20, 10)
var label_sNam = new BMap.Label(content.name, opts_sname);
lable_style.color = '#000000';
lable_style.display = tx_snam_status;
label_sNam.setStyle(lable_style);
label_sNam.setTitle("sname")
map_dqck.addOverlay(label_sNam);
break;
}
}
//创建信息窗口
//表格展现天气数据
var tableHtml = "
" + content.name + "(" + content.name_en + ")
Beijing time
| weather | Temperature ℃ | Pressure hPa | Wind Direction | Wind Speed m/s | Humidity % | Rainfall mm |
";
//$.each(TQdayList_josn, function (key, tqList) {
for (var i = TQdayList_josn.length-1; i > 0; i-- ){
var tqList = TQdayList_josn[i];
if (content.sid == tqList.stationid) {
var cn = tqList.cn != "" ? parseInt(tqList.cn) : null;
var tx_text = Surfrec._getCurrentWeather2(cn, tqList.ww, " ");
var _tr = "" + new Date(tqList.datetime.replace(/\-/g, "\/")).format('dd hh:00') + " | " + tx_text + " | " + tqList.t + " | " + tqList.p + " | " + (tqList.wd2 == "" ? "" : wd8[tqList.wd2][1]) + " | " + tqList.wf2 + " | " + tqList.rh + " | " + tqList.r6 + "
|
";
tableHtml += _tr;
//console.log(tableHtml);
}
}
tableHtml += "
";
var sContentjt01 = "
" + tableHtml + "
";
var infoBoxjt01 = new BMapLib.InfoBox(map_dqck, sContentjt01, {
offset: { width: 0, height: 5 },
boxStyle: {
width: "520px",
height: "280px"
},
//boxClass: "infobox ibox_" + content.sid,
boxClass: "infobox",
closeIconMargin: "5px 8px 0 0",
closeIconUrl: "images/iw_close1d3.gif",
enableAutoPan: true,
align: INFOBOX_AT_TOP
});
markerjt01.addEventListener("click", function () {
//关闭全部infobox
$(".infobox").hide();
infoBoxjt01.open(markerjt01)
})
})
$(".load").remove();
},
//天气要素显示隐藏控制
TQYS_chang: function (statu) {
if (statu)//显示天气要素
{
var tqys_arr = $("input:[name='tqys']:checked");//显示的天气要素
$(".BMapLabel").hide();
$(".BMap_Marker").hide();
for (var i = 0; i < tqys_arr.length; i++) {
if (tqys_arr[i].value == "tx") {//天象
if ($(".tx_tx").attr('checked') != undefined)
$(".BMap_Marker").show();
else
$(".BMap_Marker").hide();
}
else
$(".BMapLabel:[title='" + tqys_arr[i].value + "']").show();
}
this.wf_translate();
} else {//隐藏
$(".BMapLabel").hide();
//风 站名不受 显示隐藏控制
var tx_arr = $("input:[class='tx']:checked");
for (var i = 0; i < tx_arr.length; i++) {
$(".BMapLabel:[title='" + tx_arr[i].value + "']").show();
}
}
},
//处理风向图片旋转
wf_translate: function () {
setTimeout(function () {
$(".wf_translate").each(function () {
$(this).rotate(parseInt($(this).attr("angle")))
})
}, 200);
},
//减去天数
SubDay: function (days) {
//date = date.replace(/-/g, "/"); //更改日期格式
var nd = new Date();
nd = nd.valueOf();
nd = nd - days * 24 * 60 * 60 * 1000;
nd = new Date(nd);
return nd;
},
//快速定位
Dingwei: function () {
$(".dingwei a").click(function () {
$(".dingwei").hide();
var sid = $(this).text();
$.each(TQList_josn, function (index, content) {
if (content.name == sid) {
map_dqck.centerAndZoom(new BMap.Point(content.lo, content.la), 9);
$(".BMap_Marker:[title=" + content.sid + "]").click()
return false;
}
})
})
}
}
Surfrec = {};
Surfrec.CW_PHE = { "04": ["Smoke", 40], "05": ["Haze", 50], "06": ["Floating dust", 60], "07": ["Blowing sand", 70], "08": ["Dust whirl", 80], "09": ["Sand storm", 90], "10": ["Mist", 100], "11": ["Flake-shape light fog", 110], "12": ["Continuous light fog", 120], "13": ["Lightning", 130], "14": ["Precipitation within sight, but failing to reach the ground", 140], "15": ["Precipitation outside the station", 150], "16": ["Precipitation nearby the station", 160], "17": ["Thunderstorm, without precipitation", 170], "18": ["Squall", 180], "19": ["Tornado", 190], "20": ["Drizzle or snow grains (before observation)", 200], "21": ["Rain (before observation)", 210], "22": ["Snow, ice particles (before observation)", 220], "23": ["Sleet or ice particles (before observation)", 230], "24": ["Rain forming the glazed frost (before observation)", 240], "25": ["Shower (before observation)", 250], "26": ["Snow shower or sleet (before observation)", 260], "27": ["Hail or graupel (before observation)", 270], "28": ["Fog or frozen fog (before observation)", 280], "29": ["Thunderstorm (before observation)", 290], "30": ["Moderate and mild sand storm weakening", 300], "31": ["Moderate and mild sand storm lasting", 310], "32": ["Moderate and mild sand storm intensifying", 320], "33": ["Strong sand storm weakening", 330], "34": ["Strong sand storm lasting", 340], "35": ["Strong sand storm intensifying ", 350], "36": ["Moderate and mild drifting snow", 360], "37": ["Strong drifting snow", 370], "38": ["Moderate and mild blowing snow", 380], "39": ["Strong blowing snow or snowstorm", 390], "40": ["Fog nearby", 400], "41": ["Scattered fog", 410], "42": ["Fog (thinning, distinct sky)", 420], "43": ["Fog (thinning, indistinct sky)", 430], "44": ["Fog (lasting, distinct sky)", 440], "45": ["Fog (lasting, indistinct sky)", 450], "46": ["Fog (thickening, distinct sky)", 460], "47": ["Fog (thickening, indistinct sky)", 470], "48": ["Fog (forming into rime, distinct sky)", 480], "49": ["Fog (forming into rime, indistinct sky)", 490], "50": ["Intermittent light drizzle", 500], "51": ["Successional light drizzle", 510], "52": ["Intermittent moderate drizzle", 520], "53": ["Successional moderate drizzle", 530], "54": ["Intermittent thick drizzle", 540], "55": ["Successional thick drizzle", 550], "56": ["Lignt drizzle forming into glaze", 560], "57": ["Moderate-thick drizzle forming into glaze", 570], "58": ["Light drizzle and rain", 580], "59": ["Moderate-thick drizzle and rain", 590], "60": ["Intermittent light rain", 600], "61": ["Successional light rain", 610], "62": ["Intermittent moderate rain", 620], "63": ["Successional moderate rain", 630], "64": ["Intermittent heavy rain", 640], "65": ["Successional heavy rain", 650], "66": ["Light rain forming into glaze", 660], "67": ["Moderate-heavy rain forming into glaze", 670], "68": ["Light rain and snow", 680], "69": ["Moderate-heavy rain and snow", 690], "70": ["Intermittent light snow", 700], "71": ["Successional light snow", 710], "72": ["Intermittent moderate snow", 720], "73": ["Successional moderate snow", 730], "74": ["Intermittent heavy snow", 740], "75": ["Successional heavy snow", 750], "76": ["Ice spicule", 760], "77": ["Snow grains", 770], "78": ["Star-shaped snow crystals", 780], "79": ["Ice particles", 790], "80": ["Light shower", 800], "81": ["Moderate shower", 810], "82": ["Heavy shower", 820], "83": ["Light shower and snow", 830], "84": ["Moderate-heavy shower and snow", 840], "85": ["Light snow shower", 850], "86": ["Moderate-heavy snow shower", 860], "87": ["Light gustiness graupel", 870], "88": ["Moderate-heavy gustiness graupel", 880], "89": ["Light hail", 890], "90": ["Moderate-heavy hail", 900], "91": ["Light rain (after a thunderstorm)", 910], "92": ["Moderate-heavy rain (after a thunderstorm)", 920], "93": ["Light snow, graupel and hail (after a thunderstorm)", 930], "94": ["Moderate-heavy snow, graupel and hail (after a thunderstorm)", 940], "95": ["Moderate-light thunderstorm", 950], "96": ["Moderate-light thunderstorm, with hail and graupel", 960], "97": ["Heavy thunderstorm", 970], "98": ["Heavy thunderstorm, with sand storm and precipitation", 980], "99": ["Heavy thunderstorm, hail and graupel", 990], "A04": ["Haze, smoke or dust (light)", 61], "A05": ["Haze, smoke or dust (heavy)", 62], "A10": ["Mist", 101], "A11": ["Ice spicule", 761], "A12": ["Remote lightning", 131], "A18": ["Squall", 181], "A20": ["Fog (before observation)", 281], "A21": ["Precipitation (before observation)", 212], "A22": ["Drizzle or snow grains (before observation)", 201], "A23": ["Rain (before observation)", 211], "A24": ["Snow (before observation)", 221], "A25": ["Rain forming into glaze (before observation)", 241], "A26": ["Thunderstorm (before observation)", 291], "A27": ["Blowing snow or sand", 391], "A28": ["Blowing snow or sand 1 km away", 392], "A29": ["Blowing snow or sand within 1 km", 393], "A30": ["Fog", 401], "A31": ["Scattered fog", 411], "A32": ["Fog (thinning)", 431], "A33": ["Fog (lasting)", 451], "A34": ["Fog (thickening)", 471], "A35": ["Fog forming into rime", 491], "A40": ["Precipitation", 598], "A41": ["Moderate-light precipitation", 612], "A42": ["Strong precipitation", 652], "A43": ["Moderate-light liquid precipitation", 613], "A44": ["Strong liquid precipitation", 653], "A45": ["Moderate-light solid precipitation", 712], "A46": ["Strong solid precipitation", 752], "A47": ["Moderate-light frozen precipitation", 662], "A48": ["Strong frozen precipitation", 672], "A50": ["Drizzle", 499], "A51": ["Light drizzle", 511], "A52": ["Moderate drizzle", 531], "A53": ["Thick drizzle", 551], "A54": ["Light drizzle forming into glaze", 561], "A55": ["Moderate drizzle forming into glaze", 571], "A56": ["Thick drizzle forming into glaze", 572], "A57": ["Light drizzle and rain", 581], "A58": ["Thick-moderate drizzle and rain", 591], "A60": ["Rain", 599], "A61": ["Light rain", 611], "A62": ["Moderate rain", 631], "A63": ["Heavy rain", 651], "A64": ["Light rain forming into glaze", 661], "A65": ["Moderate rain forming into glaze", 671], "A66": ["Heavy rain forming into glaze", 672], "A67": ["Light rain and snow", 681], "A68": ["Heavy-moderate rain and snow", 691], "A70": ["Snow", 699], "A71": ["Light snow", 711], "A72": ["Moderate snow", 731], "A73": ["Heavy snow", 751], "A74": ["Light ice pellets", 761], "A75": ["Moderate ice pellets", 762], "A76": ["Heavy ice pellets", 763], "A77": ["Snow grains", 771], "A78": ["Ice crystal", 781], "A80": ["Showery precipitation", 799], "A81": ["Light shower", 801], "A82": ["Moderate shower", 811], "A83": ["Heavy shower", 821], "A84": ["Showery rainstorm", 822], "A85": ["Light snow shower", 851], "A86": ["Moderate snow shower", 861], "A87": ["Heavy snow shower", 862], "A89": ["Hail", 901], "A90": ["Thunderstorm", 949], "A91": ["Light-moderate thunderstorm", 951], "A92": ["Light-moderate thunderstorm, with shower or snow", 952], "A93": ["Light-moderate thunderstorm, with hail", 961], "A94": ["Heavy thunderstorm", 971], "A95": ["Heavy thunderstorm, with shower or snow", 972], "A96": ["Heavy thunderstorm, with hail", 991], "A99": ["Tornado", 191] };
Surfrec.PW_PHE = {
//"0":"云占天空≤1/2",
//"1":"云占天空有时>1/2,有时≤1/2",
//"2":"云占天空>1/2",
"3": "Sand storm,drifting snow or snowstorm",
"4": "Fog,Fog or frozen fog (",
"5": "Drizzle",
"6": "Rain",
"7": "solid precipitation",
"8": "Showery precipitation",
"9": "thunderstorm",
"A1": "Reduced visibility",
"A2": "Blowing sand",
"A3": "Fog",
"A4": "Precipitation",
"A5": "Drizzle",
"A6": "Rain",
"A7": "Snow or ice pellets",
"A8": "Showery precipitation",
"A9": "Thunderstorm"
};
Surfrec.CLOUDINESS = ['Clear', 'Micro Cloud', 'Clear', 'Less to cloudy', 'Less to cloudy', 'Less to cloudy', 'Cloudy', 'Cloudy to overcast', 'overcast', null];
Surfrec.WD8 = ['Static', 'E', 'S', 'ES', 'S', 'WS', 'W', 'WN', 'N'];
/*
* 获取天气描述
* @param cn 总云码
* @param ww 现在天象码
* @return 长度为2的1维数组。[0]--天气描述,[1]--顺序号
*/
Surfrec._getCurrentWeather = function (cn, ww, null_str) {
var n = nullif(cn, -1);
var w = nullif(ww, -1);
var s2 = null;
var i = 0;
var s1 = Surfrec.CLOUDINESS[n];
var phe = Surfrec.CW_PHE[w];
if (phe != null) {
s2 = phe[0];
i = phe[1];
}
//var s = fs121.util.join(s1, s2, ',');
var s = s1 + "," + s2;
i += n * 1000;
return [nullif(s, null_str), i];
};
Surfrec._getCurrentWeather2 = function (cn, ww, null_str) {
if (ww != null && ww != "") {
//接天气代码
var n = cn;// nullif(cn, -1);
var w = nullif(ww, -1);
var s2 = null;
var i = 0;
var s1 = Surfrec.CLOUDINESS[n];
if (n == 9 || n == null)
s1 = "Clear";
var phe = Surfrec.CW_PHE[w];
if (phe != null) {
s2 = phe[0];
i = phe[1];
}
//var s = fs121.util.join(s1, s2, ',');
var s = s1 + "," + s2;
i += n * 1000;
return s;
} else if (cn == null || cn == "") {
return "Clear";
} else if (cn != 9) {
return Surfrec.CLOUDINESS[cn];
} else {
return "";
}
};
//如果参数为3个,当v不为null时,返回arg1,否则返回arg2;
//如果参数为2个,当v不为null时,返回v,否则返回arg1;
//其它情况都返回v
nullif = function (v, arg1, arg2) {
if (arguments.length == 2)
return v != null ? v : arg1;
else if (arguments.length == 3)
return v != null ? arg1 : arg2;
else
return v;
};
Surfrec._getPastWeather = function (w1, w2) {
var phe1 = Surfrec.PW_PHE[w1];
var phe2 = Surfrec.PW_PHE[w2];
if (w1 != w2)
return fs121.util.join(phe1, phe2, ';');
else
return phe1;
};
//气象图片码
Surfrecord = {
//@param ww 天象代码
//@param n 总云量代码
getPhImgindex: function (ww, n) {
var i = 0;
if (ww == null || ww == "")
i = 0;
else if (ww.indexOf('A') != -1)
i = this.Aww2ww[ww];
else
i = ww * 1;
if (i >= 4)
return i;
else if (i != null && (n != null && n != ""))
return 100 + parseInt(n);
return 0;
},
Aww2ww: {
A00: 00, A01: 01, A02: 02, A03: 03, A04: 05, A05: 05,
A10: 10, A11: 76, A12: 13, A18: 18,
A20: 28, A21: 25, A22: 20, A23: 21, A24: 22, A25: 24, A26: 29, A27: 36, A28: 37, A29: 36,
A30: 41, A31: 40, A32: 42, A33: 44, A34: 47, A35: 48,
A40: 60, A41: 62, A42: 65, A43: 62, A44: 65, A45: 72, A46: 75, A47: 66, A48: 67,
A50: 50, A51: 51, A52: 52, A53: 55, A54: 56, A55: 57, A56: 57, A57: 58, A58: 59,
A60: 60, A61: 61, A62: 61, A63: 65, A64: 66, A65: 67, A66: 67, A67: 68, A68: 69,
A70: 70, A71: 71, A72: 72, A73: 75, A74: 79, A75: 79, A76: 79, A77: 77, A78: 78,
A80: 80, A81: 80, A82: 81, A83: 82, A84: 82, A85: 85, A86: 86, A87: 86, A89: 96,
A90: 90, A91: 17, A92: 95, A93: 96, A94: 17, A95: 97, A96: 99, A99: 19
}
};
Array.prototype.indexOf = function (val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
Array.prototype.remove = function (val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};