From fb2a0243c6df29c7221837205902902ff63a9b4d Mon Sep 17 00:00:00 2001 From: Kesar Sidhu Date: Fri, 3 Jul 2026 09:46:03 -0700 Subject: [PATCH] feat(results): close route loop back to start on map Append the starting point (depot, or first stop when no depot) to the end of each route path so the polyline shows the drive home, even though the optimizer output omits the return leg. Applies to road-following and straight-line fallback paths, and includes the return leg in distance. Co-authored-by: Cursor --- app/ui/src/app/results/components/Map.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/ui/src/app/results/components/Map.tsx b/app/ui/src/app/results/components/Map.tsx index aaefaa5d..88ef5855 100644 --- a/app/ui/src/app/results/components/Map.tsx +++ b/app/ui/src/app/results/components/Map.tsx @@ -153,13 +153,19 @@ function buildRoutePath( } return { lat: s.lat, lng: s.lng }; }); - if (route.startLocation) { - return [ - { lat: route.startLocation.lat, lng: route.startLocation.lng }, - ...deliveryPoints, - ]; + const points = route.startLocation + ? [ + { lat: route.startLocation.lat, lng: route.startLocation.lng }, + ...deliveryPoints, + ] + : deliveryPoints; + // Close the loop so the map shows the drive back home: the last stop connects + // to the starting point (depot, or the first stop when no depot is provided), + // even though the optimizer output does not include the return leg. + if (points.length >= 2) { + points.push({ ...points[0]! }); } - return deliveryPoints; + return points; } function RoutePolylinesOverlay({