// 百度地图-乡镇预报 var mkjson = null; var map = null; var infoBoxs = null; var infoList = null; /* 如果雨>0:有雨 否则: 0:晴 1~2:少云 3~6:少到多云 7~9:多云 10:阴天 杜哥提供20141229 */ var weatherStatus = { 0: ["晴", 0], 1: ["少云", 1], 2: ["少云", 1], 3: ["少到多云", 1], 4: ["少到多云", 1], 5: ["少到多云", 1], 6: ["少到多云", 1], 7: ["多云", 1], 8: ["多云", 1], 9: ["多云", 1], 10: ["阴天", 2], 11: ["有雨", 7] }; $(function () { $("#map_jingxh").parent('div').show(); map = new BMap.Map("map_jingxh"); map.addControl(new BMap.MapTypeControl()); //添加地图类型控件 map.centerAndZoom(new BMap.Point(112.925278, 23.069838), 10); $("#map_jingxh").parent('div').hide(); $.getJSON("/weather/data/township/township.js?t=" + Math.random(), function (json) { if (json) { infoList = json; addInfoWindow(json); } }); }); //各站点预报 function addInfoWindow(json) { if (json) { $.each(json, function (key, value) { var station = value[0].station; var name = station[0]; var longitude = station[3]; var latitude = station[4]; if (longitude == "" && latitude == "") return; mkjson = value[0];//json addMarker(longitude, latitude, 0); }); map.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用 map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件 //鼠标点击任意点获取预报信息 map.addEventListener("click", function (e) { if(e.overlay != null) return; var pt = e.point; var geoc = new BMap.Geocoder(); var geocname = ""; geoc.getLocation(pt, function (rs) { var addComp = rs.addressComponents; //alert(addComp.province + "," + addComp.city + "," + addComp.district + "," + addComp.street + "," + addComp.streetNumber); geocname = addComp.province + "," + addComp.city + "," + addComp.district + "," + addComp.street + "," + addComp.streetNumber; }) if (infoBoxs != null) infoBoxs.close(); var lng = e.point.lng; var lat = e.point.lat; $.ajax({ type: "POST", url: "weather/TownshipHandler.aspx", data: { action: 'view', lng: lng, lat: lat }, dataType: "json", success: function (json) { if (json) { mkjson = json; addMarker(lng, lat, 1, geocname); } } }); }); } }; function addMarker(longitude, latitude, isopen, geocname) { //创建小狐狸 if (isopen == 1) mkjson = mkjson[0]; var name = ""; var rain = mkjson.rain; var t2mm = mkjson.t2mm; var rh2m = mkjson.rh2m; var clct = mkjson.clct; var curr_date = new Date(); var day = curr_date.getDate(); var housr = curr_date.getHours(); var strtI = 3;//去除前一天4小时 预报时间为世界时前一天12点,+8小时才还是昨天20点,再加4才是北京时间的今天00点 var iend = strtI +24; var pt7 = new BMap.Point(longitude, latitude); //地点 var marker7 = new BMap.Marker(pt7, { icon: myIcon7 }); // 创建标注 if (isopen == 1) { marker7.hide(); name = geocname; } else { name=mkjson.station[1]; } //创建信息窗口 var sContent7 = new Array(); sContent7.push("
日期 | 天气 | 气象现象 | 最低气温(℃) | 最高气温(℃) |
---|---|---|---|---|
" + curr_date.Format('MM月dd日') + " | " + weathert_name + " | " + mint + " | " + maxt + " |