A GeoJSON object, such as a Feature, FeatureCollection or Geometry, or an array of them.
The bounding box as [west, south, east, north], or undefined for invalid input.
// From a Feature with existing bbox
const place = await geocodeOne('Amsterdam');
const bbox = bboxFromGeoJSON(place);
// Returns the bbox that came with the place
// From a Polygon geometry (calculates bbox)
const polygon = {
type: 'Polygon',
coordinates: [[
[4.88, 52.36],
[4.90, 52.36],
[4.90, 52.38],
[4.88, 52.38],
[4.88, 52.36]
]]
};
const polyBbox = bboxFromGeoJSON(polygon);
// Returns: [4.88, 52.36, 4.90, 52.38]
// From a FeatureCollection (aggregates all features)
const places = await discoverPlaces({ query: 'coffee' });
const collectionBbox = bboxFromGeoJSON(places);
// Returns bbox encompassing all search results
// From a LineString (calculates from coordinates)
const route = await calculateRoute({
locations: [[4.9, 52.3], [4.5, 51.9]]
});
const routeBbox = bboxFromGeoJSON(route.features[0].geometry);
// Returns bbox containing the entire route
// From an array of GeoJSON objects
const multiBbox = bboxFromGeoJSON([place1, place2, place3]);
// Returns bbox encompassing all three places
Extracts or calculates a bounding box from GeoJSON objects.
It handles various GeoJSON types, picking the best approach:
bboxproperty, which is fastest.An existing bbox wins over the geometry. This matters for Point features from TomTom services, whose bbox may cover a broader area than the point itself.
A calculated box crosses the antimeridian, with
west > east, when that is the narrower way to enclose the input:[[179, 0], [-179, 0]]spans 358°, and[[179, 0], [181, 0]]gives[179, 0, -179, 0].