Created
August 14, 2017 11:41
-
-
Save stephanbogner/c627d5bed660f3b676d08345f4f0d3d5 to your computer and use it in GitHub Desktop.
TurfJS Calculate bearing on a certain point on a line (with a buffer)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // import turf | |
| function bearingOnLine(feature, distance, buffer, units){ | |
| var lineDistance = turf.lineDistance(feature, units); | |
| buffer = buffer || lineDistance * 0.07; | |
| var measureFromDistance = Math.max(0, distance - buffer); | |
| var measureToDistance = Math.min(lineDistance, distance + buffer); | |
| var measureFrom = turf.along(feature, measureFromDistance, units); | |
| var measureTo = turf.along(feature, measureToDistance, units); | |
| var bearing = turf.bearing(measureFrom, measureTo); | |
| return bearing; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment