Skip to content

Commit f2ad23e

Browse files
committed
fix: load invalid STAC values
1 parent 01843fa commit f2ad23e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/http.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export async function fetchStac(
1616
if (response.ok) {
1717
return response
1818
.json()
19-
.then((json) => maybeAddSelfLink(json, href.toString()));
19+
.then((json) => maybeAddSelfLink(json, href.toString()))
20+
.then((json) => maybeAddTypeField(json));
2021
} else {
2122
throw new Error(`${method} ${href}: ${response.statusText}`);
2223
}
@@ -44,3 +45,19 @@ function maybeAddSelfLink(value: any, href: string) {
4445
}
4546
return value;
4647
}
48+
49+
// eslint-disable-next-line
50+
function maybeAddTypeField(value: any) {
51+
if (!value.type) {
52+
if (value.features && Array.isArray(value.features)) {
53+
value.type = "FeatureCollection";
54+
} else if (value.extent) {
55+
value.type = "Collection";
56+
} else if (value.geometry && value.properties) {
57+
value.type = "Feature";
58+
} else if (value.stac_version) {
59+
value.type = "Catalog";
60+
}
61+
}
62+
return value;
63+
}

tests/app.spec.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,22 @@ test("renders example button", async () => {
2222
.toBeVisible();
2323
});
2424

25-
test("loads STAC API from eoapi.dev", async () => {
25+
test("loads stac.eoapi.dev", async () => {
2626
window.history.pushState({}, "", "?href=https://stac.eoapi.dev/");
2727
const app = await renderApp();
2828
await expect.element(app.getByText(/eoAPI-stac/i)).toBeVisible();
2929
await expect.element(app.getByText(/collections/i)).toBeVisible();
3030
});
31+
32+
test("loads CSDA Planet", async () => {
33+
// https://github.com/developmentseed/stac-map/issues/96
34+
window.history.pushState(
35+
{},
36+
"",
37+
"?href=https://csdap.earthdata.nasa.gov/stac/collections/planet",
38+
);
39+
const app = await renderApp();
40+
await expect
41+
.element(app.getByRole("heading", { hasText: "Planet" }))
42+
.toBeVisible();
43+
});

0 commit comments

Comments
 (0)