Skip to content

Commit

Permalink
Merge pull request #45575 from bernhardoj/fix/44890-doesnt-center-on-…
Browse files Browse the repository at this point in the history
…waypoints-if-the-route-is-impossible-to-create

Fix the map is centered on the user if it is not possible to create a route
  • Loading branch information
MonilBhavsar authored Jul 18, 2024
2 parents d4aebb3 + 27e2e2e commit 6ec0f15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/MapView/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/components/MapView/MapView.website.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down

0 comments on commit 6ec0f15

Please sign in to comment.