turf.bbox
What is turf.bbox?
turf.bbox takes any GeoJSON input and returns its bounding box as a four-element array [minX, minY, maxX, maxY] in the coordinate system of the input (typically WGS84 longitude/latitude). It walks every coordinate once and returns the axis-aligned extent. The result is a plain array, not a GeoJSON Feature — for a polygon representation use turf.bboxPolygon.
turf.bbox(geojson) → BBoxThere are no options. The computation is purely planar over the input coordinates, so for features that cross the antimeridian you may need a custom strategy.
When would you use turf.bbox?
Use turf.bbox whenever you need to fit a map view to a feature. On MapLibre or Mapbox, pass the result directly to map.fitBounds to zoom a user-drawn polygon, a search result, or a newly loaded GeoJSON layer into view. It is also a common preprocessing step for spatial indexing — build an R-tree over bounding boxes for fast hit-testing before doing exact geometry checks.
In Node.js, use it to compute tile coverage for static map generation, to emit extent metadata alongside exported GeoJSON, or to reject upload payloads whose extent is outside a permitted region.
undefinedFAQs
What format does turf.bbox return?
A four-element array [west, south, east, north] (or [minX, minY, maxX, maxY]). This matches the GeoJSON spec's bbox member and plugs directly into MapLibre's fitBounds when split into two [lng, lat] pairs.
Does it handle 3D coordinates?
turf.bbox returns 2D extents only. If your features carry Z values and you need a 3D envelope, walk the coordinates manually or use turf.meta.coordEach with your own min/max tracking.
How do I install just bbox?
npm install @turf/bbox. It has a tiny dependency footprint — essentially just @turf/meta — so it tree-shakes well into production bundles. The full @turf/turf package also exports it.
What happens if my feature crosses the antimeridian?
turf.bbox treats longitude purely numerically, so a feature spanning -179 to +179 returns a bounding box [-179, …, 179, …] that visually wraps the whole globe. For antimeridian-aware handling, split the feature first or use a specialized library like @mapbox/geojson-rewind plus manual longitude normalisation.