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 withInsertedWaypoints

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

      The multi-waypoint variant of withInsertedWaypoint. Unlike one-at-a-time insertion, it projects every existing and new waypoint onto the route exactly once, then merges them:

      1. It computes each new waypoint's insertion slot with findBestWaypointInsertionIndices.
      2. It ranks the new waypoints within each slot by along-route location. Waypoints that project to the same location keep their input order.

      The result holds the existing waypoints with the new ones spliced in at the right positions, in along-route order, whatever the 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.

      • 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]]