TomTom Maps for JavaScript
    Preparing search index...

    Function withInsertedWaypoints

    • Returns a new array of waypoints with each new waypoint inserted at its optimal position.

      Multi-waypoint variant of withInsertedWaypoint. Unlike a sequential one-at-a-time insertion, this function projects every existing and new waypoint onto the route exactly once, then merges them by:

      1. Computing each new waypoint's insertion slot via findBestWaypointInsertionIndices.
      2. Within each slot, ranking the new waypoints by their along-route location (with a stable tie-break on input order when multiple waypoints project to the same location).

      The result is the existing waypoints with newcomers spliced in at the right positions and in natural along-route order — accurate regardless of input order.

      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 to insert

      Returns WaypointLike[]

      A new array with the waypoints inserted at their optimal positions

      • Returns a new array; does not modify the original existingWaypoints array.
      • Passing an empty newWaypoints array returns a shallow copy of existingWaypoints.
      • When the route has no geometry or fewer than 2 existing waypoints, all new waypoints are prepended in input order.
      const waypoints: WaypointLike[] = [
      [4.9, 52.3], // origin
      [5.0, 52.4] // destination
      ];

      const updated = withInsertedWaypoints(route, waypoints, [[4.97, 52.37], [4.93, 52.33]]);
      // → [[4.9, 52.3], [4.93, 52.33], [4.97, 52.37], [5.0, 52.4]]