Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not pass initial position at all if there is none #687

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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={
center ? { lng: center[0], lat: center[1], zoom } : undefined
}
cooperativeGestures
projection={projection}
onProjectionChange={allowProjectionChange ? setProjection : undefined}
Expand Down
Loading