Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/components/assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ function AssetCard({
)}
</HStack>
<Card.Description>
{asset.roles?.map((role) => (
<Badge key={role}>{role}</Badge>
))}
{Array.isArray(asset.roles) &&
asset.roles.map((role) => <Badge key={role}>{role}</Badge>)}
{asset.type && <Badge>{asset.type}</Badge>}
</Card.Description>
<Card.Footer>
Expand Down
13 changes: 10 additions & 3 deletions src/components/items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,21 @@ export function ItemLinks({ links }: { links: StacLink[] }) {
return items.length > 0 ? <Items items={items} /> : null;
}

function toBbox2D(bbox: number[] | undefined): BBox2D | undefined {
if (!bbox) return undefined;
if (bbox.length === 4) return [bbox[0], bbox[1], bbox[2], bbox[3]];
if (bbox.length === 6) return [bbox[0], bbox[1], bbox[3], bbox[4]];
return undefined;
}

function getItemsBbox(items: StacItem[]): BBox2D | undefined {
let west = Infinity;
let south = Infinity;
let east = -Infinity;
let north = -Infinity;
for (const item of items) {
const b = item.bbox;
if (!b || b.length < 4) continue;
const b = toBbox2D(item.bbox);
if (!b) continue;
if (b[0] < west) west = b[0];
if (b[1] < south) south = b[1];
if (b[2] > east) east = b[2];
Expand All @@ -224,7 +231,7 @@ function getItemsBbox(items: StacItem[]): BBox2D | undefined {
}

function isItemInBbox(item: StacItem, bbox: BBox2D): boolean {
const itemBbox = item.bbox as BBox2D | undefined;
const itemBbox = toBbox2D(item.bbox);
if (!itemBbox) return false;
if (bbox[2] - bbox[0] >= 360) return true;
return !(
Expand Down
9 changes: 6 additions & 3 deletions src/utils/stac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ function makeHrefsAbsolute<T extends StacValue>(value: T, baseUrl: string): T {
const baseUrlObj = new URL(baseUrl);

if (value.links != null) {
let hasSelf = false;
let hasSelfHref = false;
for (const link of value.links) {
if (link.rel === "self") hasSelf = true;
if (link.rel === "self") {
hasSelfHref = true;
link.href = baseUrl;
}
if (link.href) {
link.href = toAbsoluteUrl(link.href, baseUrlObj);
}
}
if (hasSelf === false) {
if (!hasSelfHref) {
value.links.push({ href: baseUrl, rel: "self" });
}
} else {
Expand Down
Loading