From b13279bb536e6593b31f07d824577d36d1650982 Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Thu, 28 Sep 2023 17:04:51 -0400 Subject: [PATCH] Do not pass initial position at all if there is none --- .../components/common/blocks/block-map.tsx | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/app/scripts/components/common/blocks/block-map.tsx b/app/scripts/components/common/blocks/block-map.tsx index 8539e420e..9a5b88e61 100644 --- a/app/scripts/components/common/blocks/block-map.tsx +++ b/app/scripts/components/common/blocks/block-map.tsx @@ -100,7 +100,7 @@ interface MapBlockProps extends Pick { projectionCenter?: ProjectionOptions['center']; projectionParallels?: ProjectionOptions['parallels']; allowProjectionChange?: boolean; - basemapId?: BasemapId + basemapId?: BasemapId; } function MapBlock(props: MapBlockProps) { @@ -134,37 +134,37 @@ function MapBlock(props: MapBlockProps) { ? utcString2userTzDate(compareDateTime) : undefined; - const projectionStart = useMemo(() => { - if (projectionId) { - // Ensure that the default center and parallels are used if none are - // provided. - const projection = convertProjectionToMapbox({ - id: projectionId, - center: projectionCenter, - parallels: projectionParallels - }); - return { - ...projection, - id: projectionId - }; - } else { - return projectionDefault; - } - }, [projectionId, projectionCenter, projectionParallels]); - - const [projection, setProjection] = useState(projectionStart); - - useEffect(() => { - setProjection(projectionStart); - }, [projectionStart]); - - const [mapBasemapId, setMapBasemapId] = useState(basemapId); - - useEffect(() => { - if (!basemapId) return; - - setMapBasemapId(basemapId); - }, [basemapId]); + const projectionStart = useMemo(() => { + if (projectionId) { + // Ensure that the default center and parallels are used if none are + // provided. + const projection = convertProjectionToMapbox({ + id: projectionId, + center: projectionCenter, + parallels: projectionParallels + }); + return { + ...projection, + id: projectionId + }; + } else { + return projectionDefault; + } + }, [projectionId, projectionCenter, projectionParallels]); + + const [projection, setProjection] = useState(projectionStart); + + useEffect(() => { + setProjection(projectionStart); + }, [projectionStart]); + + const [mapBasemapId, setMapBasemapId] = useState(basemapId); + + useEffect(() => { + if (!basemapId) return; + + setMapBasemapId(basemapId); + }, [basemapId]); return ( @@ -176,7 +176,9 @@ function MapBlock(props: MapBlockProps) { isComparing={!!selectedCompareDatetime} compareDate={selectedCompareDatetime} compareLabel={compareLabel} - initialPosition={{ lng: center?.[0], lat: center?.[1], zoom }} + initialPosition={ + center ? { lng: center[0], lat: center[1], zoom } : undefined + } cooperativeGestures projection={projection} onProjectionChange={allowProjectionChange ? setProjection : undefined}