function beaufort(si,windspeed){ //console.log(si +" -"+ windspeed); var b = 0; mph = windspeed; if (si=='c') mph = mph * 1.609344; if (mph==0){b=0;} if ((mph>=1)&&(mph<3)){b=1;} if ((mph>=4)&&(mph<7)){b=2;} if ((mph>=8)&&(mph<12)){b=3;} if ((mph>=13)&&(mph<18)){b=4;} if ((mph>=19)&&(mph<24)){b=5;} if ((mph>=25)&&(mph<31)){b=6;} if ((mph>=32)&&(mph<38)){b=7;} if ((mph>=39)&&(mph<46)){b=8;} if ((mph>=47)&&(mph<54)){b=9;} if ((mph>=55)&&(mph<63)){b=10;} if ((mph>=64)&&(mph<72)){b=11;} if (mph>=73){b=12;} //console.log(mph +" -"+ b); return b; } function coloruvindex(uv){ if (uv<=2) color = "10bf00"; if ((uv>=3)&&(uv<=5)) color = "fff400"; if ((uv>=6)&&(uv<=7)) color = "ffab0a"; if ((uv>=8)&&(uv<=10)) color = "e11900"; if (uv>=11) color = "9324C6"; color = 'fff'; return color; } function getweatherinfo(id,lat,lon,si,lang){ // console.log(1); var wna = { "clear-day":"wi-day-sunny", "clear-night":"wi-night-clear", "rain":"wi-rain", "snow":"wi-snow", "sleet":"wi-sleet", "wind":"wi-cloudy-windy", "fog":"wi-fog", "cloudy":"wi-cloudy", "partly-cloudy-day":"wi-day-cloudy", "partly-cloudy-night":"wi-night-alt-cloudy", "hail":"wi-hail", "thunderstorm":"wi-thunderstorm", "tornado":"wi-tornado" }; var languages = ["ar","bs","de","el","en","es","fr","hr","hu","it","nl","pl","pt","ru","sk","sv","tet","tr","uk","x-pig-latin","zh-tw","zh"]; var unit = ''; var tempicon = ''; if (si=='f') { unit= 'us'; tempicon = 'fahrenheit'; } if (si=='c') { unit= 'si'; tempicon = 'celsius'; } //unit = 'auto'; lang = lang.toLowerCase(); var a = languages.indexOf(lang); var language = 'en'; if (a>0) language = lang; //console.log(a + language); $(function() { // var url = "//api.forecast.io/forecast/f07775805be1c71820c8fbdcabe9648a/"+lat+","+lon+ "?solar=1&units="+unit+"&lang="+language+"&exclude=alerts,flags&callback=?"; var url = "//api.darksky.net/forecast/f07775805be1c71820c8fbdcabe9648a/"+lat+","+lon+ "?solar=1&units="+unit+"&lang="+language+"&exclude=alerts,flags&callback=?"; //console.log(url); $.ajax({ url: url, dataType: 'json', async: false, success: function(data) { var html = ''; var html2 = ''; html += data.daily.summary; html += "";//class=weatherinfo html += ''; /* "time": 1453503600, "summary": "Mostly cloudy starting in the afternoon.", "icon": "partly-cloudy-night", "sunriseTime": 1453534690, "sunsetTime": 1453565460, "moonPhase": 0.48, "precipIntensity": 0.0381, "precipIntensityMax": 0.3988, "precipIntensityMaxTime": 1453503600, "precipProbability": 0.59, "precipType": "rain", "temperatureMin": 5.63, "temperatureMinTime": 1453503600, "temperatureMax": 9.05, "temperatureMaxTime": 1453554000, "apparentTemperatureMin": 1.79, "apparentTemperatureMinTime": 1453586400, "apparentTemperatureMax": 6.39, "apparentTemperatureMaxTime": 1453554000, "dewPoint": 5.84, "humidity": 0.92, "windSpeed": 5.12, "windBearing": 251, "cloudCover": 0.39, "pressure": 1028.34, "ozone": 370.9 */ var i = 0; while (i <= 7 ) { html += "'; //https://erikflowers.github.io/weather-icons/ html2 += "
'; html2 += "
"; html2 += "
"; html2 += "Min. "+ Math.round(data.daily.data[i].temperatureMin); html2 += " "; html2 += '
'; html2 += "Max. "+ Math.round(data.daily.data[i].temperatureMax); html2 += " "; html2 += '
'; html2 += " "+moment.unix(data.daily.data[i].sunriseTime).format("H:mm:ss")+'
'; html2 += " "+moment.unix(data.daily.data[i].sunsetTime).format("H:mm:ss")+'
'; html2 += ''; html2 += "
"; i++; } html += ''; html += '
"; html += moment.unix(data.daily.data[i].time).format("ddd"); html += '
'; html += ""; html += '
'; // html += Math.round(data.daily.data[i].temperatureMin); // html += ' / '; html += Math.round(data.daily.data[i].temperatureMax); //html +=""; html += '
'; // html += ""; html += '
'; $('#weatherinfo_'+id).html(html); $('#weatherinfo2_'+id).html(html2); /* "currently": { "time": 1454355966, "summary": "Overwegend bewolkt", "icon": "partly-cloudy-night", "precipIntensity": 0.0559, "precipProbability": 0.06, "precipType": "rain", "temperature": 9.92, "apparentTemperature": 5.55, "dewPoint": 7.75, "humidity": 0.86, "windSpeed": 12.93, "windBearing": 241, "cloudCover": 0.79, "pressure": 1012.6, "ozone": 234.68 }, */ var htmlnow = ''; htmlnow += "
"; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; /* htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; htmlnow += ''; */ htmlnow += '
'; htmlnow += " "; htmlnow += ''; htmlnow += "
"+ Math.round(data.currently.temperature); htmlnow += "°"+si.toUpperCase(); htmlnow += '
'; htmlnow += '
'; /* start UV-index */ var j = 0; var maxuv = 0; var maxuvstarttime = moment.tz((data.hourly.data[0].time )*1000, data.timezone); var maxuvst = parseInt(maxuvstarttime.format("HH")); while (j <= 23 ){ var maxuvtime = moment.tz((data.hourly.data[j].time )*1000, data.timezone); var maxuvt = parseInt(maxuvtime.format("HH")); if (maxuvt>=maxuvst){ if (maxuv"; htmlnow += 'UV '; if (maxuv!=data.currently.uvIndex){ htmlnow += 'max. '; htmlnow += maxuv; } if (maxuv!=data.currently.uvIndex) { htmlnow += '
'; htmlnow += " (now "; } htmlnow += data.currently.uvIndex; if (maxuv!=data.currently.uvIndex) { htmlnow += ")"; } /* end UV-index */ htmlnow += ''; htmlnow += '
'; var cmt = moment.tz((data.daily.data[0].apparentTemperatureMinTime)*1000, data.timezone); var mintime = cmt.format("h a"); var cmt2 = moment.tz((data.daily.data[0].apparentTemperatureMaxTime)*1000, data.timezone); var maxtime = cmt2.format("h a"); htmlnow += Math.round(data.daily.data[0].apparentTemperatureMin); htmlnow += ' - '; htmlnow += Math.round(data.daily.data[0].apparentTemperatureMax); htmlnow += "°"+si.toUpperCase(); // htmlnow += '
'; // htmlnow += "Windchill: "+ Math.round(data.currently.apparentTemperature); // htmlnow += "°"+si.toUpperCase(); htmlnow += '
'; htmlnow += " "; htmlnow += Math.round(data.currently.cloudCover*100) +"%"; htmlnow += ''; htmlnow += " "; var windspeed = 0; if (si=='c') windspeed = Math.round((data.currently.windSpeed) *3.6) +" km/u"; if (si=='f') windspeed = Math.round(data.currently.windSpeed) + "mph"; htmlnow += windspeed; var b = beaufort(si,Math.round(data.currently.windSpeed) ); htmlnow += ""; htmlnow += '
'; htmlnow += " "; htmlnow += Math.round(data.currently.humidity*100) +"%"; htmlnow += ''; htmlnow += " "; htmlnow += Math.round(data.currently.pressure)+ " mb"; htmlnow += '
'; htmlnow += '
'; htmlnow += ''; // htmlnow += ''; // console.log(htmlnow); $('#weatherinfonow_main_'+id).html(htmlnow); $('#weatherinfonow_'+id).html(html); // $('.weather').html(html); var c = moment.tz((data.currently.time)*1000, data.timezone); var dateString = c.format("MM/DD/YYYY HH:mm:ss"); // 2014-06-22T12:21:08-04:00 //console.log(dateString); } }); }); } $(function() { $( document ).on("mouseover", ".weathercell", function(e){ var idtd = $(this).attr("id"); var res = idtd.split("_"); var wd = "wd_"+res[1]+"_"+res[2]; //console.log(wd); $("#"+wd).show(); }); $( document ).on("mouseout", ".weathercell", function(e){ var idtd = $(this).attr("id"); var res = idtd.split("_"); var wd = "wd_"+res[1]+"_"+res[2]; //console.log(wd); $("#"+wd).hide(); }); $(document).on('mousemove', function(e){ $('.weatherdetail').offset({ left: e.pageX-100, top: e.pageY-250 }); }); });