Reputation: 1
I'm trying to make a weather radar that displays alert polygons from the NWS API. For some of these alerts, the geometry is stored in separate links:
{
"id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.235b453f6211d665365a573e200008d44979bdce.001.1",
"type": "Feature",
"geometry": null,
"properties": {
"@id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.235b453f6211d665365a573e200008d44979bdce.001.1",
"@type": "wx:Alert",
"id": "urn:oid:2.49.0.1.840.0.235b453f6211d665365a573e200008d44979bdce.001.1",
"areaDesc": "Todd; Morrison; Mille Lacs; Kanabec; Benton; Isanti; Chisago; Polk; Barron; Rusk",
"geocode": {
"SAME": [
...
],
"UGC": [
...
]
},
"affectedZones": [
"https://api.weather.gov/zones/forecast/MNZ042",
"https://api.weather.gov/zones/forecast/MNZ043",
"https://api.weather.gov/zones/forecast/MNZ044",
"https://api.weather.gov/zones/forecast/MNZ045",
"https://api.weather.gov/zones/forecast/MNZ050",
"https://api.weather.gov/zones/forecast/MNZ052",
"https://api.weather.gov/zones/forecast/MNZ053",
"https://api.weather.gov/zones/forecast/WIZ014",
"https://api.weather.gov/zones/forecast/WIZ015",
"https://api.weather.gov/zones/forecast/WIZ016"
],
and every link has geometry in it:
{
"@context": {
"@version": "1.1"
},
"id": "https://api.weather.gov/zones/forecast/MNZ042",
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-94.732093800000001,
46.369010899999999
],
[
-94.731994600000007,
46.366912800000001
],
[
-94.731094300000009,
46.363113400000003
],
...
I tried to do this:
if (alert.geometry) {
geometry = alert.geometry;
} else {
const affectedZoneGeometries = await Promise.all(
alert.properties.affectedZones.map(async (zone) => {
const res = await fetch(zone);
const zoneData = await res.json();
return zoneData.geometry.coordinates;
})
);
geometry = {
'coordinates': affectedZoneGeometries,
'type': 'MultiPolygon'
}
}
Which is logged as:
but the polygons will not display on the map. I suspect that this is due to incorrect polygon parsing, but I don't know the solution to it.
Upvotes: 0
Views: 15