From db51d08870d14a38bbf74eda73d02fc811298d4a Mon Sep 17 00:00:00 2001 From: Jonathan Chemla Date: Sat, 21 Nov 2026 08:59:26 +0100 Subject: [PATCH 1/5] fix: keep what lies across the antimeridian in the map bounding box filter Co-Authored-By: Claude Fable 5.2 --- src/components/collections.tsx | 12 ++--------- src/components/items.tsx | 9 ++------- src/utils/bbox.ts | 34 +++++++++++++++++++++++++++++++ tests/utils/bbox.spec.ts | 37 ++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/src/components/collections.tsx b/src/components/collections.tsx index 9fc75c8a..71adb234 100644 --- a/src/components/collections.tsx +++ b/src/components/collections.tsx @@ -1,5 +1,6 @@ import { type BBox2D, useStore } from "@/store"; import type { StacCollections } from "@/types/stac"; +import { bboxIntersectsViewport } from "@/utils/bbox"; import { collectionMatchesFilter, getCollectionsDatetimeExtent, @@ -327,16 +328,7 @@ function isCollectionInBbox( return includeGlobalCollections; } const collectionBbox = collection?.extent?.spatial?.bbox?.[0]; - if (collectionBbox) { - return !( - collectionBbox[0] > bbox[2] || - collectionBbox[1] > bbox[3] || - collectionBbox[2] < bbox[0] || - collectionBbox[3] < bbox[1] - ); - } else { - return false; - } + return collectionBbox ? bboxIntersectsViewport(collectionBbox, bbox) : false; } function isGlobalCollection(collection: StacCollection) { diff --git a/src/components/items.tsx b/src/components/items.tsx index 4c115056..83a5fefe 100644 --- a/src/components/items.tsx +++ b/src/components/items.tsx @@ -1,4 +1,5 @@ import { type BBox2D, useStore } from "@/store"; +import { bboxIntersectsViewport } from "@/utils/bbox"; import { getItemsDatetimeExtent, itemMatchesFilter } from "@/utils/datetime"; import { fitBoundsToBbox } from "@/utils/map"; import { fetchStacValue, getSelfHref } from "@/utils/stac"; @@ -244,11 +245,5 @@ function getItemsBbox(items: StacItem[]): BBox2D | undefined { function isItemInBbox(item: StacItem, bbox: BBox2D): boolean { const itemBbox = toBbox2D(item.bbox); if (!itemBbox) return false; - if (bbox[2] - bbox[0] >= 360) return true; - return !( - itemBbox[0] > bbox[2] || - itemBbox[1] > bbox[3] || - itemBbox[2] < bbox[0] || - itemBbox[3] < bbox[1] - ); + return bboxIntersectsViewport(itemBbox, bbox); } diff --git a/src/utils/bbox.ts b/src/utils/bbox.ts index 286a9049..fa521999 100644 --- a/src/utils/bbox.ts +++ b/src/utils/bbox.ts @@ -44,3 +44,37 @@ export function normalizeViewport(bbox: BBox2D): BBox2D[] | null { [-180, s, e - 360, n], ]; } + +/** + * Whether a STAC bbox (2D or 3D) intersects a map viewport. + * + * The viewport may run past ±180 when the map is panned across the + * antimeridian, and the bbox may cross it too (west greater than east). + */ +export function bboxIntersectsViewport( + bbox: number[], + viewport: BBox2D +): boolean { + const views = normalizeViewport(viewport); + if (!views) return true; + const [west, south, east, north] = + bbox.length === 6 ? [bbox[0], bbox[1], bbox[3], bbox[4]] : bbox; + const boxes = + west > east + ? [ + [west, south, 180, north], + [-180, south, east, north], + ] + : [[west, south, east, north]]; + return views.some((view) => + boxes.some( + (box) => + !( + box[0] > view[2] || + box[1] > view[3] || + box[2] < view[0] || + box[3] < view[1] + ) + ) + ); +} diff --git a/tests/utils/bbox.spec.ts b/tests/utils/bbox.spec.ts index 90bd4d8d..e9d72a2b 100644 --- a/tests/utils/bbox.spec.ts +++ b/tests/utils/bbox.spec.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; import { + bboxIntersectsViewport, clampToGlobalExtents, normalizeViewport, resolveInitialBbox, @@ -113,3 +114,39 @@ describe("normalizeViewport", () => { ]); }); }); + +describe("bboxIntersectsViewport", () => { + const samoa = [-172.8, -14.1, -171.4, -13.4]; + const fiji = [177, -19, -178, -16]; + + it("matches a plain overlap and rejects a plain miss", () => { + expect(bboxIntersectsViewport(samoa, [-180, -20, -160, -10])).toBe(true); + expect(bboxIntersectsViewport(samoa, [0, 40, 10, 50])).toBe(false); + }); + + it("matches a bbox on the far side of a viewport panned past 180", () => { + expect(bboxIntersectsViewport(samoa, [150, -30, 200, 0])).toBe(true); + }); + + it("matches a bbox on the far side of a viewport panned past -180", () => { + expect( + bboxIntersectsViewport([170, -20, 179, -10], [-200, -30, -150, 0]) + ).toBe(true); + }); + + it("handles a bbox that itself crosses the antimeridian", () => { + expect(bboxIntersectsViewport(fiji, [-179, -20, -170, -10])).toBe(true); + expect(bboxIntersectsViewport(fiji, [178, -20, 179, -10])).toBe(true); + expect(bboxIntersectsViewport(fiji, [0, -20, 10, -10])).toBe(false); + }); + + it("reads the horizontal extent of a 3D bbox", () => { + expect( + bboxIntersectsViewport([10, 40, 0, 11, 41, 100], [10.5, 40.5, 12, 42]) + ).toBe(true); + }); + + it("matches everything when the viewport spans every longitude", () => { + expect(bboxIntersectsViewport(samoa, [-300, -80, 300, 80])).toBe(true); + }); +}); From a12936796f9d3a8d2d35fa2c129d099ecd891541 Mon Sep 17 00:00:00 2001 From: Jonathan Chemla Date: Sat, 21 Nov 2026 08:59:26 +0100 Subject: [PATCH 2/5] fix: show an item's properties.description as its description Co-Authored-By: Claude Fable 5.2 --- src/components/cards/value.tsx | 5 ++++- src/components/value.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/cards/value.tsx b/src/components/cards/value.tsx index 911dd925..ce4dd429 100644 --- a/src/components/cards/value.tsx +++ b/src/components/cards/value.tsx @@ -23,7 +23,10 @@ export default function ValueCard({ const setHref = useStore((store) => store.setHref); const selfHref = getSelfHref(value); const thumbnailAsset = getThumbnailAsset(value); - const description = value.description as string | undefined; + // An Item keeps its description in its properties + const description = (value.description ?? + (value.properties as { description?: string } | undefined)?.description) as + string | undefined; return ( store.setProjection); const version = value.stac_version as string; const thumbnailAsset = getThumbnailAsset(value); - const description = value.description as string; + const properties = value.properties as GeoJsonProperties | undefined; + // An Item keeps its description in its properties + const description = (value.description ?? properties?.description) as + string | undefined; const collectionsLink = getLink(value, "data"); const childLinks = value.links?.filter((link) => link.rel === "child"); const itemLinks = value.links?.filter((link) => link.rel === "item"); const rootLink = getLink(value, "root"); - const properties = value.properties as GeoJsonProperties | undefined; const assets = value.assets as StacAssets | undefined; useEffect(() => { From edbff8a2f593d7790dac17dccb42b98c81947a80 Mon Sep 17 00:00:00 2001 From: Jonathan Chemla Date: Sat, 21 Nov 2026 08:59:27 +0100 Subject: [PATCH 3/5] fix: show boolean enum options and min/max for nullable numbers in queryables Co-Authored-By: Claude Fable 5.2 --- src/components/queryables.tsx | 22 ++++++++++++++-------- src/utils/cql2.ts | 4 ++-- src/utils/stac.ts | 4 ++-- tests/utils/cql2.spec.ts | 9 +++++++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/components/queryables.tsx b/src/components/queryables.tsx index 6e4ca0e0..73ff610d 100644 --- a/src/components/queryables.tsx +++ b/src/components/queryables.tsx @@ -85,15 +85,19 @@ function QueryableField({ - onChange(e.target.value ? { eq: e.target.value } : undefined) - } + value={value?.eq === undefined ? "" : String(value.eq)} + onChange={(e) => { + // Keep the option's own type: a boolean or number stays one + const option = property.enum?.find( + (option) => String(option) === e.target.value + ); + onChange(option === undefined ? undefined : { eq: option }); + }} > {property.enum.map((option) => ( - ))} @@ -103,7 +107,9 @@ function QueryableField({ ); } - if (property.type === "number" || property.type === "integer") { + // A nullable number is typed ["integer", "null"] + const types = [property.type].flat(); + if (types.includes("number") || types.includes("integer")) { return ( @@ -148,7 +154,7 @@ function QueryableField({ onChange(e.target.value ? { eq: e.target.value } : undefined) } diff --git a/src/utils/cql2.ts b/src/utils/cql2.ts index 0a2344bc..772d49b8 100644 --- a/src/utils/cql2.ts +++ b/src/utils/cql2.ts @@ -1,11 +1,11 @@ export interface QueryableFilter { - eq?: string; + eq?: string | number | boolean; gte?: number; lte?: number; } export type Cql2Expression = - | { op: "="; args: [{ property: string }, string] } + | { op: "="; args: [{ property: string }, string | number | boolean] } | { op: ">=" | "<="; args: [{ property: string }, number] } | { op: "and"; args: Cql2Expression[] }; diff --git a/src/utils/stac.ts b/src/utils/stac.ts index 86ebae12..82c401df 100644 --- a/src/utils/stac.ts +++ b/src/utils/stac.ts @@ -149,8 +149,8 @@ export function getQueryablesHref(value: { links?: Array }) { } export interface QueryableProperty { - type?: string; - enum?: (string | number)[]; + type?: string | string[]; + enum?: (string | number | boolean)[]; minimum?: number; maximum?: number; title?: string; diff --git a/tests/utils/cql2.spec.ts b/tests/utils/cql2.spec.ts index bfceb2a2..87daeb42 100644 --- a/tests/utils/cql2.spec.ts +++ b/tests/utils/cql2.spec.ts @@ -2,6 +2,15 @@ import { describe, expect, it } from "vitest"; import { buildCql2Json } from "../../src/utils/cql2"; import { loadCql2Wasm } from "../../src/utils/cql2-wasm"; +describe("buildCql2Json with a boolean", () => { + it("keeps the boolean as a boolean", () => { + expect(buildCql2Json({ "ogdc:usable": { eq: true } })).toEqual({ + op: "=", + args: [{ property: "ogdc:usable" }, true], + }); + }); +}); + describe("buildCql2Json", () => { it("returns undefined for an empty queryables map", () => { expect(buildCql2Json({})).toBeUndefined(); From cf358fa259790168fedb6d5ff55e16d3c78c4ff2 Mon Sep 17 00:00:00 2001 From: Jonathan Chemla Date: Sat, 21 Nov 2026 08:59:27 +0100 Subject: [PATCH 4/5] fix: give the status code and the API's description when a request fails Co-Authored-By: Claude Fable 5.2 --- src/utils/stac.ts | 21 +++++++++++++++++++-- tests/utils/stac.spec.ts | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/utils/stac.ts b/src/utils/stac.ts index 82c401df..19583e45 100644 --- a/src/utils/stac.ts +++ b/src/utils/stac.ts @@ -17,6 +17,23 @@ function buildAuthHeaders(href: string): Record { return headers; } +/** + * An error for a failed request: the status code, the status text when there + * is one (HTTP/2 and HTTP/3 have none) and the `description` of a STAC API + * error body. + */ +export async function responseError(href: string, response: Response) { + let description: unknown; + try { + description = (await response.json())?.description; + } catch { + // Not JSON: the status says enough + } + const parts = [`GET ${href}: ${response.status}`, response.statusText]; + if (typeof description === "string") parts.push(`(${description})`); + return new Error(parts.filter(Boolean).join(" ")); +} + export async function fetchStacValue({ href, uploadedFile, @@ -36,7 +53,7 @@ export async function fetchStacValue({ makeHrefsAbsolute(applyGuessedType(json), href.toString()) ); } else { - throw new Error(`GET ${href}: ${response.statusText}`); + throw await responseError(href, response); } }); } else if (uploadedFile) { @@ -169,7 +186,7 @@ export async function fetchQueryablesSchema( headers: buildAuthHeaders(href), }); if (!response.ok) { - throw new Error(`GET ${href}: ${response.statusText}`); + throw await responseError(href, response); } return response.json(); } diff --git a/tests/utils/stac.spec.ts b/tests/utils/stac.spec.ts index d91636b3..7a450b39 100644 --- a/tests/utils/stac.spec.ts +++ b/tests/utils/stac.spec.ts @@ -16,6 +16,7 @@ import { getStacType, getThumbnailAsset, guessStacType, + responseError, sanitizeBbox, } from "../../src/utils/stac"; @@ -140,6 +141,25 @@ describe("fetchStacValue", () => { }); }); +describe("responseError", () => { + it("gives the status code when there is no status text", async () => { + const response = new Response("not json", { status: 404 }); + const error = await responseError("https://example.com/x", response); + expect(error.message).toBe("GET https://example.com/x: 404"); + }); + + it("adds the status text and a STAC API error description", async () => { + const response = new Response( + JSON.stringify({ code: "NotFoundError", description: "No such catalog" }), + { status: 404, statusText: "Not Found" } + ); + const error = await responseError("https://example.com/x", response); + expect(error.message).toBe( + "GET https://example.com/x: 404 Not Found (No such catalog)" + ); + }); +}); + describe("getStacId", () => { it("returns the id when present", () => { expect(getStacId(makeCatalog({ id: "my-id" }))).toBe("my-id"); From 625d762ce429ca62a845f0c0a6cd8d5ede918a39 Mon Sep 17 00:00:00 2001 From: Jonathan Chemla Date: Tue, 24 Nov 2026 23:29:16 +0100 Subject: [PATCH 5/5] refactor: drop comments the code already says --- src/components/cards/value.tsx | 1 - src/components/queryables.tsx | 2 -- src/components/value.tsx | 1 - 3 files changed, 4 deletions(-) diff --git a/src/components/cards/value.tsx b/src/components/cards/value.tsx index ce4dd429..84d11de4 100644 --- a/src/components/cards/value.tsx +++ b/src/components/cards/value.tsx @@ -23,7 +23,6 @@ export default function ValueCard({ const setHref = useStore((store) => store.setHref); const selfHref = getSelfHref(value); const thumbnailAsset = getThumbnailAsset(value); - // An Item keeps its description in its properties const description = (value.description ?? (value.properties as { description?: string } | undefined)?.description) as string | undefined; diff --git a/src/components/queryables.tsx b/src/components/queryables.tsx index 73ff610d..95a1dc2d 100644 --- a/src/components/queryables.tsx +++ b/src/components/queryables.tsx @@ -87,7 +87,6 @@ function QueryableField({ { - // Keep the option's own type: a boolean or number stays one const option = property.enum?.find( (option) => String(option) === e.target.value ); @@ -107,7 +106,6 @@ function QueryableField({ ); } - // A nullable number is typed ["integer", "null"] const types = [property.type].flat(); if (types.includes("number") || types.includes("integer")) { return ( diff --git a/src/components/value.tsx b/src/components/value.tsx index b983a3a3..f1f04ce7 100644 --- a/src/components/value.tsx +++ b/src/components/value.tsx @@ -51,7 +51,6 @@ export default function Value({ const version = value.stac_version as string; const thumbnailAsset = getThumbnailAsset(value); const properties = value.properties as GeoJsonProperties | undefined; - // An Item keeps its description in its properties const description = (value.description ?? properties?.description) as string | undefined; const collectionsLink = getLink(value, "data");