Skip to content

Commit

Permalink
center map in scenario map
Browse files Browse the repository at this point in the history
  • Loading branch information
anamontiaga committed Sep 12, 2023
1 parent c48a284 commit b323409
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/layout/scenarios/edit/map/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useWDPACategories } from 'hooks/wdpa';
import Loading from 'components/loading';
import Map from 'components/map';
// Controls
import { MapProps } from 'components/map/component';
import Controls from 'components/map/controls';
import FitBoundsControl from 'components/map/controls/fit-bounds';
import LoadingControl from 'components/map/controls/loading';
Expand All @@ -47,6 +48,8 @@ export const ScenariosEditMap = (): JSX.Element => {
const [mapInteractive, setMapInteractive] = useState(false);
const [mapTilesLoaded, setMapTilesLoaded] = useState(false);

const { isSidebarOpen } = useAppSelector((state) => state['/projects/[id]']);

const accessToken = useAccessToken();

const { query } = useRouter();
Expand Down Expand Up @@ -111,6 +114,14 @@ export const ScenariosEditMap = (): JSX.Element => {

const { data: targetedFeaturesData } = useTargetedFeatures(sid, {});

useEffect(() => {
setBounds((prevState) => ({
...prevState,
viewportOptions: { transitionDuration: 1500 },
options: { padding: { top: 50, right: 50, bottom: 50, left: isSidebarOpen ? 575 : 50 } },
}));
}, [isSidebarOpen]);

const previewFeatureIsSelected = useMemo(() => {
if (tab === TABS['scenario-features']) {
return (
Expand Down Expand Up @@ -181,7 +192,7 @@ export const ScenariosEditMap = (): JSX.Element => {
const minZoom = 2;
const maxZoom = 20;
const [viewport, setViewport] = useState({});
const [bounds, setBounds] = useState(null);
const [bounds, setBounds] = useState<MapProps['bounds']>(null);

const include = useMemo(() => {
if (tab === TABS['scenario-protected-areas']) {
Expand Down

0 comments on commit b323409

Please sign in to comment.