From af173870fa08d1a671dad50eac0a8d0894c5be3d Mon Sep 17 00:00:00 2001 From: Marcin Zelent Date: Mon, 5 Dec 2022 11:22:13 +0100 Subject: Fixed crash when no photos have geodata --- src/components/Map/Map.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/components') diff --git a/src/components/Map/Map.tsx b/src/components/Map/Map.tsx index 33b9970..e9ba6c1 100644 --- a/src/components/Map/Map.tsx +++ b/src/components/Map/Map.tsx @@ -41,7 +41,7 @@ export default function Map({ group, handleMarkerClick }: Props): JSX.Element { const bounds = useMemo(() => { if (group === undefined || (group.geoData === undefined && displayedMedia.length === 0)) { - return new LatLngBounds([75, -145], [-52, 145]); + return; } const latitudes = displayedMedia.map((p) => p.latitude) as number[]; @@ -56,6 +56,10 @@ export default function Map({ group, handleMarkerClick }: Props): JSX.Element { } }); + if (latitudes.length === 0 || longitudes.length === 0) { + return; + } + const minLatitude = Math.min(...latitudes); const minLongitude = Math.min(...longitudes); const maxLatitude = Math.max(...latitudes); @@ -112,12 +116,18 @@ export default function Map({ group, handleMarkerClick }: Props): JSX.Element { } const mapBounds = useMemo(() => { - function MapBounds({ bounds }: { bounds: LatLngBounds }): JSX.Element { + function MapBounds({ bounds }: { bounds: LatLngBounds | undefined }): JSX.Element { const map = useMap(); - if (map !== undefined) { + if (map === undefined) { + return <>; + } + + if (bounds !== undefined) { map.setView(bounds.getCenter()); map.fitBounds(bounds, { padding: [40, 40] }); + } else { + map.fitWorld(); } return <>; -- cgit v1.2.3