TomTom Maps for JavaScript
    Preparing search index...

    Function withInsertedWaypoints

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

      The multi-waypoint variant of withInsertedWaypoint: it takes each new waypoint's slot from findBestWaypointInsertionIndices, and splices the new waypoints in along-route order, whatever their input order.

      Parameters

      • route: Route

        The existing calculated route, a Feature with LineString geometry.

      • existingWaypoints: WaypointLike[]

        The existing waypoints in order, from origin through intermediate waypoints to destination.

      • newWaypoints: WaypointLike[]

      Returns WaypointLike[]

      A new array with the waypoints inserted at their optimal positions.

      • Waypoints that project to the same location keep their input order.
      • It returns a new array and leaves existingWaypoints unmodified.
      • Passing an empty newWaypoints array returns a shallow copy of existingWaypoints.
      • When the route has fewer than 2 coordinates or there are 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]]