Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion src/features/common/Layout/ProjectPropsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { ReactElement } from 'react';
import { ParamsContext } from './QueryParamsContext';

interface Props {}

Expand Down Expand Up @@ -109,6 +110,7 @@ function ProjectPropsProvider({ children }: any): ReactElement {
const [filtersOpen, setFilterOpen] = React.useState(false);
const [purpose, setPurpose] = React.useState('trees');
const [plantLocationsLoaded, setPlantLocationsLoaded] = React.useState(false);
const { embed, showProjectList } = React.useContext(ParamsContext);

const mapRef = React.useRef(null);
const EMPTY_STYLE = {
Expand All @@ -123,7 +125,14 @@ function ProjectPropsProvider({ children }: any): ReactElement {
minZoom: 1,
maxZoom: 25,
});
const defaultMapCenter = isMobile ? [22.54, 9.59] : [36.96, -28.5];
const isEmbed = embed === 'true' && showProjectList === 'false';
const defaultMapCenter = isMobile
? isEmbed
? [22.54, 0]
: [22.54, 9.59]
: isEmbed
? [36.96, 0]
: [36.96, -28.5];
const defaultZoom = isMobile ? 1 : 1.4;
const [viewport, setViewPort] = React.useState({
width: Number('100%'),
Expand Down
13 changes: 12 additions & 1 deletion src/features/projects/components/ProjectsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function ProjectsMap(): ReactElement {
} = React.useContext(ProjectPropsContext);

const { t } = useTranslation(['maps']);
const { embed } = React.useContext(ParamsContext);
const { embed, showProjectList } = React.useContext(ParamsContext);
//Map
const _onStateChange = (state: any) => setMapState({ ...state });
const _onViewportChange = (view: any) => setViewPort({ ...view });
Expand Down Expand Up @@ -161,6 +161,17 @@ export default function ProjectsMap(): ReactElement {
}
}, [zoomLevel]);

React.useEffect(() => {
if (embed === 'true' && showProjectList === 'false') {
const newViewport = {
...viewport,
latitude: 36.96,
longitude: 0,
};
setViewPort(newViewport);
}
}, [showProjectList]);

return (
<div
className={
Expand Down