This is the documentation of version 1.0.0-rc.4. Go to the latest version, 1.0.0-rc.5.
TomTom Maps for JavaScript
    Preparing search index...

    Function calculateProgressAtRoutePoint

    • Interpolates the cumulative traveled distance and time at an arbitrary point on the route path.

      Between the two RouteProgressPoint entries around pathIndex, the values follow the line's length rather than its vertex count, because vertices crowd into bends and thin out on straights.

      Parameters

      • route: Route

        The route whose properties.progress is interpolated. The progress array must cover the requested index, so the first entry's pointIndex must be ≤ pathIndex and the last's ≥ pathIndex.

      • pathIndex: number

        Zero-based index into the route's coordinate array.

      Returns Required<RouteProgress> | undefined

      The interpolated RouteProgressAtPoint, or undefined when:

      • the route has no progress data
      • pathIndex is outside [0, coordinates.length - 1]
      • pathIndex falls outside the range covered by the progress entries
      • any required distance or time value is missing from the bracketing entries
      const progress = route.properties.progress;
      // progress = [
      // { pointIndex: 0, distanceInMeters: 0, travelTimeInSeconds: 0 },
      // { pointIndex: 50, distanceInMeters: 2500, travelTimeInSeconds: 120 },
      // { pointIndex: 100,distanceInMeters: 5000, travelTimeInSeconds: 300 }
      // ]

      // With vertex 25 halfway along the line from vertex 0 to vertex 50:
      const result = calculateProgressAtRoutePoint(route, 25);
      // result = { distanceInMeters: 1250, travelTimeInSeconds: 60 }