The existing calculated route Feature with LineString geometry
Array of existing waypoints in order (origin, intermediate waypoints, destination)
The new waypoint to insert
A new array with the waypoint inserted at the optimal position
const route: Route = {
type: 'Feature',
id: 'route-1',
geometry: {
type: 'LineString',
coordinates: [[4.9, 52.3], [4.95, 52.35], [5.0, 52.4]]
},
properties: { ... },
bbox: [4.9, 52.3, 5.0, 52.4]
};
const waypoints: WaypointLike[] = [
[4.9, 52.3], // origin
[5.0, 52.4] // destination
];
const newWaypoint: WaypointLike = [4.95, 52.35];
const updatedWaypoints = withInsertedWaypoint(route, waypoints, newWaypoint);
// Returns: [[4.9, 52.3], [4.95, 52.35], [5.0, 52.4]]
Returns a new array of waypoints with the new waypoint inserted at the optimal position.
This is a convenience function that combines finding the best insertion index and inserting the waypoint in one step. It uses findBestWaypointInsertionIndex to determine where the waypoint fits most naturally along the route.