title: How to calculate a distance between two points along a path?
body: <p>I'm using openlayers3 and I have the encoded geometry. I can get the coordinates (lat,lng) for all points in the path (around 500 points per path). Given a random point inside the path, how do I calculate the distance between the beginning of the path up to that point?</p>
  
  <p>I've taken a look at turfjs and it looks very promising, but the solution I pictured using it wouldn't be very nice. Taking a random point (p1), I could discover the point (p2) of the path that is closest to p1, then generate a new polygon and calculate its total distance. It may have performance issues, although the search would be O(log n) and the new polygon O(n).</p>
  
  <p>EDIT: the random point is not necessarily inside the path, it's a GPS coordinate and there's a margin for error.</p>
  
  <p>EDIT 2: estimation on the number of points was off, each path has about 500 points, not 5k</p>
  
  <p>Does anyone know of a better approach? I'm not very experienced with either openlayers3 nor turfjs.</p>