﻿document.write("<script   language=\"javascript\"   src=\"/js/MapHelper.js\"><\/script>");
document.write("<script   language=\"javascript\"   src=\"/js/station.js\"><\/script>");

var stations;
var jsonData;

function GetOBTime(obtime) {
//   alert(obtime);
    obtime = "20" + obtime;
    obtime = obtime.substring(4, 6) + "月" + obtime.substring(6, 8) + "日" + obtime.substring(8, 10) + "时";
 
    return obtime;
}

function GetWindDirect(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 GetWind(angle) {
    if (angle == "")
        return "";
    if (angle >= 0.0 && angle <= 0.2) {
        return 0;
    }
    if (angle >= 0.3 && angle <= 1.5) {
        return 1;
    }
    if (angle >= 1.6 && angle <= 3.3) {
        return 2;
    }
    if (angle >= 3.4 && angle <= 5.4) {
        return 3;
    }
    if (angle >= 5.5 && angle <=7.9) {
        return 4;
    }
    if (angle >=8.0 && angle <= 10.7) {
        return 5;
    }
    if (angle >= 10.8 && angle <= 13.8) {
        return 6;
    }
    if (angle >= 13.9 && angle <= 17.1) {
        return 7;
    }
    if (angle >= 17.2 && angle <= 20.7) {
        return 8;
    }
    if (angle >= 20.8 && angle <= 24.4) {
        return 9;
    }
    if (angle >= 24.5 && angle <= 28.4) {
        return 10;
    }
    if (angle >= 28.5 && angle <= 32.6) {
        return 11;
    }
    if (angle >32.6) {
        return 12;
    }
}
//加载实测温度数据
function LoadRealTimeData() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "temp" },
        dataType: 'text',
        async: false,
        success: function(result) {
       // alert($(".mapFont a").val());
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                obTime = jsonData[i].ObservTimes;
                var id = jsonData[i].StationNum;
                if (jsonData[i].DryBulTemp != "") {
                    $("#" + id).html(jsonData[i].DryBulTemp.replace(" ", "") / 10.0 + "℃");
                }
                else {
                    $("#" + id).html("");
                }
            }
            $("#obTempTime").text(GetOBTime(obTime));
        },
        error: function() { alert("error"); }
    });
}

//加载日最高温度数据
function LoadMaxTemp() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "maxTemp" },
        dataType: 'text',
        async: false,
        success: function(result) {
        $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].MaxTemp != "") {
                    $("#" + id).html(jsonData[i].MaxTemp.replace(" ","") / 10.0 + "℃");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载日最低温度数据
function LoadMinTemp() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "minTemp" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].MinTemp != "") {
                    $("#" + id).html(jsonData[i].MinTemp / 10.0 + "℃");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载相对湿度数据
function LoadRelHumidity() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "relHumidity" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "vapourPress" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "stationPress" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "maxPSta" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "minPSta" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "seaLevelPress" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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) {
    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: "realtimedata.ashx",
        data: { type: datetype },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "avgwindvelocity2min" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "avgwinddirect2min" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    //$("#" + id).html(jsonData[i].WindDirect + "°");
                    $("#" + id).html(GetWindDirect(jsonData[i].WindDirect));
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载10分钟平均风速
function LoadAvgWindVelocity10Min() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "avgwindvelocity10min" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "avgwinddirect10min" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    //$("#" + id).html(jsonData[i].WindDirect10 + "°");
                    $("#" + id).html(GetWindDirect(jsonData[i].WindDirect10));
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载最大风速
function LoadMaxWindV() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "maxwindv" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            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() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "maxwindd" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    //$("#" + id).html(jsonData[i].MaxWindD + "°");
                    $("#" + id).html(GetWindDirect(jsonData[i].MaxWindD));
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}


//加载极大风速
function LoadExMaxWindV() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "exmaxwindv" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    $("#" + id).html(GetWind(jsonData[i].ExMaxWindV / 10.0) +"级");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}

//加载极大风速风向
function LoadExMaxWindD() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "exmaxwindd" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SeaLevelPress != "") {
                    //$("#" + id).html(jsonData[i].ExMaxWindD + "°");
                    $("#" + id).html(GetWindDirect(jsonData[i].ExMaxWindD));
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}
//加载湿度
function LoadHumidity() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "humidity" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].RH != "") {
                    $("#" + id).html(jsonData[i].RH + "%");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}
//加载10CM土壤湿度
function LoadHumidity10() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "humidity10" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].SWperVolume10cmZDSS != "") {
                    $("#" + id).html(jsonData[i].SWperVolume10cmZDSS + "%");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}
//加载15CM地温
function LoadGeothermal() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "geothermal" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].D15 != "") {
                    $("#" + id).html(jsonData[i].D15/10 + "℃");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}
//加载辐射
function LoadRadiation() {
    $.ajax({
        contentType: "application/json",
        url: "realtimedata.ashx",
        data: { type: "radiation" },
        dataType: 'text',
        async: false,
        success: function(result) {
            $(".mapFont a").text("");
            jsonData = eval("(" + result + ")");
            for (i = 0; i < jsonData.length; i++) {
                var id = jsonData[i].StationNum;
                if (jsonData[i].PR != "") {
                    $("#" + id).html(jsonData[i].PR + "W/㎡");
                }
                else {
                    $("#" + id).html("");
                }
            }
        },
        error: function() { alert("error"); }
    });
}
function displayMap(width, height) {
    stations = GetStationList();
    initMapImg(width, height, 120.168546, 120.806248, 27.996913, 27.656722);

    var strHtml = "";

    $.each(stations, function(i, row) {

        var leftPx = getPxByJd(row.Lon); //根据经度获取x轴坐标

        var topPx = getPxByWd(row.Lat); //根据纬度获取y轴坐标

        strHtml += "<div style=\'width:100px; height:32px; left:" + leftPx + "px; top:" +
        topPx + "px; position:absolute; font-size:11px;\' class=\'mapFont\'><div class=\'maptide\'></div><div>" + row.SName + "<br/><a id=\'" + row.Id + "\'></a></div></div>";
    });
    $(".map").append(strHtml);
}

function addPoint(leftPx, topPx, Name, id) {
    return "<div style=\'width:100px; height:32px; left:" + leftPx + "px; top:" +
        topPx + "px; position:absolute; font-size:10px;\' 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();
    });
})

