mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 15:49:31 -07:00
add hourly forecast
This commit is contained in:
@@ -318,4 +318,9 @@ class Almanac extends WeatherDisplay {
|
||||
|
||||
this.finishDraw();
|
||||
}
|
||||
|
||||
// make sun and moon data available outside this class
|
||||
getSun() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
@@ -251,8 +251,39 @@ const icons = (() => {
|
||||
}
|
||||
};
|
||||
|
||||
const getHourlyIcon = (skyCover, visibility, iceAccumulation, probabilityOfPrecipitation, snowfallAmount, windSpeed, isNight = false) => {
|
||||
// internal function to add path to returned icon
|
||||
const addPath = (icon) => `images/r/${icon}`;
|
||||
|
||||
// first item in list is highest priority, units are metric where applicable
|
||||
if (iceAccumulation > 0) return addPath('Freezing-Rain-1992.gif');
|
||||
if (snowfallAmount > 10) {
|
||||
if (windSpeed > 30) return addPath('Blowing Snow.gif');
|
||||
return addPath('Heavy-Snow-1994.gif');
|
||||
}
|
||||
if (snowfallAmount > 0) return addPath('Light-Snow.gif');
|
||||
if (probabilityOfPrecipitation > 70) return addPath('Rain-1992.gif');
|
||||
if (probabilityOfPrecipitation > 50) return addPath('Shower.gif');
|
||||
if (probabilityOfPrecipitation > 30) {
|
||||
if (!isNight) return addPath('Scattered-Showers-1994.gif');
|
||||
return addPath('Scattered-Showers-Night.gif');
|
||||
}
|
||||
if (skyCover > 70) return addPath('Cloudy.gif');
|
||||
if (skyCover > 50) {
|
||||
if (!isNight) return addPath('Mostly-Cloudy-1994.gif');
|
||||
return addPath('Partly-Clear-1994.gif');
|
||||
}
|
||||
if (skyCover > 30) {
|
||||
if (!isNight) return addPath('Partly-Cloudy.gif');
|
||||
return addPath('Mostly-Clear.gif');
|
||||
}
|
||||
if (isNight) return addPath('Clear-1992.gif');
|
||||
return addPath('Sunny.gif');
|
||||
};
|
||||
|
||||
return {
|
||||
getWeatherIconFromIconLink,
|
||||
getWeatherRegionalIconFromIconLink,
|
||||
getHourlyIcon,
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
// navigation handles progress, next/previous and initial load messages from the parent frame
|
||||
/* globals index, utils, _StationInfo, STATUS */
|
||||
/* globals CurrentWeather, LatestObservations, TravelForecast, RegionalForecast, LocalForecast, ExtendedForecast, Almanac, Radar, Progress, currentWeatherScroll */
|
||||
/* globals CurrentWeather, LatestObservations, TravelForecast, RegionalForecast, LocalForecast, ExtendedForecast, Almanac, Radar, Progress, Hourly */
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
navigation.init();
|
||||
@@ -19,8 +19,9 @@ const navigation = (() => {
|
||||
let playing = false;
|
||||
let progress;
|
||||
|
||||
// current conditions are made available from the display below
|
||||
// current conditions and sunrise/sunset are made available from the display below
|
||||
let currentWeather;
|
||||
let almanac;
|
||||
|
||||
const init = async () => {
|
||||
// nothing to do
|
||||
@@ -79,6 +80,7 @@ const navigation = (() => {
|
||||
weatherParameters.state = point.properties.relativeLocation.properties.state;
|
||||
weatherParameters.timeZone = point.properties.relativeLocation.properties.timeZone;
|
||||
weatherParameters.forecast = point.properties.forecast;
|
||||
weatherParameters.forecastGridData = point.properties.forecastGridData;
|
||||
weatherParameters.stations = stations.features;
|
||||
|
||||
// update the main process for display purposes
|
||||
@@ -94,25 +96,22 @@ const navigation = (() => {
|
||||
// start loading canvases if necessary
|
||||
if (displays.length === 0) {
|
||||
currentWeather = new CurrentWeather(0,'currentWeather');
|
||||
almanac = new Almanac(7, 'almanac');
|
||||
displays = [
|
||||
currentWeather,
|
||||
new LatestObservations(1, 'latestObservations'),
|
||||
new TravelForecast(2, 'travelForecast', false), // not active by default
|
||||
new RegionalForecast(3, 'regionalForecast'),
|
||||
new LocalForecast(4, 'localForecast'),
|
||||
new ExtendedForecast(5, 'extendedForecast'),
|
||||
new Almanac(6, 'almanac'),
|
||||
new Radar(7, 'radar'),
|
||||
new Hourly(2, 'hourly'),
|
||||
new TravelForecast(3, 'travelForecast', false), // not active by default
|
||||
new RegionalForecast(4, 'regionalForecast'),
|
||||
new LocalForecast(5, 'localForecast'),
|
||||
new ExtendedForecast(6, 'extendedForecast'),
|
||||
almanac,
|
||||
new Radar(8, 'radar'),
|
||||
];
|
||||
}
|
||||
// call for new data on each display
|
||||
displays.forEach(display => display.getData(weatherParameters));
|
||||
|
||||
// GetMonthPrecipitation(this.weatherParameters);
|
||||
// GetAirQuality3(this.weatherParameters);
|
||||
// ShowDopplerMap(this.weatherParameters);
|
||||
// GetWeatherHazards3(this.weatherParameters);
|
||||
|
||||
};
|
||||
|
||||
// receive a status update from a module {id, value}
|
||||
@@ -262,6 +261,12 @@ const navigation = (() => {
|
||||
return currentWeather.getCurrentWeather();
|
||||
};
|
||||
|
||||
// get sunrise/sunset
|
||||
const getSun = () => {
|
||||
if (!almanac) return false;
|
||||
return almanac.getSun();
|
||||
};
|
||||
|
||||
return {
|
||||
init,
|
||||
message,
|
||||
@@ -272,5 +277,6 @@ const navigation = (() => {
|
||||
msg,
|
||||
getDisplay,
|
||||
getCurrentWeather,
|
||||
getSun,
|
||||
};
|
||||
})();
|
||||
@@ -77,6 +77,12 @@ class TravelForecast extends WeatherDisplay {
|
||||
this.longContext = this.longCanvas.getContext('2d');
|
||||
this.longCanvasGifs = [];
|
||||
}
|
||||
|
||||
// stop all gifs
|
||||
this.longCanvasGifs.forEach(gif => gif.pause());
|
||||
// delete the gifs
|
||||
this.longCanvasGifs.length = 0;
|
||||
|
||||
// set up variables
|
||||
const cities = this.data;
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ class WeatherDisplay {
|
||||
// if (_ScrollText !== '') OkToDrawCustomScrollText = true;
|
||||
if (this.elemId === 'almanac') OkToDrawNoaaImage = false;
|
||||
if (this.elemId === 'travelForecast') OkToDrawNoaaImage = false;
|
||||
if (this.elemId === 'hourly') OkToDrawNoaaImage = false;
|
||||
if (this.elemId === 'regionalForecast') OkToDrawNoaaImage = false;
|
||||
if (this.elemId === 'progress') {
|
||||
OkToDrawCurrentConditions = false;
|
||||
|
||||
Reference in New Issue
Block a user