Skip to content

Commit 06d441b

Browse files
committed
Add getBoundsGeoJSON method
1 parent 107766b commit 06d441b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/utils/record.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,24 @@ export class OgmRecord {
244244
const south = parseFloat(coords.groups.south);
245245
return new LngLatBounds([west, south, east, north]);
246246
}
247+
248+
// Get the bounding box as a GeoJSON Polygon
249+
getBoundsGeoJSON() {
250+
const bounds = this.getBounds();
251+
if (!bounds) return null;
252+
253+
// Convert LngLatBounds to GeoJSON Polygon
254+
return {
255+
type: 'Polygon',
256+
coordinates: [
257+
[
258+
[bounds.getWest(), bounds.getSouth()],
259+
[bounds.getEast(), bounds.getSouth()],
260+
[bounds.getEast(), bounds.getNorth()],
261+
[bounds.getWest(), bounds.getNorth()],
262+
[bounds.getWest(), bounds.getSouth()],
263+
],
264+
],
265+
};
266+
}
247267
}

0 commit comments

Comments
 (0)