﻿document.write("<script language=\"javascript\" src=\"/script/realtime/MapHelper.js\"><\/script>");
document.write("<script language=\"javascript\" src=\"/script/realtime/station.js\"><\/script>");

var stations;
var jsonData;
var obTime;
function GetOBTime(obtime) {
    obtime = "20" + obtime;
    obtime = obtime.substring(4, 6) + "月" + obtime.substring(6, 8) + "日" + obtime.substring(8, 10) + "时";
    return obtime;
}

function getfengxiang1(angle) {
    if (angle == "") {
        return "";
    }
    if (angle >= 348.76 || angle <= 11.25) {
        return "北";
    }
    if (angle >= 11.26 && angle <= 33.75) {
        return "北东北";
    }
    if (angle >= 33.76 && angle <= 56.25) {
        return "东北";
    }
    if (angle >= 56.26 && angle <= 78.75) {
        return "东东北";
    }
    if (angle >= 78.76 && angle <= 101.25) {
        return "东";
    }
    if (angle >= 101.26 && angle <= 123.75) {
        return "东东南";
    }
    if (angle >= 123.76 && angle <= 146.25) {
        return "东南";
    }
    if (angle >= 146.26 && angle <= 168.75) {
        return "南东南";
    }
    if (angle >= 168.76 && angle <= 191.25) {
        return "南";
    }
    if (angle >= 191.26 && angle <= 213.75) {
        return "南西南";
    }
    if (angle >= 213.76 && angle <= 236.25) {
        return "西南";
    }
    if (angle >= 236.26 && angle <= 258.75) {
        return "西西南";
    }
    if (angle >= 258.76 && angle <= 281.25) {
        return "西";
    }
    if (angle >= 281.26 && angle <= 303.75) {
        return "西";
    }
    if (angle >= 303.76 && angle <= 326.25) {
        return "西北";
    }
    if (angle >= 326.26 && angle <= 348.75) {
        return "北西北";
    }
}
function GetWindDirect(fengxiang) {
    var fximg = "vane/";
    if (fengxiang != null && fengxiang != "") {
        if (fengxiang >= 348.76 || fengxiang <= 11.25) {
           fximg += "arrow5.gif";
        } else if (fengxiang > 11.25 && fengxiang <= 33.75) {
            fximg += "arrow1-3.gif";
        } else if (fengxiang > 33.75 && fengxiang <= 56.25) {
            fximg += "arrow6.gif";
        } else if (fengxiang > 56.25 && fengxiang <= 78.75) {
            fximg += "arrow2-1.gif";
        } else if (fengxiang > 78.75 && fengxiang <= 101.25) {
            fximg += "arrow7.gif";
        } else if (fengxiang > 101.25 && fengxiang <= 123.75) {
            fximg += "arrow2-2.gif";
        } else if (fengxiang > 123.75 && fengxiang <= 146.25) {
            fximg += "arrow8.gif";
        } else if (fengxiang > 146.25 && fengxiang <= 168.75) {
            fximg += "arrow1-4.gif";
        } else if (fengxiang > 168.75 && fengxiang <= 191.25) {
            fximg += "arrow1.gif";
        } else if (fengxiang > 191.25 && fengxiang <= 213.75) {
            fximg += "arrow1-2.gif";
        } else if (fengxiang > 213.75 && fengxiang <= 236.25) {
            fximg += "arrow2.gif";
        } else if (fengxiang > 236.25 && fengxiang <= 258.75) {
            fximg += "arrow2-3.gif";
        } else if (fengxiang > 258.75 && fengxiang <= 281.25) {
            fximg += "arrow3.gif";
        } else if (fengxiang > 281.25 && fengxiang <= 303.75) {
            fximg += "arrow2-4.gif";
        } else if (fengxiang > 303.75 && fengxiang <= 326.25) {
            fximg += "arrow4.gif";
        } else if (fengxiang > 326.25 && fengxiang < 348.75) {
            fximg += "arrow1-1.gif";
        }

    }

    var html = "";
    if (fximg != "")
        html = "<img src='/images/" + fximg + "'/>";
    return html;
}
function clearfc() {
    $(".mapFont span").html("");
}
//加载实测温度数据
function LoadRealTimeData() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "temp" },
        dataType: 'text',
        async: false,
        success: function (result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                obTime = jsonData[i].ObservTimes;
                var id = jsonData[i].StationNum;
                $("#" + id).html("");
                //alert($("#58658").html());
                if (jsonData[i].DryBulTemp != "") {
                    $("#" + id).html(jsonData[i].DryBulTemp / 10.0 + "℃");
                }
                else {
                    $("#" + id).html("");
                }
            }
            $("#obTempTime").text(GetOBTime(obTime));
        },
        error: function () { alert("error"); }
    });
}

