Skip to content

Commit

Permalink
Do not pass initial position at all if there is none
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Sep 28, 2023
1 parent aedbf51 commit d12b444
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions app/scripts/components/common/blocks/block-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ interface MapBlockProps extends Pick<MapboxMapProps, 'datasetId' | 'layerId'> {
projectionCenter?: ProjectionOptions['center'];
projectionParallels?: ProjectionOptions['parallels'];
allowProjectionChange?: boolean;
basemapId?: BasemapId
basemapId?: BasemapId;
}

function MapBlock(props: MapBlockProps) {
Expand Down Expand Up @@ -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 (
<Carto>
Expand All @@ -176,7 +176,9 @@ function MapBlock(props: MapBlockProps) {
isComparing={!!selectedCompareDatetime}
compareDate={selectedCompareDatetime}
compareLabel={compareLabel}
initialPosition={{ lng: center?.[0], lat: center?.[1], zoom }}
initialPosition={

Check failure on line 179 in app/scripts/components/common/blocks/block-map.tsx

View workflow job for this annotation

GitHub Actions / ts-check

No overload matches this call.
center ? { lng: center[0], lat: center[1], zoom } : null
}
cooperativeGestures
projection={projection}
onProjectionChange={allowProjectionChange ? setProjection : undefined}
Expand Down

0 comments on commit d12b444

Please sign in to comment.