pre-load wfo point info for regional and travel cities

This commit is contained in:
Matt Walsh
2022-11-22 14:17:04 -06:00
parent 6e2abf6720
commit c28608bb39
13 changed files with 2940 additions and 11 deletions

View File

@@ -65,13 +65,12 @@ class RegionalForecast extends WeatherDisplay {
// get regional forecasts and observations (the two are intertwined due to the design of api.weather.gov)
const regionalDataAll = await Promise.all(regionalCities.map(async (city) => {
try {
// get the point first, then break down into forecast and observations
const point = await utils.weather.getPoint(city.lat, city.lon);
if (!city.point) throw new Error('No pre-loaded point');
// start off the observation task
const observationPromise = RegionalForecast.getRegionalObservation(point, city);
const observationPromise = RegionalForecast.getRegionalObservation(city.point, city);
const forecast = await utils.fetch.json(point.properties.forecast);
const forecast = await utils.fetch.json(`https://api.weather.gov/gridpoints/${city.point.wfo}/${city.point.x},${city.point.y}/forecast`);
// get XY on map for city
const cityXY = RegionalForecast.getXYForCity(city, minMaxLatLon.maxLat, minMaxLatLon.minLon, weatherParameters.state);
@@ -142,7 +141,7 @@ class RegionalForecast extends WeatherDisplay {
static async getRegionalObservation(point, city) {
try {
// get stations
const stations = await utils.fetch.json(point.properties.observationStations);
const stations = await utils.fetch.json(`https://api.weather.gov/gridpoints/${city.point.wfo}/${city.point.x},${city.point.y}/stations`);
// get the first station
const station = stations.features[0].id;

View File

@@ -29,8 +29,8 @@ class TravelForecast extends WeatherDisplay {
const forecastPromises = TravelCities.map(async (city) => {
try {
// get point then forecast
const point = await utils.weather.getPoint(city.Latitude, city.Longitude);
const forecast = await utils.fetch.json(point.properties.forecast);
if (!city.point) throw new Error('No pre-loaded point');
const forecast = await utils.fetch.json(`https://api.weather.gov/gridpoints/${city.point.wfo}/${city.point.x},${city.point.y}/forecast`);
// determine today or tomorrow (shift periods by 1 if tomorrow)
const todayShift = forecast.properties.periods[0].isDaytime ? 0 : 1;
// return a pared-down forecast