TomTom Maps for JavaScript
    Preparing search index...

    Function findBestWaypointInsertionIndices

    • Multi-waypoint variant of findBestWaypointInsertionIndex.

      Projects every existing and new waypoint onto the route exactly once, then returns one insertion slot per new waypoint. The i-th returned index is the slot in existingWaypoints (0 = before origin, existingWaypoints.length = after destination) where the i-th new waypoint falls based on its along-route location.

      Multiple new waypoints may share the same slot. Use withInsertedWaypoints when you also need them merged into the existing array in correct along-route order — that helper handles within-slot ranking on top of these slot indices.

      Parameters

      • route: Route

        The existing calculated route Feature with LineString geometry

      • existingWaypoints: WaypointLike[]

        Array of existing waypoints in order (origin, intermediate waypoints, destination)

      • newWaypoints: WaypointLike[]

        The waypoints whose insertion slots to compute

      Returns number[]

      An array of insertion slot indices, one per new waypoint, in input order

      • Empty newWaypoints returns an empty array.
      • Edge cases (empty route geometry, fewer than 2 existing waypoints) return 0 for every new waypoint — i.e. they would all prepend.
      • A new waypoint whose projection has no resolvable along-route location also returns 0, matching the singular findBestWaypointInsertionIndex behavior.