turf.square
What is turf.square?
turf.square takes a bounding box array [minX, minY, maxX, maxY] and returns the smallest square bbox that fully contains it, expanding the shorter dimension symmetrically around the original centre.
turf.square(bbox) → BBoxWhen would you use turf.square?
Use turf.square when you need a square viewport or tile around an arbitrary feature — for example, computing a 1:1 aspect thumbnail for a static map, snapping camera targets to a square footprint for consistent UI cards, or constraining a viewport to a symmetric extent around a user selection.
In Node.js you can combine turf.bbox with turf.square to generate standardised square extents for batch map rendering, ensuring consistent output aspect without manual padding math.
undefinedFAQs
Does square preserve the original centre?
Yes. The expansion is symmetric around the centre of the short dimension, so the feature stays centred inside the resulting square bbox.
How do I install just square?
npm install @turf/square. It depends only on @turf/distance and @turf/helpers, so the footprint is small.
Is the square measured in degrees or metres?
The expansion uses geodetic distance so the square is approximately equal-sided on the ground, not in raw longitude/latitude. Near the poles it is noticeably non-square in degree coordinates because a degree of longitude covers much less ground.
Does it return a polygon or a bbox array?
A bbox array. For a polygon, wrap the result with turf.bboxPolygon.