regional forecast silent reload

This commit is contained in:
Matt Walsh
2025-04-02 22:18:35 -05:00
parent cc896bf18d
commit bd6c5430c4

View File

@@ -21,9 +21,11 @@ class RegionalForecast extends WeatherDisplay {
this.timing.totalScreens = 3;
}
async getData(_weatherParameters, refresh) {
if (!super.getData(_weatherParameters, refresh)) return;
const weatherParameters = _weatherParameters ?? this.weatherParameters;
async getData(weatherParameters, refresh) {
if (!super.getData(weatherParameters, refresh)) return;
// regional forecast implements a silent reload
// but it will not fall back to previously loaded data if data can not be loaded
// there are enough other cities available to populate the map sufficiently even if some do not load
// pre-load the base map
let baseMap = 'images/Basemap2.png';
@@ -40,14 +42,14 @@ class RegionalForecast extends WeatherDisplay {
y: 117,
};
// get user's location in x/y
const sourceXY = utils.getXYFromLatitudeLongitude(weatherParameters.latitude, weatherParameters.longitude, offsetXY.x, offsetXY.y, weatherParameters.state);
const sourceXY = utils.getXYFromLatitudeLongitude(this.weatherParameters.latitude, this.weatherParameters.longitude, offsetXY.x, offsetXY.y, weatherParameters.state);
// get latitude and longitude limits
const minMaxLatLon = utils.getMinMaxLatitudeLongitude(sourceXY.x, sourceXY.y, offsetXY.x, offsetXY.y, weatherParameters.state);
const minMaxLatLon = utils.getMinMaxLatitudeLongitude(sourceXY.x, sourceXY.y, offsetXY.x, offsetXY.y, this.weatherParameters.state);
// get a target distance
let targetDistance = 2.5;
if (weatherParameters.state === 'HI') targetDistance = 1;
if (this.weatherParameters.state === 'HI') targetDistance = 1;
// make station info into an array
const stationInfoArray = Object.values(StationInfo).map((value) => ({ ...value, targetDistance }));
@@ -86,7 +88,7 @@ class RegionalForecast extends WeatherDisplay {
const forecast = await json(`https://api.weather.gov/gridpoints/${point.wfo}/${point.x},${point.y}/forecast`);
// get XY on map for city
const cityXY = utils.getXYForCity(city, minMaxLatLon.maxLat, minMaxLatLon.minLon, weatherParameters.state);
const cityXY = utils.getXYForCity(city, minMaxLatLon.maxLat, minMaxLatLon.minLon, this.weatherParameters.state);
// wait for the regional observation if it's not done yet
const observation = await observationPromise;