turf.sector
What is turf.sector?
turf.sector returns a polygon shaped like a pie slice — two radial edges from a centre point plus the arc between two bearings at a given radius. It is the polygon counterpart to turf.lineArc.
turf.sector(center, radius, bearing1, bearing2, options?) → Feature<Polygon>Options include:
steps— vertices along the arc (default64)units—'kilometers'(default),'meters','miles','nauticalmiles','radians','degrees'properties— output feature properties
When would you use turf.sector?
Use turf.sector to draw field-of-view or directional-coverage polygons — a camera's visible cone, a radar or sonar sweep, an antenna coverage wedge, or a "time-of-flight" slice for a drone's flight window. On MapLibre, the output is a valid Polygon you can render with a semi-transparent fill layer.
In Node.js, combine turf.sector with turf.polygonTangents to build observer-to-polygon coverage visualisations — useful in visibility/line-of-sight applications.
undefinedFAQs
What happens when bearing2 equals bearing1?
The wedge degenerates — typically producing no polygon area. Use turf.circle instead for a full circle.
How do I install just sector?
npm install @turf/sector. It depends on @turf/helpers, @turf/invariant, @turf/destination, @turf/line-arc, and @turf/meta.
Does it work if bearing1 > bearing2?
Yes — the arc wraps around 360° correctly. Keep steps high enough to render the longer arc smoothly.
Can I use this for visibility analysis?
Yes — pair with turf.polygonTangents from an observer to a target building, take the two tangent bearings, and call turf.sector to draw the coverage wedge toward the target.