//加载日最高温度数据
function LoadMaxTemp() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "maxTemp" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                $("#" + id).html("");
                if (jsonData[i].MaxTemp != "") {
                    $("#" + id).html(jsonData[i].MaxTemp / 10.0 + "℃");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载日最低温度数据
function LoadMinTemp() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "minTemp" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                $("#" + id).html("");
                if (jsonData[i].MinTemp != "") {
                    $("#" + id).html(jsonData[i].MinTemp / 10.0 + "℃");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}


//加载1小时相对湿度数据
function LoadhourRelHumidity() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "HourrelHumidity" },
        dataType: 'text',
        async: false,
        success: function (result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].RelHumidity != "") {
                    $("#" + id).html(jsonData[i].RelHumidity + "%");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function () { alert("error"); }
    });
}
//加载相对湿度数据
function LoadRelHumidity() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "relHumidity" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].RelHumidity != "") {
                    $("#" + id).html(jsonData[i].RelHumidity + "%");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}
//加载水气压数据
function LoadVapourPress() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "vapourPress" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].VapourPress != "") {
                    $("#" + id).html(jsonData[i].VapourPress / 10.0 + "hpa");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载站点气压数据
function LoadStationPress() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "stationPress" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].StationPress != "") {
                    $("#" + id).html(jsonData[i].StationPress / 10.0 + "hpa");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载日最高气压值
function LoadMaxPSta() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "maxPSta" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].MaxPSta != "") {
                    $("#" + id).html(jsonData[i].MaxPSta / 10.0 + "hpa");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载日最高气压值
function LoadMinPSta() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "minPSta" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].MinPSta != "") {
                    $("#" + id).html(jsonData[i].MinPSta / 10.0 + "hpa");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载海平面气压
function LoadSeaLevelPress() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "seaLevelPress" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    $("#" + id).html(jsonData[i].SeaLevelPress / 10.0 + "hpa");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载实测降雨量数据
function LoadPrecipitation(hours) {
    clearfc();
    var datetype = "precipitation";
    switch (hours) {
        case 3:
            datetype = "precipitation3hours";
            break;
        case 6:
            datetype = "precipitation6hours";
            break;
        case 12:
            datetype = "precipitation12hours";
            break;
        case 24:
            datetype = "precipitation24hours";
            break;
    }
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: datetype },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].Precipitation != "") {
                    $("#" + id).html(jsonData[i].Precipitation / 10.0 + "mm");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载2分钟平均风速
function LoadAvgWindVelocity2Min() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "avgwindvelocity2min" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    $("#" + id).html(jsonData[i].WindVelocity / 10.0 + "m/s");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载2分钟平均风向
function LoadAvgWindDirect2Min() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "avgwinddirect2min" },
        dataType: 'text',
        async: false,
        success: function (result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "" && jsonData[i].WindDirect != "") {

                   // $("#" + id).html(jsonData[i].WindDirect + "°");
                    $("#" + id).html(GetWindDirect(jsonData[i].WindDirect));
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function () { alert("error"); }
    });
}

