mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 19:49:31 -07:00
extended forecast silent refresh
This commit is contained in:
@@ -21,12 +21,11 @@ class Almanac extends WeatherDisplay {
|
|||||||
this.timing.totalScreens = 1;
|
this.timing.totalScreens = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getData(_weatherParameters, refresh) {
|
async getData(weatherParameters, refresh) {
|
||||||
const superResponse = super.getData(_weatherParameters, refresh);
|
const superResponse = super.getData(weatherParameters, refresh);
|
||||||
const weatherParameters = _weatherParameters ?? this.weatherParameters;
|
|
||||||
|
|
||||||
// get sun/moon data
|
// get sun/moon data
|
||||||
const { sun, moon } = this.calcSunMoonData(weatherParameters);
|
const { sun, moon } = this.calcSunMoonData(this.weatherParameters);
|
||||||
|
|
||||||
// store the data
|
// store the data
|
||||||
this.data = {
|
this.data = {
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class CurrentWeather extends WeatherDisplay {
|
|||||||
async getData(weatherParameters, refresh) {
|
async getData(weatherParameters, refresh) {
|
||||||
// always load the data for use in the lower scroll
|
// always load the data for use in the lower scroll
|
||||||
const superResult = super.getData(weatherParameters, refresh);
|
const superResult = super.getData(weatherParameters, refresh);
|
||||||
|
// note: current weather does not use old data on a silent refresh
|
||||||
|
// this is deliberate because it can pull data from more than one station in sequence
|
||||||
|
|
||||||
// filter for 4-letter observation stations, only those contain sky conditions and thus an icon
|
// filter for 4-letter observation stations, only those contain sky conditions and thus an icon
|
||||||
const filteredStations = this.weatherParameters.stations.filter((station) => station?.properties?.stationIdentifier?.length === 4 && !skipStations.includes(station.properties.stationIdentifier.slice(0, 1)));
|
const filteredStations = this.weatherParameters.stations.filter((station) => station?.properties?.stationIdentifier?.length === 4 && !skipStations.includes(station.properties.stationIdentifier.slice(0, 1)));
|
||||||
|
|||||||
@@ -22,9 +22,8 @@ class ExtendedForecast extends WeatherDisplay {
|
|||||||
if (!super.getData(weatherParameters, refresh)) return;
|
if (!super.getData(weatherParameters, refresh)) return;
|
||||||
|
|
||||||
// request us or si units
|
// request us or si units
|
||||||
let forecast;
|
|
||||||
try {
|
try {
|
||||||
forecast = await json(this.weatherParameters.forecast, {
|
this.data = await json(this.weatherParameters.forecast, {
|
||||||
data: {
|
data: {
|
||||||
units: settings.units.value,
|
units: settings.units.value,
|
||||||
},
|
},
|
||||||
@@ -34,11 +33,13 @@ class ExtendedForecast extends WeatherDisplay {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Unable to get extended forecast');
|
console.error('Unable to get extended forecast');
|
||||||
console.error(error.status, error.responseJSON);
|
console.error(error.status, error.responseJSON);
|
||||||
this.setStatus(STATUS.failed);
|
// if there's no previous data, fail
|
||||||
return;
|
if (!this.data) {
|
||||||
|
this.setStatus(STATUS.failed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// we only get here if there was no error above
|
// we only get here if there was no error above
|
||||||
this.data = parse(forecast.properties.periods);
|
|
||||||
this.screenIndex = 0;
|
this.screenIndex = 0;
|
||||||
this.setStatus(STATUS.loaded);
|
this.setStatus(STATUS.loaded);
|
||||||
}
|
}
|
||||||
@@ -48,7 +49,7 @@ class ExtendedForecast extends WeatherDisplay {
|
|||||||
|
|
||||||
// determine bounds
|
// determine bounds
|
||||||
// grab the first three or second set of three array elements
|
// grab the first three or second set of three array elements
|
||||||
const forecast = this.data.slice(0 + 3 * this.screenIndex, 3 + this.screenIndex * 3);
|
const forecast = parse(this.data.properties.periods).slice(0 + 3 * this.screenIndex, 3 + this.screenIndex * 3);
|
||||||
|
|
||||||
// create each day template
|
// create each day template
|
||||||
const days = forecast.map((Day) => {
|
const days = forecast.map((Day) => {
|
||||||
|
|||||||
@@ -42,19 +42,17 @@ class Radar extends WeatherDisplay {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
async getData(_weatherParameters, refresh) {
|
async getData(weatherParameters, refresh) {
|
||||||
if (!super.getData(_weatherParameters, refresh)) return;
|
if (!super.getData(weatherParameters, refresh)) return;
|
||||||
const weatherParameters = _weatherParameters ?? this.weatherParameters;
|
|
||||||
|
|
||||||
// ALASKA AND HAWAII AREN'T SUPPORTED!
|
// ALASKA AND HAWAII AREN'T SUPPORTED!
|
||||||
if (weatherParameters.state === 'AK' || weatherParameters.state === 'HI') {
|
if (this.weatherParameters.state === 'AK' || this.weatherParameters.state === 'HI') {
|
||||||
this.setStatus(STATUS.noData);
|
this.setStatus(STATUS.noData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the base map
|
// get the base map
|
||||||
let src = 'images/4000RadarMap2.jpg';
|
const src = 'images/4000RadarMap2.jpg';
|
||||||
if (weatherParameters.State === 'HI') src = 'images/HawaiiRadarMap2.png';
|
|
||||||
this.baseMap = await loadImg(src);
|
this.baseMap = await loadImg(src);
|
||||||
|
|
||||||
const baseUrl = 'https://mesonet.agron.iastate.edu/archive/data/';
|
const baseUrl = 'https://mesonet.agron.iastate.edu/archive/data/';
|
||||||
@@ -110,19 +108,12 @@ class Radar extends WeatherDisplay {
|
|||||||
const height = 1600;
|
const height = 1600;
|
||||||
offsetX *= 2;
|
offsetX *= 2;
|
||||||
offsetY *= 2;
|
offsetY *= 2;
|
||||||
const sourceXY = utils.getXYFromLatitudeLongitudeMap(weatherParameters, offsetX, offsetY);
|
const sourceXY = utils.getXYFromLatitudeLongitudeMap(this.weatherParameters, offsetX, offsetY);
|
||||||
|
|
||||||
// create working context for manipulation
|
|
||||||
const workingCanvas = document.createElement('canvas');
|
|
||||||
workingCanvas.width = width;
|
|
||||||
workingCanvas.height = height;
|
|
||||||
const workingContext = workingCanvas.getContext('2d');
|
|
||||||
workingContext.imageSmoothingEnabled = false;
|
|
||||||
|
|
||||||
// calculate radar offsets
|
// calculate radar offsets
|
||||||
const radarOffsetX = 120;
|
const radarOffsetX = 120;
|
||||||
const radarOffsetY = 70;
|
const radarOffsetY = 70;
|
||||||
const radarSourceXY = utils.getXYFromLatitudeLongitudeDoppler(weatherParameters, offsetX, offsetY);
|
const radarSourceXY = utils.getXYFromLatitudeLongitudeDoppler(this.weatherParameters, offsetX, offsetY);
|
||||||
const radarSourceX = radarSourceXY.x / 2;
|
const radarSourceX = radarSourceXY.x / 2;
|
||||||
const radarSourceY = radarSourceXY.y / 2;
|
const radarSourceY = radarSourceXY.y / 2;
|
||||||
|
|
||||||
@@ -135,6 +126,13 @@ class Radar extends WeatherDisplay {
|
|||||||
const context = canvas.getContext('2d');
|
const context = canvas.getContext('2d');
|
||||||
context.imageSmoothingEnabled = false;
|
context.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
|
// create working context for manipulation
|
||||||
|
const workingCanvas = document.createElement('canvas');
|
||||||
|
workingCanvas.width = width;
|
||||||
|
workingCanvas.height = height;
|
||||||
|
const workingContext = workingCanvas.getContext('2d');
|
||||||
|
workingContext.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
// get the image
|
// get the image
|
||||||
const response = await fetch(rewriteUrl(url));
|
const response = await fetch(rewriteUrl(url));
|
||||||
|
|
||||||
@@ -170,7 +168,7 @@ class Radar extends WeatherDisplay {
|
|||||||
workingContext.drawImage(imgBlob, 0, 0, width, 1600);
|
workingContext.drawImage(imgBlob, 0, 0, width, 1600);
|
||||||
|
|
||||||
// get the base map
|
// get the base map
|
||||||
context.drawImage(await this.baseMap, sourceXY.x, sourceXY.y, offsetX * 2, offsetY * 2, 0, 0, 640, 367);
|
context.drawImage(this.baseMap, sourceXY.x, sourceXY.y, offsetX * 2, offsetY * 2, 0, 0, 640, 367);
|
||||||
|
|
||||||
// crop the radar image
|
// crop the radar image
|
||||||
const cropCanvas = document.createElement('canvas');
|
const cropCanvas = document.createElement('canvas');
|
||||||
|
|||||||
Reference in New Issue
Block a user