// 天気予報 // 天気 itsmo.lib.weather = function() {}; itsmo.lib.weather.codes = null; itsmo.lib.weather.getCodes = function() { if (null != itsmo.lib.weather.codes) { return itsmo.lib.weather.codes; } itsmo.lib.weather.codes = {}; var d = [ ['01', '晴れ(昼)', 'fine'], ['02', '晴れ(夜)', 'star'], ['03', '曇り', 'cloudy'], ['04', '雪', 'snow'], ['05', '雨', 'rain'], ['101', '晴れ時々曇り', ''], ['100', '晴れ', ''], ['102', '晴れ一時雨', ''], ['103', '晴れ時々雨', ''], ['104', '晴れ一時雪', ''], ['105', '晴れ時々雪', ''], ['111', '晴れのち曇り', ''], ['114', '晴れのち雨', ''], ['117', '晴れのち雪', ''], ['201', '曇り時々晴れ', ''], ['202', '曇り一時雨', ''], ['203', '曇り時々雨', ''], ['204', '曇り一時雪', ''], ['205', '曇り時々雪', ''], ['209', '霧', ''], ['211', '曇りのち晴れ', ''], ['214', '曇りのち雨', ''], ['217', '曇りのち雪', ''], ['301', '雨時々晴れ', ''], ['302', '雨時々やむ', ''], ['303', '雨時々雪', ''], ['304', '雨もしくは雪', ''], ['309', '雨一時雪', ''], ['311', '雨のち晴れ', ''], ['313', '雨のち曇り', ''], ['315', '雨のち雪', ''], ['340', '雪もしくは雨', ''], ['401', '雪時々晴れ', ''], ['402', '雪時々やむ', ''], ['403', '雪時々雨', ''], ['409', '雪一時雨', ''], ['411', '雪のち晴れ', ''], ['413', '雪のち曇り', ''], ['414', '雪のち雨', ''], ['999', '不明', ''] ]; $.each(d, function(i, v) { itsmo.lib.weather.codes[v[0]] = { nm: v[1], _class: v[2] }; }); return itsmo.lib.weather.codes; }; itsmo.lib.weather.getWeatherHtml = function(code, isAddName) { var s = itsmo.lib.weather.getCodes(); s = s[code]; if (undefined == s || null == s) { s = '不明'; } else { var nm = s.nm; if ('' == s._class) { s = '' + nm + ''; } else { s = ''; } if (isAddName) { s += '' + nm + ''; } } return s; }; itsmo.lib.weather.daysNameStr = [ '日', '月', '火', '水', '木', '金', '土' ]; itsmo.lib.weather.getDateStr = function(d) { var s = (d.getMonth() + 1) + '/' + d.getDate() + '(' + itsmo.lib.weather.daysNameStr[d.getDay()] + ')'; return s; }; itsmo.lib.weather.get02d = function(n) { n = '0' + n; return n.substring(n.length - 2); }; itsmo.lib.weather.eventSentaku = function(result) { if (null != result && 0 == result.status) { } else { return; } $.each(result.items, function(i, v) { var n = $.inArray(v.tenkiDate, itsmo.lib.weather.days); if (n < 0 || n >= 2) { return; } if (v.sentaku >= 1 && v.sentaku <= 4) { // ok.正常な値。 } else { return; } var s = '' + v.sentakuName + '' + v.sentakuName + ''; $('#id_table_' + n + ' tr.wash td').html(s); }); }; itsmo.lib.weather.eventWeather3hour = function(code, result) { if ('000' != code.code) { return; } // 発表日時 var s = result.info.date.pubDate; $('#id_pubY').html(s.substring(0, 4)); $('#id_pubM').html(parseInt(s.substring(4, 6), 10) + ''); $('#id_pubD').html(parseInt(s.substring(6, 8), 10) + ''); s = result.info.date.pubTime; $('#id_pubH').html(parseInt(s.substring(0, 2), 10) + ''); $('#id_pubI').html(s.substring(2, 4)); $.each(result.item, function(i, v) { var n = $.inArray(v.weatherDate, itsmo.lib.weather.days); if (n < 0 || n >= 2) { return null; } var h = parseInt(v.weatherTime.substring(0, 2), 10); if (0 == n) { h = (h - 6) / 3; } else { h /= 3; } var id = '#id_table_' + n; var id2 = 'td:eq(' + h + ')'; if (v.weatherCode == null) { s = '-'; } else { s = itsmo.lib.weather.getWeatherHtml(v.weatherCode); } $(id + ' tr:eq(1) ' + id2).html(s); if (v.weatherCode == null) { s = ''; } else { s = v.temperature; } $(id + ' tr:eq(2) ' + id2 + ' span').html(s); if (v.weatherCode == null) { s = ''; } else { s = v.rainMm; } $(id + ' tr:eq(3) ' + id2 + ' span').html(s); return null; }); }; itsmo.lib.weather.eventWeatherWeek = function(code, result) { if ('000' != code.code) { return; } $.each(result.item, function(i, v) { var n = $.inArray(v.weatherDate, itsmo.lib.weather.days); if (n < itsmo.lib.weather.weatherWeekSkipNum) { return; } var id = '#id_table_2'; var id2 = 'td:eq(' + (n - itsmo.lib.weather.weatherWeekSkipNum) + ')'; var e = $(id + ' tr:eq(2) ' + id2); e.find('span.highest').html('' + v.maxTemperature); e.find('span.lowest').html('' + v.minTemperature); var s = v.rainPercent; $(id + ' tr:eq(3) ' + id2 + ' span').html(s); s = itsmo.lib.weather.getWeatherHtml(v.weatherCode, true); $(id + ' tr:eq(1) ' + id2).html(s); }); }; itsmo.lib.weather.days = null; itsmo.lib.weather.weatherWeekSkipNum = 2; itsmo.lib.weather.init = function(lat, lon) { var s, i, v; if (lat <= 0 || lon <= 0) { lat = 128441320; lon = 503169540; } // 日付設定。 s = new Date(); itsmo.lib.weather.days = []; for (i = 0; i < 7; ++i) { $('span.id_daystr_' + i).html(itsmo.lib.weather.getDateStr(s)); itsmo.lib.weather.days.push(s.getFullYear() + itsmo.lib.weather.get02d(s.getMonth() + 1) + itsmo.lib.weather.get02d(s.getDate())); s.setTime(s.getTime() + 1 * 24 * 60 * 60 * 1000); } // 洗濯情報取得。 /* opt = new ZdcNearTenkiOptions(); opt.point = new ZdcPoint(lon, lat, 2); opt.timeout = 3000; gik = new ZdcNearTenki(); ZdcEvent.addListener(gik, 'end', itsmo.lib.weather.eventSentaku); gik.search(opt); */ // 3時間毎の天気を取得。 ZDC.Search.getWeatherThreeHours({latlon: itsmo.lib.toLatLon(lat, lon)}, itsmo.lib.weather.eventWeather3hour); // 週間天気を取得。 ZDC.Search.getWeatherWeek({latlon: itsmo.lib.toLatLon(lat, lon)}, itsmo.lib.weather.eventWeatherWeek); }; itsmo.lib.weather.week = function(lat, lon) { var s, i, v; if (lat <= 0 || lon <= 0) { lat = 128441320; lon = 503169540; } // 日付設定。 s = new Date(); myDate = s.getDate(); s.setDate(myDate+1); itsmo.lib.weather.days = []; for (i = 0; i < 7; ++i) { $('span.id_daystr_' + i).html(itsmo.lib.weather.getDateStr(s)); itsmo.lib.weather.days.push(s.getFullYear() + itsmo.lib.weather.get02d(s.getMonth() + 1) + itsmo.lib.weather.get02d(s.getDate())); s.setTime(s.getTime() + 1 * 24 * 60 * 60 * 1000); } // 週間天気を取得。 opt = new ZdcNearTenkiWeekOptions(); opt.point = new ZdcPoint(lon, lat, 2); opt.timeout = 3000; gik = new ZdcNearTenkiWeek(); ZdcEvent.addListener(gik, 'end', itsmo.lib.weather.eventTenkiWeek2); gik.search(opt); } itsmo.lib.weather.eventTenkiWeek2 = function(result) { if (null != result && 0 == result.status) { } else { return; } // 発表日時 var st = result.pubDate; $('#id_pubY').html(st.substring(0, 4)); $('#id_pubM').html(parseInt(st.substring(4, 6), 10) + ''); $('#id_pubD').html(parseInt(st.substring(6, 8), 10) + ''); st = result.pubTime; $('#id_pubH').html(parseInt(st.substring(0, 2), 10) + ''); $('#id_pubI').html(st.substring(2, 4)); $.each(result.items, function(i, v) { var n = $.inArray(v.tenkiDate, itsmo.lib.weather.days); var id = '#id_table_2'; var id2 = 'td:eq(' + n + ')'; var e = $(id + ' tr:eq(2) ' + id2); e.find('span.highest').html((v.maxTemperature=='') ? '-': '' + v.maxTemperature); e.find('span.lowest').html((v.minTemperature=='') ? '-': '' + v.minTemperature); var s = (v.rainPercent=='') ? '-': '' + v.rainPercent; $(id + ' tr:eq(3) ' + id2 + ' span').html(s); s = itsmo.lib.weather.getWeatherHtml(v.tenkiCode, true); $(id + ' tr:eq(1) ' + id2).html(s); }); };