turf.booleanPointOnLine
What is turf.booleanPointOnLine?
turf.booleanPointOnLine returns true when a point lies on any segment of a LineString, within an optional epsilon tolerance.
turf.booleanPointOnLine(point, line, options?) → booleanOptions include:
ignoreEndVertices— iftrue, the line's start and end positions do not count as on-line (defaultfalse)epsilon— numeric tolerance for floating-point comparison
When would you use turf.booleanPointOnLine?
Use turf.booleanPointOnLine when validating that a snapped position really is on its target line — for example confirming that a marker dragged along a road is still on the road, or that a waypoint supplied by a user lies on a specific route rather than near it.
ignoreEndVertices is handy when you want to detect interior-only hits, for example when endpoint-matching is handled separately.
turf.booleanPointOnLine(snapped, route, { epsilon: 1e-9 });FAQs
How do I install Turf.js to use this function?
Install npm install @turf/boolean-point-on-line and import import { booleanPointOnLine } from '@turf/boolean-point-on-line', or use turf.booleanPointOnLine via @turf/turf.
How strict is the match?
By default it is exact. Pass epsilon (in degrees of coordinate difference) to allow a small tolerance — necessary when the point comes from a reprojected or rounded source.
Does it work on MultiLineString?
No, the line must be a single LineString. For MultiLineString, flatten with turf.flatten and iterate, or use turf.nearestPointOnLine + distance check.
When should I use booleanPointOnLine vs nearestPointOnLine?
Use booleanPointOnLine for a yes/no answer. Use turf.nearestPointOnLine when you need the actual closest point on the line or the distance to it.