From 05ab7ed1920b2e55f517cea7dc73c16f13d8fac7 Mon Sep 17 00:00:00 2001 From: Rakshit Jain Date: Fri, 29 Sep 2023 01:29:08 +0530 Subject: [PATCH 1/2] added coordinates in get bounds --- src/components/MapView/MapView.tsx | 8 +++++--- src/components/MapView/MapView.web.tsx | 7 +++++-- src/components/MapView/utils.ts | 6 +++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx index 9370cc95fb82..09599e3b93d9 100644 --- a/src/components/MapView/MapView.tsx +++ b/src/components/MapView/MapView.tsx @@ -39,14 +39,17 @@ const MapView = forwardRef(({accessToken, style, ma centerCoordinate: waypoints[0].coordinate, }); } else { - const {southWest, northEast} = utils.getBounds(waypoints.map((waypoint) => waypoint.coordinate)); + const {southWest, northEast} = utils.getBounds( + waypoints.map((waypoint) => waypoint.coordinate), + directionCoordinates, + ); cameraRef.current?.fitBounds(northEast, southWest, mapPadding, 1000); } } return () => { setIsIdle(false); }; - }, [mapPadding, waypoints, isIdle]), + }, [mapPadding, waypoints, isIdle, directionCoordinates]), ); useEffect(() => { @@ -71,7 +74,6 @@ const MapView = forwardRef(({accessToken, style, ma onMapIdle={setMapIdle} pitchEnabled={pitchEnabled} attributionPosition={{...styles.r2, ...styles.b2}} - scaleBarEnabled={false} logoPosition={{...styles.l2, ...styles.b2}} // eslint-disable-next-line {...responder.panHandlers} diff --git a/src/components/MapView/MapView.web.tsx b/src/components/MapView/MapView.web.tsx index 52f953e0d3bd..78c5a9175594 100644 --- a/src/components/MapView/MapView.web.tsx +++ b/src/components/MapView/MapView.web.tsx @@ -43,9 +43,12 @@ const MapView = forwardRef( const map = mapRef.getMap(); - const {northEast, southWest} = utils.getBounds(waypoints.map((waypoint) => waypoint.coordinate)); + const {northEast, southWest} = utils.getBounds( + waypoints.map((waypoint) => waypoint.coordinate), + directionCoordinates, + ); map.fitBounds([northEast, southWest], {padding: mapPadding}); - }, [waypoints, mapRef, mapPadding]); + }, [waypoints, mapRef, mapPadding, directionCoordinates]); useEffect(() => { if (!mapRef) { diff --git a/src/components/MapView/utils.ts b/src/components/MapView/utils.ts index c37d272296e5..b2c8fcad787b 100644 --- a/src/components/MapView/utils.ts +++ b/src/components/MapView/utils.ts @@ -1,6 +1,10 @@ -function getBounds(waypoints: Array<[number, number]>): {southWest: [number, number]; northEast: [number, number]} { +function getBounds(waypoints: Array<[number, number]>, directionCoordinates: undefined | Array<[number, number]>): {southWest: [number, number]; northEast: [number, number]} { const lngs = waypoints.map((waypoint) => waypoint[0]); const lats = waypoints.map((waypoint) => waypoint[1]); + if (directionCoordinates) { + lngs.push(...directionCoordinates.map((coordinate) => coordinate[0])); + lats.push(...directionCoordinates.map((coordinate) => coordinate[1])); + } return { southWest: [Math.min(...lngs), Math.min(...lats)], From ce095329bbf0708cd9b3ad9d4b59f326f3e22730 Mon Sep 17 00:00:00 2001 From: Rakshit Jain Date: Sun, 1 Oct 2023 11:01:26 +0530 Subject: [PATCH 2/2] merge fix --- src/components/MapView/MapView.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx index 09599e3b93d9..a7155082ad86 100644 --- a/src/components/MapView/MapView.tsx +++ b/src/components/MapView/MapView.tsx @@ -74,6 +74,7 @@ const MapView = forwardRef(({accessToken, style, ma onMapIdle={setMapIdle} pitchEnabled={pitchEnabled} attributionPosition={{...styles.r2, ...styles.b2}} + scaleBarEnabled={false} logoPosition={{...styles.l2, ...styles.b2}} // eslint-disable-next-line {...responder.panHandlers}