fix(map): honor raster coverage and temporal dates
This commit is contained in:
@@ -117,6 +117,49 @@ export function persistedDatasetSupportsSelection(
|
||||
return scale === 'detail'
|
||||
}
|
||||
|
||||
export function datasetIntersectsSelection(
|
||||
dataset: { source_metadata?: Record<string, unknown> | null },
|
||||
bbox: VectorSelectionBBox,
|
||||
): boolean {
|
||||
const bounds = dataset.source_metadata?.['bbox_epsg4326']
|
||||
if (!Array.isArray(bounds) || bounds.length !== 4) {
|
||||
return true
|
||||
}
|
||||
const [minX, minY, maxX, maxY] = bounds.map(Number)
|
||||
if (![minX, minY, maxX, maxY].every(Number.isFinite)) {
|
||||
return true
|
||||
}
|
||||
return !(
|
||||
bbox.max_x < minX
|
||||
|| bbox.min_x > maxX
|
||||
|| bbox.max_y < minY
|
||||
|| bbox.min_y > maxY
|
||||
)
|
||||
}
|
||||
|
||||
export function deduplicateTemporalSnapshots<
|
||||
T extends {
|
||||
id: string
|
||||
observed_at?: string | null
|
||||
imported_at?: string | null
|
||||
created_at?: string | null
|
||||
},
|
||||
>(datasets: T[]): T[] {
|
||||
const byObservation = new Map<string, T>()
|
||||
for (const dataset of datasets) {
|
||||
if (!dataset.observed_at) continue
|
||||
const current = byObservation.get(dataset.observed_at)
|
||||
const recency = new Date(dataset.imported_at ?? dataset.created_at ?? 0).getTime()
|
||||
const currentRecency = new Date(current?.imported_at ?? current?.created_at ?? 0).getTime()
|
||||
if (!current || recency > currentRecency || (recency === currentRecency && dataset.id > current.id)) {
|
||||
byObservation.set(dataset.observed_at, dataset)
|
||||
}
|
||||
}
|
||||
return Array.from(byObservation.values()).sort(
|
||||
(left, right) => new Date(left.observed_at ?? 0).getTime() - new Date(right.observed_at ?? 0).getTime(),
|
||||
)
|
||||
}
|
||||
|
||||
export function selectionFeatureLimit(bbox: VectorSelectionBBox): number {
|
||||
const scale = selectionAnalysisScale(bbox)
|
||||
if (scale === 'overview') return 25
|
||||
|
||||
Reference in New Issue
Block a user