fix regional forecast and observations

This commit is contained in:
Matt Walsh
2022-12-12 15:41:28 -06:00
parent 703d64f6b2
commit 94fafc247a
7 changed files with 34035 additions and 22604 deletions

View File

@@ -15,7 +15,7 @@ const buildForecast = (forecast, city, cityXY) => ({
const getRegionalObservation = async (point, city) => {
try {
// get stations
const stations = await json(`https://api.weather.gov/gridpoints/${city.point.wfo}/${city.point.x},${city.point.y}/stations`);
const stations = await json(`https://api.weather.gov/gridpoints/${point.wfo}/${point.x},${point.y}/stations`);
// get the first station
const station = stations.features[0].id;

View File

@@ -11,6 +11,7 @@ import { DateTime } from '../vendor/auto/luxon.mjs';
import WeatherDisplay from './weatherdisplay.mjs';
import { registerDisplay } from './navigation.mjs';
import * as utils from './regionalforecast-utils.mjs';
import { getPoint } from './utils/weather.mjs';
class RegionalForecast extends WeatherDisplay {
constructor(navId, elemId) {
@@ -73,12 +74,13 @@ 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 {
if (!city.point) throw new Error('No pre-loaded point');
const point = city?.point ?? (await getAndFormatPoint(city.lat, city.lon));
if (!point) throw new Error('No pre-loaded point');
// start off the observation task
const observationPromise = utils.getRegionalObservation(city.point, city);
const observationPromise = utils.getRegionalObservation(point, city);
const forecast = await json(`https://api.weather.gov/gridpoints/${city.point.wfo}/${city.point.x},${city.point.y}/forecast`);
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);
@@ -192,5 +194,14 @@ class RegionalForecast extends WeatherDisplay {
}
}
const getAndFormatPoint = async (lat, lon) => {
const point = await getPoint(lat, lon);
return {
x: point.properties.gridX,
y: point.properties.gridY,
wfo: point.properties.gridId,
};
};
// register display
registerDisplay(new RegionalForecast(5, 'regional-forecast'));