Skip to content

Commit

Permalink
feat: improve extent function
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Jun 5, 2024
1 parent a7dcceb commit 2130c4a
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions libs/feature/map/src/lib/utils/map-utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,18 @@ export class MapUtilsService {
}

getRecordExtent(record: Partial<CatalogRecord>): Extent {
if (!('spatialExtents' in record)) {
return null
} else if (record.spatialExtents.length > 0) {
// transform an array of geojson geometries into a bbox
const totalExtent = record.spatialExtents.reduce(
(prev, curr) => {
const geom = GEOJSON.readGeometry(curr.geometry)
return extend(prev, geom.getExtent())
},
[Infinity, Infinity, -Infinity, -Infinity]
)
return transformExtent(totalExtent, 'EPSG:4326', 'EPSG:3857')
} else {
if (!('spatialExtents' in record) || record.spatialExtents.length === 0) {
return null
}
// transform an array of geojson geometries into a bbox
const totalExtent = record.spatialExtents.reduce(
(prev, curr) => {
const geom = GEOJSON.readGeometry(curr.geometry)
return extend(prev, geom.getExtent())
},
[Infinity, Infinity, -Infinity, -Infinity]
)
return transformExtent(totalExtent, 'EPSG:4326', 'EPSG:3857')
}
}

Expand Down

0 comments on commit 2130c4a

Please sign in to comment.