From 7d6e381bc0789e52d2273b01b02acf8f03d93a71 Mon Sep 17 00:00:00 2001
From: Bernhard Owen Josephus <bernhard.josephus@gmail.com>
Date: Wed, 17 Jul 2024 16:28:56 +0800
Subject: [PATCH 1/2] center on map when the waypoint coordinates exist

---
 src/components/MapView/MapView.tsx         | 3 ++-
 src/components/MapView/MapView.website.tsx | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx
index 553be816cf3f..6b2c5cc22220 100644
--- a/src/components/MapView/MapView.tsx
+++ b/src/components/MapView/MapView.tsx
@@ -157,7 +157,8 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
             }
         };
         const centerMap = useCallback(() => {
-            if (directionCoordinates && directionCoordinates.length > 1) {
+            const waypointCoordinates = waypoints?.map((waypoint) => waypoint.coordinate) ?? [];
+            if (waypointCoordinates.length > 1 || ((directionCoordinates ?? []).length) > 1) {
                 const {southWest, northEast} = utils.getBounds(waypoints?.map((waypoint) => waypoint.coordinate) ?? [], directionCoordinates);
                 cameraRef.current?.fitBounds(southWest, northEast, mapPadding, CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME);
                 return;
diff --git a/src/components/MapView/MapView.website.tsx b/src/components/MapView/MapView.website.tsx
index c8f4e9bb38fc..105a775552aa 100644
--- a/src/components/MapView/MapView.website.tsx
+++ b/src/components/MapView/MapView.website.tsx
@@ -194,7 +194,8 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
             if (!mapRef) {
                 return;
             }
-            if (directionCoordinates && directionCoordinates.length > 1) {
+            const waypointCoordinates = waypoints?.map((waypoint) => waypoint.coordinate) ?? [];
+            if (waypointCoordinates.length > 1 || ((directionCoordinates ?? []).length) > 1) {
                 const {northEast, southWest} = utils.getBounds(waypoints?.map((waypoint) => waypoint.coordinate) ?? [], directionCoordinates);
                 const map = mapRef?.getMap();
                 map?.fitBounds([southWest, northEast], {padding: mapPadding, animate: true, duration: CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME});

From 27e2e2ee3fec87e2bdfcdccf59e59fcbd667da59 Mon Sep 17 00:00:00 2001
From: Bernhard Owen Josephus <bernhard.josephus@gmail.com>
Date: Wed, 17 Jul 2024 17:26:44 +0800
Subject: [PATCH 2/2] prettier

---
 src/components/MapView/MapView.tsx         | 2 +-
 src/components/MapView/MapView.website.tsx | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx
index 6b2c5cc22220..57eec0510114 100644
--- a/src/components/MapView/MapView.tsx
+++ b/src/components/MapView/MapView.tsx
@@ -158,7 +158,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
         };
         const centerMap = useCallback(() => {
             const waypointCoordinates = waypoints?.map((waypoint) => waypoint.coordinate) ?? [];
-            if (waypointCoordinates.length > 1 || ((directionCoordinates ?? []).length) > 1) {
+            if (waypointCoordinates.length > 1 || (directionCoordinates ?? []).length > 1) {
                 const {southWest, northEast} = utils.getBounds(waypoints?.map((waypoint) => waypoint.coordinate) ?? [], directionCoordinates);
                 cameraRef.current?.fitBounds(southWest, northEast, mapPadding, CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME);
                 return;
diff --git a/src/components/MapView/MapView.website.tsx b/src/components/MapView/MapView.website.tsx
index 105a775552aa..618dd5b24cf5 100644
--- a/src/components/MapView/MapView.website.tsx
+++ b/src/components/MapView/MapView.website.tsx
@@ -195,7 +195,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
                 return;
             }
             const waypointCoordinates = waypoints?.map((waypoint) => waypoint.coordinate) ?? [];
-            if (waypointCoordinates.length > 1 || ((directionCoordinates ?? []).length) > 1) {
+            if (waypointCoordinates.length > 1 || (directionCoordinates ?? []).length > 1) {
                 const {northEast, southWest} = utils.getBounds(waypoints?.map((waypoint) => waypoint.coordinate) ?? [], directionCoordinates);
                 const map = mapRef?.getMap();
                 map?.fitBounds([southWest, northEast], {padding: mapPadding, animate: true, duration: CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME});