//加载10分钟平均风速
function LoadAvgWindVelocity10Min() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "avgwindvelocity10min" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    $("#" + id).html(jsonData[i].WindVelocity10 / 10.0 + "m/s");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载10分钟平均风向
function LoadAvgWindDirect10Min() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "avgwinddirect10min" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "" && jsonData[i].WindDirect10 != "") {
                    //$("#" + id).html(jsonData[i].WindDirect10 + "°");
                    $("#" + id).html(GetWindDirect(jsonData[i].WindDirect10));
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载最大风速
function LoadMaxWindV() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "maxwindv" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    $("#" + id).html(jsonData[i].MaxWindV / 10.0 + "m/s");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载最大风速风向
function LoadMaxWindD() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "maxwindd" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "" && jsonData[i].MaxWindD != "") {
                    //$("#" + id).html(jsonData[i].MaxWindD + "°");
                    $("#" + id).html(GetWindDirect(jsonData[i].MaxWindD));
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}


//加载极大风速
function LoadExMaxWindV() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "exmaxwindv" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    $("#" + id).html(jsonData[i].ExMaxWindV / 10.0 + "m/s");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载极大风速风向
function LoadExMaxWindD() {
    clearfc();
    $.ajax({
        contentType: "application/json",
        url: "ashx/StationDate.ashx",
        data: { type: "exmaxwindd" },
        dataType: 'text',
        async: false,
        success: function(result) {
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "" && jsonData[i].ExMaxWindD != "") {
                    //$("#" + id).html(jsonData[i].ExMaxWindD + "°");
                    $("#" + id).html(GetWindDirect(jsonData[i].ExMaxWindD));
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

function displayMap(width, height) {
    stations = GetStationList();
   // $(".map").html("");
    initMapImg(width, height, 120.7202995, 121.359006956, 28.576518976, 27.507001);
    //左下：120.043731,27.50700127.921097341
    //右上：120.708573,27.768413
   // 左下：120.7202995，27.921097341
   //右上：121.359006956，28.576518976
    var strHtml = "";

    $.each(stations, function (i, row) {
		
		if (row.Id == 'K3827') // row.SName 为'乐清'的有两个, Id分别为 'K3827' 和 '58656'
			return;
    
        //debugger;
        var leftPx = getPxByJd(row.Lon) - 10; //根据经度获取x轴坐标
        var topPx = getPxByWd(row.Lat) - 5; //根据纬度获取y轴坐标
        
        leftPx = leftPx - leftPx % 1;
        topPx = topPx - topPx % 1;

        var qw = "";
        var fs = "";
        var fx = "";
        var yl = "";
        if (row.QW != "")
            qw = row.QW / 10 + " &nbsp;℃";
        if (row.FS != "")
            fs = row.FS / 10 + " &nbsp;m/s";
        if (row.FX != "")
            fx = row.FX;
        if (row.YL != "")
            yl = row.YL / 10 + " &nbsp;mm";
        var eleDate = "<div>";
        eleDate += "&nbsp;气&nbsp;温：" + qw + "<br>";
        eleDate += "&nbsp;风&nbsp;速：" + fs + "<br>";
        eleDate += "&nbsp;风&nbsp;向：" + GetWindDirect(fx) + "<br>";
        eleDate += "&nbsp1h雨量：" + yl + "<br></div>";

        document.getElementById("TipContent").innerHTML = eleDate;
        var tipDate = document.getElementById("Tip").innerHTML;

        switch (RTrim(row.SName)) {
			case "七里港":
				topPx += 118;
				break;
			case "磐石":
				topPx += 118;
				break;
			case "翁垟":
				leftPx += -1;
				topPx += 112;
				break;
			case "白象":
				leftPx += 7;
				topPx += 47;
				break;
			case "白石":
				leftPx += 2;
				topPx += 92;
				break;
			case "乐清":
				topPx += 68;
				break;
			case "湖雾":
				topPx += 15;
				break;
			case "北雁荡":
				topPx += 26;
				break;
			case "大荆":
				leftPx += 5;
				topPx += 17;
				break;
			case "清江":
				topPx += 52;
				break;
			case "南岳":
				leftPx += -3;
				topPx += 70;        
				break;
			case "仙溪":
				leftPx += 4;
				topPx += 11;        
				break;
			case "雁湖":
				topPx += 33;        
				break;
			case "砩头":
				topPx += 22;
				leftPx += 4;        
				break;
			case "芙蓉":
				topPx += 45;
				leftPx += 3   
				break;
			case "虹桥":
				leftPx += 3;
				topPx += 72;        
				break;
			case "石帆":
				leftPx += -7;
				topPx += 77;        
				break;
			case "四都":
				leftPx += -3;
				topPx += 67;        
				break;
			case "城北":
				leftPx += 1;
				topPx +=74;        
				break;
			case "西门岛":
				leftPx += -2;
				topPx += 33;        
				break;
			case "淡溪":
				leftPx += 80;
				topPx += 70;
				break;
			case "福溪":
				topPx += 3;
				leftPx += 3;
				break;
			case "岭底":
				leftPx += 2;
				topPx += 48;
				break;
			case "智仁":
				leftPx += 3;
				topPx += -4;
				break;
		}
		
        strHtml += "<div onclick=\"loadqx('" + RTrim(row.SName) + "');\"><div class='mapBox' style='cursor:pointer;text-align:left; left:" 
                + leftPx + "px; top:" + topPx + "px; position:absolute; font-size:12px;' class='mapFont'><div class='mapDot'><div class='mapSName'>" + RTrim(row.SName) + "</div><div id='" + row.Id + "' class='mapTemp'></div></div></div></div>";
        //  alert(strHtml);
    });
    
    $("#mapDiv").append(strHtml);
    
   // new ActiveTip("mapDiv");
}
 //onclick='openTip('" + unescape(row.SName) + "');'

function loadqx(stationName) {
    LoadFlash($("#ysid").val(), stationName);
}
function checkys(id){

 $("#ysid").val(id)
 
 for(var i=1;i<=5;i++)
 {
    if(id==i)
    {
        $("#ys"+i).addClass("current");
        $(".ysTitle").hide();
        $("#ysTitle"+i).show();
        switch(i)
        {
            case 1:LoadRealTimeData();
            break;
            case 2:LoadStationPress();
            break;
            case 3:LoadPrecipitation();
            break;
            case 4:LoadAvgWindVelocity2Min();
            break;
            case 5:LoadRelHumidity();
            break;
            default:break;
        }
    }else
    {
        $("#ys"+i).removeClass("current");
    }
 }
 
}
function addPoint(leftPx, topPx, Name, id) {
   // return "<div style=\'width:60px; height:32px;text-align:left; margin-left:1px; left:" + leftPx + "px; top:" +
      //  topPx + "px; position:absolute; font-size:12px;\' class=\'mapFont\'><div class=\'maptide\'></div><div>" + row.SName + "<br/><a id=\'" + row.Id + "\'></a></div></div>";
}

$(function() {
    $('#maploading').ajaxStart(function() {
        $(this).show();
    }).ajaxStop(function() {
        $(this).hide();
    });
})
function LTrim(str) {
    var i;
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) != " " && str.charAt(i) != " ") break;
    }
    str = str.substring(i, str.length);
    return str;
}
function RTrim(str) {
    var i;
    for (i = str.length - 1; i >= 0; i--) {
        if (str.charAt(i) != " " && str.charAt(i) != " ") break;
    }
    str = str.substring(0, i + 1);
    return str;
}
function Trim(str) {
    return LTrim(RTrim(str));
}


function SetOBTime(hours) {
            if (hours == 0) {
                $("#obTime").text($("#obTempTime").text());
            }
            else {
                var currTimeStr = (new Date()).getFullYear() + "年" + $("#obTempTime").text() + "00:00";
                currTimeStr = currTimeStr.replace("年", "/").replace("月", "/").replace("日", " ").replace("时", ":");
                var currTime = new Date();
                currTime = new Date(currTimeStr);
                var preTime = new Date(currTimeStr);
                preTime.setHours(preTime.getHours() + hours);
                currTimeStr = (currTime.getMonth() + 1) + "月" + currTime.getDate() + "日" + currTime.getHours() + "时";
                var preTimeStr = (preTime.getMonth() + 1) + "月" + preTime.getDate() + "日" + preTime.getHours() + "时";
                $("#obTime").text(preTimeStr + " - " + currTimeStr);
            }
        }
