Removed yahoo api, now using openweatherapi
This commit is contained in:
parent
ecd5aac507
commit
939cd57e94
|
@ -2,112 +2,112 @@ function DataManager(pointSearch){
|
|||
var $this = $(this),
|
||||
that = this,
|
||||
includeRadiusMiles=20;
|
||||
|
||||
|
||||
var _locations = [];
|
||||
|
||||
this.locations = _locations;
|
||||
|
||||
this.locations = _locations;
|
||||
|
||||
this.location = function(woeid) {
|
||||
return _locations.find(x => x.woeid === woeid);
|
||||
}
|
||||
|
||||
|
||||
this.init = function (searchString) {
|
||||
_locations[0] = new Location();
|
||||
|
||||
|
||||
$(_locations[0])
|
||||
|
||||
|
||||
.on('refresh', function(){ $this.trigger('refresh') })
|
||||
.on('ready', function(){
|
||||
.on('ready', function(){
|
||||
$this.trigger('ready:main');
|
||||
})
|
||||
.on('init', initLocations);
|
||||
_locations[0].first = true;
|
||||
_locations[0].first = true;
|
||||
_locations[0].init(searchString);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// kicks off after main location is returned.
|
||||
// create the list of neighboring cities
|
||||
function initLocations(){
|
||||
|
||||
|
||||
// find reporting stations
|
||||
var observationData = _locations[0].observations(0),
|
||||
lat = observationData.item.lat,
|
||||
lon = observationData.item.long,
|
||||
lat = observationData.lat,
|
||||
lon = observationData.lon,
|
||||
locList = [];
|
||||
|
||||
|
||||
// begin the forcast pull
|
||||
_locations[0].initForecasts();
|
||||
|
||||
// get a list of observation stations info
|
||||
// get a list of observation stations info
|
||||
$.getJSON('https://api.weather.gov/points/' + lat + ',' + lon + '/stations', function(data) {
|
||||
|
||||
|
||||
var feature, geo, station, dist;
|
||||
for (var i=0; i < data.features.length; i++) {
|
||||
|
||||
|
||||
feature = data.features[i];
|
||||
geo = feature.geometry.coordinates;
|
||||
dist = distance(lat, lon, geo[1], geo[0]);
|
||||
|
||||
if (dist < includeRadiusMiles) {
|
||||
|
||||
if (dist < includeRadiusMiles) {
|
||||
locList.push({lat: geo[1], long:geo[0], distance:dist, stationUrl:feature.id});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (locList.length===0) {
|
||||
$this.trigger('allinit');
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// sort list by distance
|
||||
locList.sort(function(a, b) {
|
||||
return parseInt(a.distance) - parseInt(b.distance);
|
||||
});
|
||||
|
||||
|
||||
// set the station for location 0
|
||||
_locations[0].stationUrl = locList[0].stationUrl
|
||||
_locations[0].initNWSObservations();
|
||||
|
||||
|
||||
// create location objects, get inital pull
|
||||
for(var loc of locList) {
|
||||
loc.location = new Location();
|
||||
$(loc.location).on('init',onLocationInit);
|
||||
loc.location.init(loc.lat+','+loc.long);
|
||||
loc.location.init(loc.lat+','+loc.long);
|
||||
loc.location.stationUrl = loc.stationUrl;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
var initCount=0;
|
||||
function onLocationInit() {
|
||||
initCount++;
|
||||
if (initCount===locList.length) {
|
||||
allLocationsInit();
|
||||
allLocationsInit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function allLocationsInit() {
|
||||
|
||||
|
||||
var location, cities=[], city;
|
||||
|
||||
// add locations removing any duplicate cities by name
|
||||
for(var loc of locList) {
|
||||
|
||||
|
||||
if (_locations.filter(e => e.city == loc.location.city).length === 0) {
|
||||
_locations.push(loc.location);
|
||||
loc.location.initForecasts();
|
||||
loc.location.initNWSObservations();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this.trigger('allinit');
|
||||
|
||||
$this.trigger('allinit');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function GroupDataManager() {
|
||||
var locations =
|
||||
var locations =
|
||||
[
|
||||
{name:'Chicago', n2:'IL'},
|
||||
{name:'Minneapolis', n2:'MN'},
|
||||
|
@ -19,59 +19,57 @@ function GroupDataManager() {
|
|||
{name:'Ixtapa', n2:'MX'}
|
||||
]
|
||||
;
|
||||
|
||||
checkRefresh();
|
||||
|
||||
checkRefresh();
|
||||
setInterval(checkRefresh, 300000);
|
||||
|
||||
|
||||
// check to see if data needs to be refreshed
|
||||
function checkRefresh() {
|
||||
var woeid, location;
|
||||
|
||||
|
||||
for (location of locations) {
|
||||
|
||||
|
||||
// check the expiration
|
||||
if (location.hasOwnProperty('xdate') && dateFns.isFuture(location.xdate)) { continue; }
|
||||
|
||||
|
||||
woeid = location.hasOwnProperty('woeid') ? location.woeid : '';
|
||||
|
||||
|
||||
// woeid is the id for the location to pull data for
|
||||
var url = 'https://query.yahooapis.com/v1/public/yql?format=json&q=' +
|
||||
'select * from weather.forecast where woeid' +
|
||||
(woeid ? '='+woeid : ' in (select woeid from geo.places(1) where text="(' + (location.name + ' ' + location.n2).trim() + ')")' );
|
||||
|
||||
var url = 'https://api.openweathermap.org/data/2.5/weather?q='+ location.name + '&appid=putapikeyhere&units=imperial'
|
||||
|
||||
pullData(url, location);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function pullData(url, location) {
|
||||
var $span;
|
||||
|
||||
|
||||
// ajax the latest observation
|
||||
$.getJSON(url, function(data) {
|
||||
location.data = data.query.results.channel;
|
||||
location.data = data;
|
||||
|
||||
if ( !location.hasOwnProperty('woeid') ) {
|
||||
location.woeid = location.data.link.match(/(\d*)\/$/)[1];
|
||||
$span = $("<span id='" + location.woeid + "'></span>").appendTo('#marquee-now');
|
||||
location.woeid = location.data.id;
|
||||
$span = $("<span id='" + location.woeid + "'></span>").appendTo('#marquee-now');
|
||||
} else {
|
||||
$span = $('#marquee-now>span#' + location.woeid);
|
||||
$span = $('#marquee-now>span#' + location.woeid);
|
||||
}
|
||||
|
||||
// display the current info
|
||||
$span.text(location.name + ': ' + location.data.item.condition.temp + ' ' + location.data.item.condition.text.toLowerCase());
|
||||
|
||||
$span.text(location.name + ': ' + Math.round(parseInt(location.data.main.temp)) + ' ' + location.data.weather[0].description.toLowerCase());
|
||||
|
||||
|
||||
// set the expiration date/time
|
||||
location.xdate = dateFns.addMinutes(location.data.lastBuildDate, location.data.ttl);
|
||||
location.xdate = dateFns.addMinutes(location.data.lastBuildDate, location.data.ttl);
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
var groupDataManager = new GroupDataManager;
|
||||
var groupDataManager = new GroupDataManager;
|
||||
|
|
|
@ -1,87 +1,92 @@
|
|||
function Location() { // onReady, onRefresh, onAllComplete
|
||||
|
||||
|
||||
var that = this,
|
||||
$this = $(this),
|
||||
_forecastmgr,
|
||||
_observations=[];
|
||||
|
||||
_observations=[];
|
||||
|
||||
this.temperature = function() {
|
||||
if (_observations[1]!=null && _observations[1].temperature.value) {
|
||||
return C2F(_observations[1].temperature.value);
|
||||
} else {
|
||||
return Math.round( _observations[0].item.condition.temp );
|
||||
}
|
||||
return Math.round( _observations[0].current.temp );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.observations = function(i) {
|
||||
return _observations[i];
|
||||
};
|
||||
|
||||
|
||||
this.forecasts=function(type){return _forecastmgr.forecast(type)};
|
||||
|
||||
|
||||
this.init = function(searchString){
|
||||
checkRefresh(searchString);
|
||||
};
|
||||
|
||||
|
||||
this.initForecasts = function() {
|
||||
// start the forecast data pull
|
||||
_forecastmgr = new ForecastManager(_observations[0].item.lat, _observations[0].item.long, function() {
|
||||
_forecastmgr = new ForecastManager(_observations[0].lat, _observations[0].lon, function() {
|
||||
$this.trigger('ready');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
this.initNWSObservations = function(){
|
||||
stationObservations();
|
||||
};
|
||||
|
||||
|
||||
|
||||
// check to see if data needs to be refreshed
|
||||
function checkRefresh(location) {
|
||||
|
||||
|
||||
// check the expiration
|
||||
if ( _observations[0]!=undefined && dateFns.isFuture( _observations[0].xdate ) ) {
|
||||
setTimeout(checkRefresh, getRandom(5000, 10000));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// woeid is the id for the location to pull data for
|
||||
var url = 'https://query.yahooapis.com/v1/public/yql?format=json&q=' +
|
||||
'select * from weather.forecast where woeid' +
|
||||
(that.woeid ? '='+that.woeid : ' in (select woeid from geo.places(1) where text="(' + location + ')")' )
|
||||
console.log(location);
|
||||
if (location != undefined) {
|
||||
var loclat = location.split(",")[0]
|
||||
var loclong = location.split(",")[1]
|
||||
var url = 'https://api.openweathermap.org/data/2.5/onecall?lat=' + loclat + '&lon=' + loclong + '&appid=putkeyhere&units=imperial'
|
||||
|
||||
|
||||
// ajax the latest observation
|
||||
$.getJSON(url, function(data) {
|
||||
_observations[0] = json = data.query.results.channel;
|
||||
|
||||
_observations[0] = json = data;
|
||||
|
||||
$this.trigger('refresh');
|
||||
|
||||
// the following block only runs on init
|
||||
// the following block only runs on init
|
||||
if (that.woeid===undefined) {
|
||||
|
||||
that.woeid = json.link.match(/(\d*)\/$/)[1];
|
||||
|
||||
that.lat = json.item.lat;
|
||||
that.long = json.item.long;
|
||||
|
||||
that.city = data.query.results.channel.location.city;
|
||||
that.woeid = loclat
|
||||
|
||||
$this.trigger('init');
|
||||
that.lat = data.lat
|
||||
that.long = data.lon;
|
||||
|
||||
//that.city = data.query.results.channel.location.city;
|
||||
|
||||
$this.trigger('init');
|
||||
|
||||
}
|
||||
|
||||
// set the expiration date/time
|
||||
_observations[0].xdate = dateFns.addMinutes(json.lastBuildDate, json.ttl);
|
||||
|
||||
_observations[0].xdate = dateFns.addMinutes(json.lastBuildDate, json.ttl);
|
||||
|
||||
setTimeout(checkRefresh, getRandom(5000, 10000));
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
$.getJSON('http://api.openweathermap.org/geo/1.0/reverse?lat=' + loclat + '&lon=' + loclong + '&limit=1&appid=0cb279a98124446dd16dba02fbfb60ee', function(sloc) {
|
||||
that.city = sloc[0].name;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// pull observations from the location observation station
|
||||
function stationObservations(){
|
||||
function stationObservations() {
|
||||
|
||||
var url = that.stationUrl + '/observations/current';
|
||||
|
||||
|
@ -96,27 +101,26 @@ function Location() { // onReady, onRefresh, onAllComplete
|
|||
_observations[1] = data.properties;
|
||||
|
||||
// set the expiration date/time
|
||||
_observations[1].xdate = dateFns.addMinutes(data.properties.timestamp, 60);
|
||||
_observations[1].xdate = dateFns.addMinutes(data.properties.timestamp, 60);
|
||||
setTimeout(stationObservations, getRandom(5000, 10000));
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function ForecastManager (latitude, longitude, readyCallback) {
|
||||
var _forecasts = {},
|
||||
keys =['daily','hourly'],
|
||||
keys =['daily','hourly'],
|
||||
key,
|
||||
readycount = 0;
|
||||
|
||||
for(key of keys) {
|
||||
_forecasts[key] = new Forecast(key, latitude, longitude, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function count() {
|
||||
// count up completed forecast pulls
|
||||
readycount++;
|
||||
|
@ -124,26 +128,26 @@ function ForecastManager (latitude, longitude, readyCallback) {
|
|||
readyCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.forecast = function(type) {
|
||||
try{
|
||||
return _forecasts[type].data;
|
||||
} catch(err){}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function Forecast(type, lat, lon, readyCallback) {
|
||||
|
||||
|
||||
var that = this,
|
||||
url = 'https://api.weather.gov/points/' + lat + ',' + lon + '/forecast/' + (type==='hourly' ? type : '');
|
||||
|
||||
|
||||
this.data = {};
|
||||
|
||||
|
||||
checkRefresh();
|
||||
|
||||
|
||||
function checkRefresh() {
|
||||
|
||||
|
||||
// check the expiration
|
||||
if ( that.data!={} && dateFns.isFuture( that.data.xdate ) ) {
|
||||
setTimeout(checkRefresh, getRandom(5000, 10000));
|
||||
|
@ -153,28 +157,20 @@ function Forecast(type, lat, lon, readyCallback) {
|
|||
// ajax the forecast
|
||||
$.getJSON(url, function(data) {
|
||||
that.data = data.properties.periods;
|
||||
|
||||
|
||||
// trigger ready callback on first data pull
|
||||
if (readyCallback){
|
||||
readyCallback();
|
||||
}
|
||||
|
||||
|
||||
// set the expiration date/time
|
||||
//that.data.xdate = dateFns.addMinutes(data.properties.updated, 60);
|
||||
that.data.xdate = dateFns.addMinutes(new Date(), 5);
|
||||
//that.data.xdate = dateFns.addMinutes(data.properties.updated, 60);
|
||||
that.data.xdate = dateFns.addMinutes(new Date(), 5);
|
||||
setTimeout(checkRefresh, getRandom(5000, 10000));
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
function Loops(bindDataManager) {
|
||||
var //dataManager,
|
||||
obsData,
|
||||
foreDataDaily,
|
||||
obsData,
|
||||
foreDataDaily,
|
||||
foreDataHourly;
|
||||
|
||||
|
||||
obsData = bindDataManager.observations;
|
||||
foreDataDaily = bindDataManager.forecasts('daily');
|
||||
foreDataHourly = bindDataManager.forecasts('hourly');
|
||||
|
@ -16,39 +16,41 @@ function Loops(bindDataManager) {
|
|||
|
||||
function displayAtmospheric(idx) {
|
||||
|
||||
var displays = {
|
||||
|
||||
var displays = {
|
||||
|
||||
conditions() {
|
||||
return obsData(0).item.condition.text.toLowerCase();
|
||||
return obsData(0).current.weather[0].description.toLowerCase();
|
||||
},
|
||||
|
||||
wind(){ return 'wind ' + degToCompass(obsData(0).wind.direction) + ' ' + obsData(0).wind.speed; },
|
||||
wind(){ return 'wind ' + degToCompass(obsData(0).current.wind_deg) + ' ' + Math.round(parseInt(obsData(0).current.wind_speed)); },
|
||||
|
||||
gusts(){
|
||||
gusts(){
|
||||
if ( obsData(1)!=undefined ) {
|
||||
return obsData(1).windGust.value!=null ? 'gusts ' + mps2mph( obsData(1).windGust.value ) : '';
|
||||
return obsData(1).windGust.value!=null ? 'gusts ' + mps2mph( obsData(1).windGust.value ) : '';
|
||||
}
|
||||
},
|
||||
|
||||
humidity(){ return 'humidity ' + obsData(0).atmosphere.humidity + '%'; },
|
||||
humidity(){ return 'humidity ' + obsData(0).current.humidity + '%'; },
|
||||
|
||||
dewpoint(){ return 'dew point ' + dewPoint(obsData(0).item.condition.temp, obsData(0).atmosphere.humidity ) + '°'; },
|
||||
dewpoint(){ return 'dew point ' + dewPoint(obsData(0).current.temp, obsData(0).current.humidity ) + '°'; },
|
||||
|
||||
heatindex_windchill(){
|
||||
if (parseInt(obsData(0).item.condition.temp)<80 && parseInt(obsData(0).wind.chill) < parseInt(obsData(0).item.condition.temp)) {
|
||||
return 'wind chill ' + obsData(0).wind.chill + '°';
|
||||
} else if (parseInt(obsData(0).item.condition.temp)>=80 && parseInt(obsData(0).atmosphere.humidity)>=40 ){
|
||||
return 'heat index ' + heatIndex(obsData(0).item.condition.temp, obsData(0).atmosphere.humidity) + '°';
|
||||
var windchill = 35.74 + (0.6215 * parseInt(obsData(0).current.temp)) + (0.4275 * parseInt(obsData(0).current.temp) - 35.75) * parseInt(obsData(0).current.wind_speed) ^ 0.16;
|
||||
if (parseInt(obsData(0).current.temp)<80 && windchill < parseInt(obsData(0).current.temp)) {
|
||||
|
||||
return 'wind chill ' + windchill + '°';
|
||||
} else if (parseInt(obsData(0).current.temp)>=80 && parseInt(obsData(0).current.humidity)>=40 ){
|
||||
return 'heat index ' + heatIndex(obsData(0).current.temp, obsData(0).current.humidity) + '°';
|
||||
}
|
||||
else return '';
|
||||
else return '';
|
||||
},
|
||||
|
||||
pressure(){ return 'pressure ' + (obsData(0).atmosphere.pressure*0.0295301).toFixed(2) + ' ' + ['S','R','F'][obsData(0).atmosphere.rising]; },
|
||||
pressure(){ return 'pressure ' + (obsData(0).current.pressure*0.0295301).toFixed(2) },
|
||||
//+ ['S','R','F'][obsData(0).current.rising];
|
||||
visibility() { return 'visibility ' + (parseInt(obsData(0).current.visibility) / 1000) + ' mile' + (obsData(0).current.visibility != 1 ? 's' : ''); },
|
||||
|
||||
visibility() { return 'visibility ' + obsData(0).atmosphere.visibility + ' mile' + (obsData(0).atmosphere.visibility != 1 ? 's' : ''); },
|
||||
uvindex() { return 'UV index ' + obsData(0).current.uvi; },
|
||||
|
||||
uvindex() { return ''; }
|
||||
|
||||
},
|
||||
keys = Object.keys(displays),
|
||||
text = displays[ keys[idx] ]();
|
||||
|
@ -56,27 +58,27 @@ function Loops(bindDataManager) {
|
|||
// increment the pointer
|
||||
idx = (++idx===keys.length ? 0 : idx);
|
||||
|
||||
if (text) {
|
||||
if (text) {
|
||||
$('#current-info').html(text);
|
||||
setTimeout(function(){ displayAtmospheric(idx) }, 6000); // 6 second increment loop
|
||||
} else {
|
||||
// nothing to display - skip to the next one
|
||||
setTimeout(function(){ displayAtmospheric(idx) }, 0);
|
||||
}
|
||||
setTimeout(function(){ displayAtmospheric(idx) }, 0);
|
||||
}
|
||||
|
||||
} // end function
|
||||
|
||||
|
||||
|
||||
|
||||
function displayForecast(idx) {
|
||||
|
||||
var displays = {
|
||||
|
||||
var displays = {
|
||||
|
||||
text1() {
|
||||
$('#forecast-title').text( possessiveForecast(foreDataDaily[0].name) );
|
||||
resizeText(foreDataDaily[0].detailedForecast);
|
||||
},
|
||||
text2() {
|
||||
$('#forecast-title').text( possessiveForecast(foreDataDaily[1].name) );
|
||||
$('#forecast-title').text( possessiveForecast(foreDataDaily[1].name) );
|
||||
resizeText(foreDataDaily[1].detailedForecast);
|
||||
},
|
||||
|
||||
|
@ -84,84 +86,84 @@ function Loops(bindDataManager) {
|
|||
var newtile, weekend, icons,
|
||||
startidx = (foreDataDaily[0].name==='Tonight' ? 1 : 2),
|
||||
days = ['SUN','MON','TUE','WED','THU','FRI','SAT'];
|
||||
|
||||
|
||||
$('#forecast-title').text("5 DAY FORECAST");
|
||||
$('#forecast-tiles').empty();
|
||||
|
||||
|
||||
for (var i=startidx; i<=10; i+=2 ) {
|
||||
|
||||
|
||||
weekend = ( dateFns.isWeekend(foreDataDaily[i].startTime) ? ' weekend' : '');
|
||||
newtile = $("<div class='forecast-tile daily" + weekend + "'></div>");
|
||||
|
||||
|
||||
$("<div class='header'></div>") .appendTo(newtile) .text(days[ dateFns.getDay(foreDataDaily[i].startTime) ]);
|
||||
|
||||
|
||||
icons = mapNWSicons(foreDataDaily[i].icon);
|
||||
for (x=icons.length-1; x>=0; x--){
|
||||
$("<img class='icon' src=''/>") .appendTo(newtile) .attr('src', icons[x]);
|
||||
$("<img class='icon' src=''/>") .appendTo(newtile) .attr('src', icons[x]);
|
||||
}
|
||||
|
||||
|
||||
$("<div class='high'></div>") .appendTo(newtile) .text(foreDataDaily[i].temperature);
|
||||
$("<div class='low'></div>") .appendTo(newtile) .text(foreDataDaily[i+1].temperature);
|
||||
|
||||
$('#forecast-tiles').append(newtile);
|
||||
|
||||
$('#forecast-tiles').append(newtile);
|
||||
}
|
||||
|
||||
$('#forecast-tiles').css('display','flex');
|
||||
|
||||
$('#forecast-tiles').css('display','flex');
|
||||
},
|
||||
|
||||
hourly() {
|
||||
var newtile, icons, sizer, highbar,
|
||||
indexes = calcHourlyReport(foreDataHourly),
|
||||
data, label, temps=[];
|
||||
|
||||
|
||||
$('#forecast-title').text( buildHourlyHeaderTitle(foreDataHourly[indexes[0]].startTime) );
|
||||
$('#forecast-tiles').empty();
|
||||
|
||||
|
||||
for (var i of indexes) {
|
||||
data = foreDataHourly[i];
|
||||
|
||||
|
||||
newtile = $("<div class='forecast-tile hourly'></div>");
|
||||
sizer = $("<div class='width-sizer'></div>").appendTo(newtile);
|
||||
|
||||
|
||||
icons = mapNWSicons(data.icon);
|
||||
for (var x=icons.length-1; x>=0; x--){
|
||||
$("<img class='icon' src=''/>") .appendTo(sizer) .attr('src', icons[x]);
|
||||
$("<img class='icon' src=''/>") .appendTo(sizer) .attr('src', icons[x]);
|
||||
}
|
||||
|
||||
|
||||
$("<div class='footer'></div>") .appendTo(newtile) .text(buildHourlyTimeTitle(data.startTime));
|
||||
|
||||
|
||||
highbar = $("<div class='hourly-high'></div>") .appendTo(sizer);
|
||||
|
||||
|
||||
$("<div class='high'></div>") .appendTo(highbar) .text(data.temperature);
|
||||
temps.push(data.temperature);
|
||||
|
||||
|
||||
$("<div class='temp-bar'></div>") .appendTo(highbar);
|
||||
|
||||
$('#forecast-tiles').append(newtile);
|
||||
|
||||
$('#forecast-tiles').append(newtile);
|
||||
}
|
||||
|
||||
|
||||
$('#forecast-tiles').css('display','flex');
|
||||
|
||||
|
||||
// animate grow and show temp
|
||||
var min = Math.min(...temps), // 54
|
||||
max = Math.max(...temps), // 73
|
||||
range = (max-min),
|
||||
prange = (100-78), // percent range for bar height
|
||||
temp, value;
|
||||
temp, value;
|
||||
$('.forecast-tile').each(function(){
|
||||
temp = $(this).find('.high').first().text();
|
||||
value = ((temp-min)/range) * prange + 78; // find percentage of range and translate to percent and add that to the starting css % height number
|
||||
$(this).find('.hourly-high').animate({height:value+"%"}, 1500,function(){
|
||||
$(this).find('.high').fadeTo('slow', 1);
|
||||
});
|
||||
});
|
||||
})
|
||||
},
|
||||
},
|
||||
|
||||
dummy(){}
|
||||
|
||||
|
||||
},
|
||||
keys = Object.keys(displays);
|
||||
|
||||
|
||||
displays[ keys[idx] ]();
|
||||
|
||||
// increment the pointer
|
||||
|
@ -170,7 +172,7 @@ function Loops(bindDataManager) {
|
|||
setTimeout(function(){ displayForecast(idx) }, 15000); // 15 second increment loop
|
||||
|
||||
}
|
||||
|
||||
|
||||
function resizeText(text){
|
||||
var s = 38,
|
||||
$test = $('<div style="position:absolute;top:100%;"></div>') .appendTo('#forecast-text') .css('font-size', s + 'px') .html(text);
|
||||
|
@ -183,29 +185,29 @@ function Loops(bindDataManager) {
|
|||
$('#forecast-text div') .text(text) .css('font-size', s + 'px');
|
||||
$test.remove();
|
||||
$('#forecast-tiles').hide();
|
||||
//},100); // delay is a workaround for Interstate font not updating display
|
||||
}
|
||||
|
||||
function possessiveForecast(text){
|
||||
return text + (text.toUpperCase() != 'OVERNIGHT' ? "'S" : '') + ' FORECAST';
|
||||
//},100); // delay is a workaround for Interstate font not updating display
|
||||
}
|
||||
|
||||
|
||||
function possessiveForecast(text){
|
||||
return text + (text.toUpperCase() != 'OVERNIGHT' ? "'S" : '') + ' FORECAST';
|
||||
}
|
||||
|
||||
|
||||
} // end Loops class
|
||||
|
||||
|
||||
function buildHourlyHeaderTitle(time) {
|
||||
var today = new Date(),
|
||||
var today = new Date(),
|
||||
tomorrow = dateFns.addDays(today, 1),
|
||||
sforecast = "'s Forecast";
|
||||
|
||||
|
||||
// title based on the first hour reported
|
||||
switch (dateFns.getHours(time)) {
|
||||
|
||||
|
||||
case 6: // 6 - Nextday's Forecast / Today's Forecast
|
||||
// if 6am today
|
||||
if (dateFns.isToday(time)) {
|
||||
return dateFns.format(today, 'dddd') + sforecast;
|
||||
return dateFns.format(today, 'dddd') + sforecast;
|
||||
}
|
||||
case 0: // 0 - Nextday's Forecast
|
||||
return dateFns.format(tomorrow, 'dddd') + sforecast;
|
||||
|
@ -221,7 +223,7 @@ function buildHourlyHeaderTitle(time) {
|
|||
|
||||
case 20:
|
||||
return dateFns.format(today, 'ddd') + ' Night/' + dateFns.format(tomorrow, 'ddd');
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -229,13 +231,13 @@ function buildHourlyHeaderTitle(time) {
|
|||
|
||||
function buildHourlyTimeTitle(time){
|
||||
var hour=dateFns.getHours(time);
|
||||
|
||||
|
||||
if (hour===0) {
|
||||
return 'midnight';
|
||||
} else if (hour===12){
|
||||
return 'noon';
|
||||
}
|
||||
|
||||
|
||||
return dateFns.format(time,'h a');
|
||||
}
|
||||
|
||||
|
@ -249,7 +251,7 @@ function calcHourlyReport(data) {
|
|||
//firsthour = targets[ getNextHighestIndex(targets, current) ],
|
||||
start,
|
||||
hour, i=0;
|
||||
|
||||
|
||||
switch (true) {
|
||||
case (current < 3):
|
||||
start = 6;
|
||||
|
@ -263,20 +265,20 @@ function calcHourlyReport(data) {
|
|||
start = 20; break;
|
||||
case (current < 20):
|
||||
start = 0; break;
|
||||
default:
|
||||
start = 6;
|
||||
default:
|
||||
start = 6;
|
||||
}
|
||||
|
||||
|
||||
while(ret.length<4){
|
||||
|
||||
|
||||
// hour must be equal or greater than current
|
||||
hour = dateFns.getHours( data[i].startTime );
|
||||
if ( dateFns.isAfter(data[i].startTime, now) && (hour==start || ret.length>0) ) {
|
||||
|
||||
|
||||
if ( targets.indexOf(hour)>=0 ) { // it is in our target list so record its index
|
||||
ret.push(i);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -324,28 +326,28 @@ function mapNWSicons(url){
|
|||
fog:[15,15]
|
||||
},
|
||||
matches = url.match(/icons\/land\/(day|night)\/([a-z_]*)\/?([a-z_]*)/), // day or night followed by one or more condition codes
|
||||
idx = {day:0, night:1}[matches[1]],
|
||||
idx = {day:0, night:1}[matches[1]],
|
||||
ret=[], match;
|
||||
|
||||
|
||||
for (i=2; i<matches.length; i++){
|
||||
|
||||
|
||||
if (matches[i]) {
|
||||
match = map[ matches[i] ];
|
||||
|
||||
|
||||
ret.push( match[idx] );
|
||||
|
||||
// some icons are 2 layered
|
||||
// some icons are 2 layered
|
||||
if (match.length>2) {
|
||||
ret.push( match[2] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// place word icons last so they render on top
|
||||
if (ret.length>1 && [15,47,41,42, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 20, 31, 33, 34, 38, 39, 40, 44].indexOf( ret[1] )>-1) {
|
||||
ret.swap(0,1);
|
||||
}
|
||||
|
||||
|
||||
return ret.map(function(num){
|
||||
return 'images/icons/' + ('0'+num).slice(-2) + '.png';
|
||||
});
|
||||
|
@ -370,8 +372,8 @@ partly cloudy
|
|||
/*
|
||||
|
||||
https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.forecast where woeid=2402292
|
||||
|
||||
"units":{
|
||||
|
||||
"units":{
|
||||
"distance":"mi",
|
||||
"pressure":"in",
|
||||
"speed":"mph",
|
||||
|
@ -383,47 +385,47 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"language":"en-us",
|
||||
"lastBuildDate":"Thu, 12 Oct 2017 10:10 PM CDT",
|
||||
"ttl":"60",
|
||||
"location":{
|
||||
"location":{
|
||||
"city":"Fargo",
|
||||
"country":"United States",
|
||||
"region":" ND"
|
||||
},
|
||||
"wind":{
|
||||
"wind":{
|
||||
"chill":"52",
|
||||
"direction":"295",
|
||||
"speed":"18"
|
||||
},
|
||||
"atmosphere":{
|
||||
"atmosphere":{
|
||||
"humidity":"54",
|
||||
"pressure":"978.0",
|
||||
"rising":"0",
|
||||
"visibility":"16.1"
|
||||
},
|
||||
"astronomy":{
|
||||
"astronomy":{
|
||||
"sunrise":"7:41 am",
|
||||
"sunset":"6:46 pm"
|
||||
},
|
||||
"image":{
|
||||
"image":{
|
||||
"title":"Yahoo! Weather",
|
||||
"width":"142",
|
||||
"height":"18",
|
||||
"link":"http://weather.yahoo.com",
|
||||
"url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
|
||||
},
|
||||
"item":{
|
||||
"item":{
|
||||
"title":"Conditions for Fargo, ND, US at 09:00 PM CDT",
|
||||
"lat":"46.865089",
|
||||
"long":"-96.829224",
|
||||
"link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2402292/",
|
||||
"pubDate":"Thu, 12 Oct 2017 09:00 PM CDT",
|
||||
"condition":{
|
||||
"condition":{
|
||||
"code":"27",
|
||||
"date":"Thu, 12 Oct 2017 09:00 PM CDT",
|
||||
"temp":"55",
|
||||
"text":"Mostly Cloudy"
|
||||
},
|
||||
"forecast":[
|
||||
{
|
||||
"forecast":[
|
||||
{
|
||||
"code":"30",
|
||||
"date":"12 Oct 2017",
|
||||
"day":"Thu",
|
||||
|
@ -431,7 +433,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"48",
|
||||
"text":"Partly Cloudy"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"32",
|
||||
"date":"13 Oct 2017",
|
||||
"day":"Fri",
|
||||
|
@ -439,7 +441,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"37",
|
||||
"text":"Sunny"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"39",
|
||||
"date":"14 Oct 2017",
|
||||
"day":"Sat",
|
||||
|
@ -447,7 +449,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"38",
|
||||
"text":"Scattered Showers"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"34",
|
||||
"date":"15 Oct 2017",
|
||||
"day":"Sun",
|
||||
|
@ -455,7 +457,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"31",
|
||||
"text":"Mostly Sunny"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"34",
|
||||
"date":"16 Oct 2017",
|
||||
"day":"Mon",
|
||||
|
@ -463,7 +465,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"35",
|
||||
"text":"Mostly Sunny"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"34",
|
||||
"date":"17 Oct 2017",
|
||||
"day":"Tue",
|
||||
|
@ -471,7 +473,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"39",
|
||||
"text":"Mostly Sunny"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"30",
|
||||
"date":"18 Oct 2017",
|
||||
"day":"Wed",
|
||||
|
@ -479,7 +481,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"48",
|
||||
"text":"Partly Cloudy"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"30",
|
||||
"date":"19 Oct 2017",
|
||||
"day":"Thu",
|
||||
|
@ -487,7 +489,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"44",
|
||||
"text":"Partly Cloudy"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"30",
|
||||
"date":"20 Oct 2017",
|
||||
"day":"Fri",
|
||||
|
@ -495,7 +497,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
"low":"49",
|
||||
"text":"Partly Cloudy"
|
||||
},
|
||||
{
|
||||
{
|
||||
"code":"28",
|
||||
"date":"21 Oct 2017",
|
||||
"day":"Sat",
|
||||
|
@ -505,7 +507,7 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
}
|
||||
],
|
||||
"description":"<![CDATA[<img src=\"http://l.yimg.com/a/i/us/we/52/27.gif\"/>\n<BR />\n<b>Current Conditions:</b>\n<BR />Mostly Cloudy\n<BR />\n<BR />\n<b>Forecast:</b>\n<BR /> Thu - Partly Cloudy. High: 70Low: 48\n<BR /> Fri - Sunny. High: 58Low: 37\n<BR /> Sat - Scattered Showers. High: 49Low: 38\n<BR /> Sun - Mostly Sunny. High: 56Low: 31\n<BR /> Mon - Mostly Sunny. High: 65Low: 35\n<BR />\n<BR />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2402292/\">Full Forecast at Yahoo! Weather</a>\n<BR />\n<BR />\n<BR />\n]]>",
|
||||
"guid":{
|
||||
"guid":{
|
||||
"isPermaLink":"false"
|
||||
}
|
||||
|
||||
|
@ -513,8 +515,8 @@ https://query.yahooapis.com/v1/public/yql?format=json&q=select * from weather.fo
|
|||
|
||||
|
||||
Current Conditions:</b>\n<BR />Mostly Cloudy\n<BR />\n<BR />\n<b>
|
||||
Forecast:</b>\n<BR /> Thu - Partly Cloudy. High: 70Low: 48\n<BR /> Fri - Sunny. High: 58Low: 37\n<BR /> Sat - Scattered Showers. High: 49Low: 38\n<BR /> Sun - Mostly Sunny. High: 56Low: 31\n<BR />
|
||||
Forecast:</b>\n<BR /> Thu - Partly Cloudy. High: 70Low: 48\n<BR /> Fri - Sunny. High: 58Low: 37\n<BR /> Sat - Scattered Showers. High: 49Low: 38\n<BR /> Sun - Mostly Sunny. High: 56Low: 31\n<BR />
|
||||
Mon - Mostly Sunny. High: 65Low: 35\n<BR />\n<BR />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2402292/\">Full Forecast at Yahoo! Weather</a>\n<BR />\n<BR />\n<BR />\n]]>",
|
||||
"guid":{
|
||||
"guid":{
|
||||
|
||||
*/
|
||||
*/
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
|
||||
function Radar(divIDin, intervalHoursIn, zoomIn, latitudeIn, longitudeIn, withSat) {
|
||||
|
||||
|
||||
var map,
|
||||
divID = divIDin,
|
||||
intervalHours = intervalHoursIn,
|
||||
zoom = zoomIn,
|
||||
latitude = latitudeIn,
|
||||
longitude = longitudeIn;
|
||||
|
||||
|
||||
this.setView = function(lat, long, zoomLevel){
|
||||
map.setView(L.latLng(lat, long), zoomLevel)
|
||||
map.setView(L.latLng(lat, long), zoomLevel)
|
||||
};
|
||||
|
||||
|
||||
|
||||
startAnimation();
|
||||
setInterval(updatePeriod, 300000);
|
||||
|
||||
|
||||
function updatePeriod() {
|
||||
var endDate = roundDate(new Date()),
|
||||
startDate = dateFns.subHours(endDate, 3),
|
||||
newAvailableTimes = L.TimeDimension.Util.explodeTimeRange(startDate, endDate, 'PT5M');
|
||||
|
||||
newAvailableTimes = L.TimeDimension.Util.explodeTimeRange(startDate, endDate, 'PT5M');
|
||||
|
||||
map.timeDimension.setAvailableTimes(newAvailableTimes, 'replace');
|
||||
map.timeDimension.setCurrentTime(startDate);
|
||||
map.timeDimension.setCurrentTime(startDate);
|
||||
}
|
||||
|
||||
|
||||
// snap date to 5 minute intervals
|
||||
function roundDate(date) {
|
||||
date.setUTCMinutes( Math.round(date.getUTCMinutes() / 5) * 5);
|
||||
date.setUTCSeconds(0);
|
||||
return date;
|
||||
}
|
||||
|
||||
|
||||
function startAnimation () {
|
||||
|
||||
var endDate = roundDate(new Date()),
|
||||
player;
|
||||
|
||||
player;
|
||||
|
||||
map = L.map(divID, {
|
||||
zoom: zoom,
|
||||
fullscreenControl: false,
|
||||
timeDimension: true,
|
||||
timeDimensionControl: true,
|
||||
timeDimensionControl: true,
|
||||
timeDimensionOptions:{
|
||||
timeInterval: "PT" + intervalHours + "H/" + endDate.toISOString(),
|
||||
period: "PT5M",
|
||||
currentTime: endDate
|
||||
},
|
||||
},
|
||||
|
||||
timeDimensionControlOptions: {
|
||||
autoPlay: true,
|
||||
|
@ -59,23 +59,24 @@ function Radar(divIDin, intervalHoursIn, zoomIn, latitudeIn, longitudeIn, withSa
|
|||
},
|
||||
center: [latitude, longitude] // 31.205482,-82.4331197 test coordinates
|
||||
});
|
||||
map.timeDimensionControl._player.on('stop', function(){
|
||||
map.timeDimensionControl._player.on('stop', function(){
|
||||
setTimeout( function() {
|
||||
map.timeDimensionControl._player.setLooped(true);
|
||||
map.timeDimensionControl._player.start();
|
||||
setTimeout(function(){map.timeDimensionControl._player.setLooped(false)}, 1000);
|
||||
}, 1000)
|
||||
}, 1000)
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// basemap
|
||||
// streets cj9fqw1e88aag2rs2al6m3ko2
|
||||
// satellite streets cj8p1qym6976p2rqut8oo6vxr
|
||||
// weatherscan green cj8owq50n926g2smvagdxg9t8
|
||||
L.tileLayer('https://api.mapbox.com/styles/v1/swaldner/cj8p1qym6976p2rqut8oo6vxr/tiles/{z}/{x}/{y}?access_token=pk.eyJ1Ijoic3dhbGRuZXIiLCJhIjoiY2o4ZGpjcnVvMHBhazMzcDVnanZmd2lobCJ9.Kr5329g4YyZIlnYfHNXRWA', {
|
||||
// mapbox://styles/goldbblazez/ckgc7fwvr4qmn19pevtvhyabl
|
||||
L.tileLayer('https://api.mapbox.com/styles/v1/goldbblazez/ckgc8lzdz4lzh19qt7q9wbbr9/tiles/{z}/{x}/{y}?access_token=putapikeyhere', {
|
||||
tileSize: 512,
|
||||
zoomOffset: -1
|
||||
}).addTo(map);
|
||||
}).addTo(map);
|
||||
|
||||
|
||||
var radarWMS = L.nonTiledLayer.wms("https://nowcoast.noaa.gov/arcgis/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer/WMSServer", {
|
||||
|
@ -84,22 +85,22 @@ function Radar(divIDin, intervalHoursIn, zoomIn, latitudeIn, longitudeIn, withSa
|
|||
transparent: true,
|
||||
opacity: 0.8
|
||||
});
|
||||
|
||||
|
||||
if (withSat) {
|
||||
|
||||
|
||||
var goes_visible_sat = L.nonTiledLayer.wms('https://nowcoast.noaa.gov/arcgis/services/nowcoast/sat_meteo_imagery_time/MapServer/WMSServer', {
|
||||
layers: '9', // 9 for visible sat
|
||||
format: 'image/png',
|
||||
transparent: true,
|
||||
opacity:0.7,
|
||||
useCanvas:true
|
||||
}),
|
||||
}),
|
||||
satellitetimeLayer = L.timeDimension.layer.wms(goes_visible_sat, {
|
||||
proxy: proxy,
|
||||
updateTimeDimension: false,
|
||||
cache:1
|
||||
});
|
||||
|
||||
|
||||
satellitetimeLayer.addTo(map).on('timeload',function(t) {
|
||||
var canvas, ctx,
|
||||
imageData, data,
|
||||
|
@ -114,13 +115,13 @@ function Radar(divIDin, intervalHoursIn, zoomIn, latitudeIn, longitudeIn, withSa
|
|||
|
||||
ctx = canvas.getContext('2d');
|
||||
|
||||
imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
|
||||
imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
|
||||
var pixels = imageData.data,
|
||||
brighten = 0,
|
||||
contrast = 10;
|
||||
for(var i = 0; i < pixels.length; i+=4){//loop through all data
|
||||
|
||||
|
||||
pixels[i] += brighten;
|
||||
pixels[i+1] += brighten;
|
||||
pixels[i+2] += brighten;
|
||||
|
@ -133,9 +134,9 @@ function Radar(divIDin, intervalHoursIn, zoomIn, latitudeIn, longitudeIn, withSa
|
|||
|
||||
var rgb = pixels[i] + pixels[i+1] + pixels[i+2];
|
||||
pixels[i] = pixels[i+1] = pixels[i+2] = 255;
|
||||
pixels[i+3] = rgb / 3;
|
||||
pixels[i+3] = rgb / 3;
|
||||
}
|
||||
imageData.data = pixels;
|
||||
imageData.data = pixels;
|
||||
|
||||
// overwrite original image
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
|
@ -144,18 +145,18 @@ function Radar(divIDin, intervalHoursIn, zoomIn, latitudeIn, longitudeIn, withSa
|
|||
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
var proxy = 'js/leaflet/proxy.php';
|
||||
var radarTimeLayer = L.timeDimension.layer.wms(radarWMS, {
|
||||
proxy: proxy,
|
||||
updateTimeDimension: false
|
||||
});
|
||||
|
||||
|
||||
radarTimeLayer.addTo(map);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +165,7 @@ function Radar(divIDin, intervalHoursIn, zoomIn, latitudeIn, longitudeIn, withSa
|
|||
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* Workaround for 1px lines appearing in some browsers due to fractional transforms
|
||||
* and resulting anti-aliasing.
|
||||
* https://github.com/Leaflet/Leaflet/issues/3575
|
||||
|
@ -184,5 +185,3 @@ function Radar(divIDin, intervalHoursIn, zoomIn, latitudeIn, longitudeIn, withSa
|
|||
}
|
||||
});
|
||||
})()
|
||||
|
||||
|
||||
|
|
|
@ -10,62 +10,62 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
function Slides(dataMan) {
|
||||
var radarSlideDuration = 60000,
|
||||
slideDelay = 10000;
|
||||
|
||||
buildHeader();
|
||||
|
||||
|
||||
buildHeader();
|
||||
|
||||
setTimeout(nextCity, 5000);
|
||||
|
||||
|
||||
|
||||
|
||||
// loop cities
|
||||
function nextCity(){
|
||||
|
||||
|
||||
advanceHeader();
|
||||
|
||||
|
||||
var city = $('#info-slides-header .city.current');
|
||||
|
||||
|
||||
// is radar or city?
|
||||
if (city[0].dataset.woeid) {
|
||||
// show slide deck for the current city
|
||||
// show slide deck for the current city
|
||||
showCitySlides( dataMan.location(city[0].dataset.woeid), 0 );
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
|
||||
|
||||
// radar
|
||||
showRadar(dataMan.locations[0].lat, dataMan.locations[0].long, 8);
|
||||
|
||||
|
||||
//setTimeout(function() { weatherAudio.playLocalRadar() }, 2000 );
|
||||
|
||||
|
||||
// show for how long?
|
||||
setTimeout(nextCity, 60000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function showRadar(lat, long, zoom) {
|
||||
|
||||
weatherMan.mainMap.setView(lat, long, zoom);
|
||||
|
||||
|
||||
weatherMan.mainMap.setView(lat, long, zoom);
|
||||
|
||||
setTimeout(function() {
|
||||
|
||||
|
||||
// fade out info, fade in radar
|
||||
$('.info-slide-content:visible').fadeOut(250, function(){
|
||||
$('.info-slide').fadeOut(250, function() {
|
||||
$('.radar-slide').fadeIn(500);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}, 1500); // give it time to load
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// show the set of slides for one city
|
||||
|
||||
|
||||
// show the set of slides for one city
|
||||
function showCitySlides(location, idx) {
|
||||
|
||||
|
||||
var currentDisplay,
|
||||
displays = {
|
||||
|
||||
|
@ -73,35 +73,34 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
currentConditions() {
|
||||
$('.city-info-slide #subhead-title').text('Currently');
|
||||
$('.city-info-slide #subhead-city').text(location.city);
|
||||
|
||||
var obsData = location.observations,
|
||||
strLabels = 'Humidity<br>Dew Point<br>Pressure<Br>Wind<br>Gusts<br>',
|
||||
var obsData = location.observations,
|
||||
strLabels = 'Humidity<br>Dew Point<br>Pressure<Br>Wind<br>',
|
||||
strData =
|
||||
obsData(0).atmosphere.humidity + '%<br>'+
|
||||
dewPoint(obsData(0).item.condition.temp, obsData(0).atmosphere.humidity ) + '<br>' +
|
||||
(obsData(0).atmosphere.pressure*0.0295301).toFixed(2) + ' ' + ['S','R','F'][obsData(0).atmosphere.rising] + '<br>' +
|
||||
degToCompass(obsData(0).wind.direction) + ' ' +
|
||||
obsData(0).wind.speed + '<br>' +
|
||||
(obsData(1).windGust.value!=null ? mps2mph( obsData(1).windGust.value ) : 'none') +
|
||||
'<br>' // gusts show mph
|
||||
;
|
||||
|
||||
if (parseInt(obsData(0).wind.chill) < parseInt(obsData(0).item.condition.temp)) {
|
||||
obsData(0).current.humidity + '%<br>' + dewPoint(parseInt(obsData(0).current.temp), parseInt(obsData(0).current.humidity)) + '<br>' + (obsData(0).current.pressure*0.0295301).toFixed(2) + '<br>' + degToCompass(obsData(0).current.wind_deg) + ' ' + obsData(0).current.wind_speed + '<br>';
|
||||
if (obsData(0).current.wind_gust!=undefined) {
|
||||
strLabels+='Gusts<Br>';
|
||||
strData+=obsData(0).current.wind_gust + '<br>';
|
||||
} else {
|
||||
strLabels+='Gusts<Br>';
|
||||
strData+='none<br>';
|
||||
}
|
||||
var windchill = 35.74 + (0.6215 * parseInt(obsData(0).current.temp)) + (0.4275 * parseInt(obsData(0).current.temp) - 35.75) * parseInt(obsData(0).current.wind_speed) ^ 0.16;
|
||||
if (windchill < parseInt(obsData(0).current.temp)) {
|
||||
strLabels+='Wind Chill';
|
||||
strData+= obsData(0).wind.chill + '°';
|
||||
} else if (parseInt(obsData(0).item.condition.temp)>=80 && parseInt(obsData(0).atmosphere.humidity)>=40 ){
|
||||
strData+= windchill;
|
||||
} else if (parseInt(obsData(0).current.temp)>=80 && parseInt(obsData(0).current.humidity)>=40 ){
|
||||
strLabels+='Heat Index';
|
||||
return 'heat index ' + heatIndex(obsData(0).item.condition.temp, obsData(0).atmosphere.humidity) + '°';
|
||||
return 'heat index ' + heatIndex(obsData(0).current.temp, obsData(0).current.humidity) + '°';
|
||||
}
|
||||
|
||||
$('.city-info .frost-pane .labels').html(strLabels);
|
||||
$('.city-info .frost-pane .data').html(strData);
|
||||
|
||||
// right pane
|
||||
$('.city-info .icon').css('background-image', 'url("' + getCCicon(obsData(0).item.condition.code) + '")');
|
||||
$('.city-info .conditions').text( obsData(0).item.condition.text );
|
||||
$('.city-info .temp').text( obsData(0).item.condition.temp );
|
||||
|
||||
$('.city-info .icon').css('background-image', 'url("' + getCCicon(+obsData(0).current.weather[0].id + obsData(0).current.weather[0].icon) + '")');
|
||||
$('.city-info .conditions').text( obsData(0).current.weather[0].description);
|
||||
$('.city-info .temp').text( Math.round(parseInt(obsData(0).current.temp)) );
|
||||
|
||||
fadeToContent('.city-info');
|
||||
wait(slideDelay);
|
||||
|
||||
|
@ -117,9 +116,9 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
// Local Forecast -Today (10 sec)
|
||||
,forecast(fidx) {
|
||||
var div = '.info-slide-content.forecast ',
|
||||
forecasts = location.forecasts('daily');
|
||||
|
||||
function fillinfo() {
|
||||
forecasts = location.forecasts('daily');
|
||||
|
||||
function fillinfo() {
|
||||
|
||||
fidx = (fidx===undefined ? 0 : fidx);
|
||||
|
||||
|
@ -131,9 +130,9 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
// content
|
||||
resizeText( forecasts[fidx].detailedForecast );
|
||||
$(div + '.content').text( forecasts[fidx].detailedForecast );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
fadeToContent(div, fillinfo);
|
||||
|
||||
setTimeout( function() {
|
||||
|
@ -141,46 +140,46 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
if (fidx<3) {
|
||||
currentDisplay(++fidx);
|
||||
} else {
|
||||
wait(0);
|
||||
wait(0);
|
||||
}
|
||||
|
||||
}, slideDelay);
|
||||
|
||||
}, slideDelay);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Extended Forecast(5 day columns)
|
||||
//,extendedForecast() {},
|
||||
|
||||
|
||||
},
|
||||
keys = Object.keys(displays);
|
||||
|
||||
|
||||
|
||||
|
||||
if (idx<keys.length) {
|
||||
currentDisplay = displays[keys[idx]];
|
||||
currentDisplay();
|
||||
currentDisplay();
|
||||
} else { // done - exit
|
||||
nextCity();
|
||||
nextCity();
|
||||
}
|
||||
return;
|
||||
|
||||
|
||||
function wait(duration){
|
||||
setTimeout(function() {
|
||||
showCitySlides(location, ++idx);
|
||||
}, duration);
|
||||
setTimeout(function() {
|
||||
showCitySlides(location, ++idx);
|
||||
}, duration);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function resizeText(text){
|
||||
var s = 50,
|
||||
$container = $('.info-slide-content.forecast .content'),
|
||||
$test = $('<div style="position:absolute;top:100%;"></div>') .appendTo($container) .css('font-size', s + 'px') .html(text);
|
||||
|
||||
|
||||
// have to display parent so we can get measurements
|
||||
$container.closest('.info-slide-content').show();
|
||||
|
||||
|
||||
$test.width($container.width() );
|
||||
while ($test.outerHeight(true) >= ($container.height()) ) {
|
||||
s -= 1;
|
||||
|
@ -190,13 +189,13 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
$container .text(text) .css('font-size', s + 'px');
|
||||
$test.remove();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function fadeToContent(to, callfirst) {
|
||||
var $to = $(to),
|
||||
$parent = $to.closest('.info-slide');
|
||||
|
||||
|
||||
if ( $parent.is(":hidden") ) {
|
||||
// hide other visible slide then show the parent
|
||||
$to.hide();
|
||||
|
@ -207,34 +206,34 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
} else {
|
||||
hideOldShowMe();
|
||||
}
|
||||
|
||||
function hideOldShowMe() {
|
||||
|
||||
function hideOldShowMe() {
|
||||
if ($('.info-slide-content:visible')) {
|
||||
$('.info-slide-content:visible').fadeOut(500, showMe);
|
||||
} else {
|
||||
showMe();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function showMe() {
|
||||
if (callfirst) { callfirst() };
|
||||
$to.fadeIn(500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//doDisplay = displays[ keys[idx] ]();
|
||||
|
||||
// increment the pointer
|
||||
//idx = (++idx===keys.length ? 0 : idx);
|
||||
|
||||
//if (text) {
|
||||
//if (text) {
|
||||
// $('#current-info').html(text);
|
||||
// setTimeout(function(){ displayAtmospheric(idx) }, 6000); // 6 second increment loop
|
||||
//} else {
|
||||
// nothing to display - skip to the next one
|
||||
// setTimeout(function(){ displayAtmospheric(idx) }, 0);
|
||||
//}
|
||||
// setTimeout(function(){ displayAtmospheric(idx) }, 0);
|
||||
//}
|
||||
|
||||
/*
|
||||
(Main City)
|
||||
|
@ -257,29 +256,29 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
Extended Forecast(5 day columns)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
//idx++;
|
||||
//if (idx<=0){
|
||||
setTimeout(cityLoop, 3000); // change to 60000 for production
|
||||
setTimeout(cityLoop, 3000); // change to 60000 for production
|
||||
//} else {
|
||||
|
||||
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function advanceHeader() {
|
||||
|
||||
|
||||
// swap current
|
||||
var $cities = $('#info-slides-header .city'),
|
||||
$scroller = $('#info-slides-header .hscroller'),
|
||||
left;
|
||||
|
||||
|
||||
$($cities[0]).removeClass('current');
|
||||
$($cities[1]).addClass('current');
|
||||
|
||||
|
||||
// animate move left
|
||||
left = $scroller.position().left - $($cities[1]).position().left;
|
||||
$scroller.animate({ 'left': left+'px' }, 700,
|
||||
|
@ -287,12 +286,12 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
// on completion, move the old one to the end
|
||||
$scroller.css('left','');
|
||||
$($cities[0]).appendTo($scroller);
|
||||
$('#info-slides-header span').first().appendTo($scroller);
|
||||
$('#info-slides-header span').first().appendTo($scroller);
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function buildHeader(){
|
||||
var city, first, woeid,
|
||||
cities='',
|
||||
|
@ -301,16 +300,13 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
|
|||
|
||||
for (var location of dataMan.locations) {
|
||||
city = location.city;
|
||||
cities += arrow+'<span class="city" data-woeid="' + location.woeid + '">' + city + '</span>';
|
||||
cities += arrow+'<span class="city" data-woeid="' + location.woeid + '">' + city + '</span>';
|
||||
}
|
||||
|
||||
$('#info-slides-header .hscroller').append(cities + arrow + (radar + cities + arrow).repeat(4));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // end function
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ function shuffle (array) {
|
|||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ function getRandom(min, max) {
|
|||
function getNextHighestIndex(arr, value) {
|
||||
var i = arr.length;
|
||||
while (arr[--i] > value);
|
||||
return ++i;
|
||||
return ++i;
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ function getUrlParameter(e) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// convert celsius to farenheight
|
||||
function C2F(c){
|
||||
return Math.round( c * 9 / 5 + 32 );
|
||||
|
@ -42,18 +42,18 @@ function C2F(c){
|
|||
function mps2mph(meters) {
|
||||
return Math.round( parseFloat(meters) * 2.23694 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// array swap
|
||||
Array.prototype.swap = function(a,b){ var tmp=this[a];this[a]=this[b];this[b]=tmp;};
|
||||
|
||||
|
||||
|
||||
function degToCompass(deg){
|
||||
val = Math.round((deg/22.5)+.5);
|
||||
arr=["N","NE","E","SE","S","SW","W","NW"];
|
||||
return arr[(val % 8)];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function distance(lat1, lon1, lat2, lon2) {
|
||||
|
@ -75,7 +75,7 @@ function dewPoint(tem, r){
|
|||
ed = r/100.0*es;
|
||||
eln = Math.log(ed/6.112);
|
||||
td = -243.5*eln/(eln - 17.67 );
|
||||
return Math.round( (td*9/5)+32 );
|
||||
return Math.round( (td*9/5)+32 );
|
||||
}
|
||||
|
||||
function heatIndex(T, R) { // T = temp, R = relative humidity
|
||||
|
@ -83,18 +83,129 @@ function heatIndex(T, R) { // T = temp, R = relative humidity
|
|||
c1 = -42.379, c2 = 2.04901523, c3 = 10.14333127,
|
||||
c4 = -0.22475541, c5 = -6.83783*Math.pow(10,-3), c6 = -5.481717*Math.pow(10,-2),
|
||||
c7 = 1.22874*Math.pow(10,-3), c8 = 8.5282*Math.pow(10,-4), c9 = -1.99*Math.pow(10,-6);
|
||||
|
||||
|
||||
return Math.round(c1 + c2*T + c3 *R + c4*T*R + c5*T2 + c6*R2 + c7*T2*R + c8*T*R2 + c9*T2*R2);
|
||||
}
|
||||
|
||||
|
||||
// maps current condition code to icon
|
||||
function getCCicon(ccCode){
|
||||
return "images/icons/" + ( "0" + {0:1,1:1,2:1,3:1,4:1,5:2,6:38,7:3,8:4,9:5,10:6,11:7,12:7,13:9,14:10,15:39,16:12,17:13,18:13,19:17,20:15,21:16,22:14,23:18,24:18,25:42,26:20,27:21,28:22,29:23,30:24,31:25,32:26,33:27,34:28,35:38,36:41,37:31,38:31,39:31,40:30,41:12,42:9,43:12,44:24,45:1,46:10,47:1,3200:19}[ccCode]
|
||||
).slice(-2) + ".png";
|
||||
return "images/icons/" + ( "0" + {"20011d":1,"20011n":1,"20111d":1,"20111n":1,"20211d":1,"20211n":1,"21011d":1,"21011n":1,"21111d":1,"21111n":1,"21211d":1,"21211n":1,"22111d":1,"22111n":1,"23011d":1,"23011n":1,"23111d":1,"23111n":1,"23211d":1,"23211n":1,"30009d":5,"30009n":5,"30109d":5,"30109n":5,"30209d":5,"30209n":5,"31009d":5,"31009n":5,"31109d":5,"31109n":5,"31209d":5,"31209n":5,"31309d":5,"31309n":5,"31409d":5,"31409n":5,"32109d":5,"32109n":5,"50010d":7,"50010n":7,"50110d":8,"50110n":8,"50210d":31,"50210n":31,"50310d":31,"50310n":31,"50410d":31,"50410d":31,"51110d":6,"51110n":6,"52010d":7,"52010n":7,"52110d":8,"52110n":8,"52210d":31,"52210n":31,"53110d":29,"53110n":37,"60013d":10,"60013n":10,"60113d":12,"60113n":12,"60213d":33,"60213n":33,"61113d":13,"61113n":13,"61213d":13,"61213n":13,"61313d":13,"61313n":13,"61513d":2,"61513n":2,"61613d":2,"61613n":2,"62013d":10,"62013n":10,"62113d":12,"62113n":12,"62213d":33,"62213n":33,"70150d":15,"70150n":15,"71150d":14,"71150n":14,"72150d":16,"72150n":16,"73150d":16,"73150n":16,"74150d":15,"74150n":15,"75150d":16,"75150n":16,"76150d":14,"76150n":14,"76250d":14,"76250n":14,"77150d":18,"77150n":18,"78150d":1,"78150n":1,"80001d":26,"80001n":25,"80102d":28,"80102n":27,"80203d":22,"80203n":21,"80304d":24,"80304n":23,"80405d":20,"80405n":20}[ccCode]).slice(-2) + ".png";
|
||||
}
|
||||
function getCCtext(ccCode) {
|
||||
return {
|
||||
"20011d": "Thunderstorm",
|
||||
"20011n": 1,
|
||||
"20111d": 1,
|
||||
"20111n": 1,
|
||||
"20211d": 1,
|
||||
"20211n": 1,
|
||||
"21011d": 1,
|
||||
"21011n": 1,
|
||||
"21111d": 1,
|
||||
"21111n": 1,
|
||||
"21211d": 1,
|
||||
"21211n": 1,
|
||||
"22111d": 1,
|
||||
"22111n": 1,
|
||||
"23011d": 1,
|
||||
"23011n": 1,
|
||||
"23111d": 1,
|
||||
"23111n": 1,
|
||||
"23211d": 1,
|
||||
"23211n": 1,
|
||||
"30009d": 5,
|
||||
"30009n": 5,
|
||||
"30109d": 5,
|
||||
"30109n": 5,
|
||||
"30209d": 5,
|
||||
"30209n": 5,
|
||||
"31009d": 5,
|
||||
"31009n": 5,
|
||||
"31109d": 5,
|
||||
"31109n": 5,
|
||||
"31209d": 5,
|
||||
"31209n": 5,
|
||||
"31309d": 5,
|
||||
"31309n": 5,
|
||||
"31409d": 5,
|
||||
"31409n": 5,
|
||||
"32109d": 5,
|
||||
"32109n": 5,
|
||||
"50010d": 7,
|
||||
"50010n": 7,
|
||||
"50110d": 8,
|
||||
"50110n": 8,
|
||||
"50210d": 31,
|
||||
"50210n": 31,
|
||||
"50310d": 31,
|
||||
"50310n": 31,
|
||||
"50410d": 31,
|
||||
"50410d": 31,
|
||||
"51110d": 6,
|
||||
"51110n": 6,
|
||||
"52010d": 7,
|
||||
"52010n": 7,
|
||||
"52110d": 8,
|
||||
"52110n": 8,
|
||||
"52210d": 31,
|
||||
"52210n": 31,
|
||||
"53110d": 29,
|
||||
"53110n": 37,
|
||||
"60013d": 10,
|
||||
"60013n": 10,
|
||||
"60113d": 12,
|
||||
"60113n": 12,
|
||||
"60213d": 33,
|
||||
"60213n": 33,
|
||||
"61113d": 13,
|
||||
"61113n": 13,
|
||||
"61213d": 13,
|
||||
"61213n": 13,
|
||||
"61313d": 13,
|
||||
"61313n": 13,
|
||||
"61513d": 2,
|
||||
"61513n": 2,
|
||||
"61613d": 2,
|
||||
"61613n": 2,
|
||||
"62013d": 10,
|
||||
"62013n": 10,
|
||||
"62113d": 12,
|
||||
"62113n": 12,
|
||||
"62213d": 33,
|
||||
"62213n": 33,
|
||||
"70150d": 15,
|
||||
"70150n": 15,
|
||||
"71150d": 14,
|
||||
"71150n": 14,
|
||||
"72150d": 16,
|
||||
"72150n": 16,
|
||||
"73150d": 16,
|
||||
"73150n": 16,
|
||||
"74150d": 15,
|
||||
"74150n": 15,
|
||||
"75150d": 16,
|
||||
"75150n": 16,
|
||||
"76150d": 14,
|
||||
"76150n": 14,
|
||||
"76250d": 14,
|
||||
"76250n": 14,
|
||||
"77150d": 18,
|
||||
"77150n": 18,
|
||||
"78150d": 1,
|
||||
"78150n": 1,
|
||||
"80001d": 26,
|
||||
"80001n": 25,
|
||||
"80102d": 28,
|
||||
"80102n": 27,
|
||||
"80203d": 22,
|
||||
"80203n": 21,
|
||||
"80304d": 24,
|
||||
"80304n": 23,
|
||||
"80405d": 20,
|
||||
"80405n": 20
|
||||
}[ccCode]).slice(-2) + ".png";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// https://date-fns.org/docs/Getting-Started
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
|
||||
function WeatherManager() {
|
||||
|
||||
|
||||
var mainloc
|
||||
var mainMap, miniMap, slides,
|
||||
dataMan, loops, // weatherAudio,
|
||||
that = this;
|
||||
|
||||
$(function(){
|
||||
|
||||
|
||||
$(function(){
|
||||
|
||||
// init marquees
|
||||
function refreshMarquee () {
|
||||
|
||||
|
@ -15,31 +15,31 @@ function WeatherManager() {
|
|||
.marquee('destroy')
|
||||
.marquee({speed: 200, pauseOnHover:true, delayBeforeStart:3000})
|
||||
.on('finished', refreshMarquee);
|
||||
}
|
||||
}
|
||||
refreshMarquee();
|
||||
|
||||
|
||||
|
||||
|
||||
$('#marquee2').marquee({
|
||||
speed: 170, pauseOnHover: true
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
weatherAudio.playCallback = function(tags) {
|
||||
$('.track-info').text('playing "' + tags.title + '" by ' + tags.artist);
|
||||
}
|
||||
|
||||
|
||||
// this little guy runs the date and time
|
||||
setInterval(
|
||||
function () {
|
||||
setInterval(
|
||||
function () {
|
||||
var today = new Date();
|
||||
|
||||
$('#date').text( today.toString().slice(4,10).trimRight() );
|
||||
$('#date').text( today.toString().slice(4,10).trimRight() );
|
||||
$('#time').text( today.toLocaleTimeString('en-US', { hour: 'numeric', hour12: true, minute: 'numeric', second: 'numeric' }).replace(/ /g,'') );
|
||||
}
|
||||
, 1000);
|
||||
|
||||
|
||||
initDataPull();
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
@ -48,62 +48,62 @@ function WeatherManager() {
|
|||
// get the main location data
|
||||
// on initialization ready, init local forecast loop
|
||||
// on return of fully ready, begin display loops
|
||||
|
||||
|
||||
// check the url for a specific location
|
||||
var queryString = window.location.search;
|
||||
|
||||
|
||||
if (queryString) {
|
||||
dataMan = createDataManager( queryString.split("?")[1] );
|
||||
} else {
|
||||
|
||||
|
||||
// get lat lon from user's ip
|
||||
$.getJSON("http://ip-api.com/json/?callback=?", function(data) {
|
||||
$.getJSON("http://ip-api.com/json/?callback=?", function(data) {
|
||||
dataMan = createDataManager( data.lat+','+data.lon );
|
||||
mainloc = data.city
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function initDisplayLoops(){
|
||||
loops = new Loops(dataMan.locations[0]);
|
||||
loops = new Loops(dataMan.locations[0]);
|
||||
}
|
||||
function initSlidesLoop() {
|
||||
slides = new Slides(dataMan);
|
||||
slides = new Slides(dataMan);
|
||||
}
|
||||
function createDataManager(searchString) {
|
||||
var dataManager = new DataManager();
|
||||
|
||||
|
||||
$(dataManager)
|
||||
.on('refresh', refreshObservationDisplay)
|
||||
.on('ready:main', initDisplayLoops)
|
||||
.on('allinit', initSlidesLoop);
|
||||
|
||||
|
||||
dataManager.init(searchString);
|
||||
|
||||
|
||||
return dataManager;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function refreshObservationDisplay() {
|
||||
var data = dataMan.locations[0].observations(0),
|
||||
cond = data.item.condition,
|
||||
loc = data.location;
|
||||
|
||||
cond = data.current.weather[0];
|
||||
|
||||
if (mainMap===undefined) {
|
||||
mainMap = that.mainMap = new Radar("radar-1", 3, 8, data.item.lat, data.item.long, false);
|
||||
miniMap = new Radar("minimap", 3, 5, data.item.lat, data.item.long);
|
||||
}
|
||||
|
||||
$('#city').text(loc.city);
|
||||
$('#forecast-city').text(loc.city + ':');
|
||||
mainMap = that.mainMap = new Radar("radar-1", 3, 8, data.lat, data.lon, false);
|
||||
miniMap = new Radar("minimap", 3, 5, data.lat, data.lon);
|
||||
}
|
||||
|
||||
$('#city').text(mainloc);
|
||||
$('#forecast-city').text(mainloc + ':');
|
||||
$('#current-temp').text( dataMan.locations[0].temperature() ) ;
|
||||
$('#conditions-icon').css('background-image', 'url("' + getCCicon(cond.code) + '")');
|
||||
|
||||
$('#conditions-icon').css('background-image', 'url("' + getCCicon(cond.id + cond.icon) + '")');
|
||||
|
||||
//weatherAudio.playCurrentConditions(cond);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
var weatherMan = new WeatherManager();
|
||||
var weatherMan = new WeatherManager();
|
||||
|
|
Loading…
Reference in New Issue