search for 4-letter stations on regional maps close #187

This commit is contained in:
Matt Walsh
2026-03-06 15:55:28 -06:00
parent 194e108037
commit ec65025ae2

View File

@@ -23,7 +23,7 @@ const buildForecast = (forecast, city, cityXY) => {
const getRegionalObservation = async (point, city) => { const getRegionalObservation = async (point, city) => {
try { try {
// get stations using centralized safe handling // get stations using centralized safe handling
const stations = await safeJson(`https://api.weather.gov/gridpoints/${point.wfo}/${point.x},${point.y}/stations?limit=1`); const stations = await safeJson(`https://api.weather.gov/gridpoints/${point.wfo}/${point.x},${point.y}/stations?limit=10`);
if (!stations || !stations.features || stations.features.length === 0) { if (!stations || !stations.features || stations.features.length === 0) {
if (debugFlag('verbose-failures')) { if (debugFlag('verbose-failures')) {
@@ -32,9 +32,13 @@ const getRegionalObservation = async (point, city) => {
return false; return false;
} }
// get the first station // get the first station with a 4-letter id (generally has appropriate data)
const station = stations.features[0].id; const station4Letter = stations.features.find((station) => {
const stationId = stations.features[0].properties.stationIdentifier; if (station.properties.stationIdentifier.length === 4) return station.properties;
return false;
});
const station = station4Letter.id;
const stationId = station4Letter.properties.stationIdentifier;
// get the observation data using centralized safe handling // get the observation data using centralized safe handling
const observation = await safeJson(`${station}/observations/latest`); const observation = await safeJson(`${station}/observations/latest`);