Skip to content

Commit

Permalink
Actually delete all polygons
Browse files Browse the repository at this point in the history
  • Loading branch information
nerik authored and danielfdsilva committed Oct 25, 2023
1 parent d8a7b49 commit 26a98b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/scripts/components/common/map/controls/aoi/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ export const aoisDeleteAtom = atom(null, (get, set, ids: string[]) => {
);
set(aoisSerialized, encodeAois(newFeatures));
});

export const aoiDeleteAllAtom = atom(null, (get, set) => {
set(aoisSerialized, encodeAois([]));
});
1 change: 1 addition & 0 deletions app/scripts/components/common/map/controls/aoi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function DrawControl(props: DrawControlProps) {
return control.current;
},
({ map }: { map: any }) => {
map._drawControl = control.current;
map.on('draw.create', onUpdate);
map.on('draw.update', onUpdate);
map.on('draw.delete', onDelete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React, { useCallback } from 'react';
import { CollecticonArrowLoop } from '@devseed-ui/collecticons';
import { Button, createButtonStyles } from '@devseed-ui/button';
import styled from 'styled-components';
import { useSetAtom } from 'jotai';
import { themeVal } from '@devseed-ui/theme-provider';
import useThemedControl from '../hooks/use-themed-control';
import useMaps from '../../hooks/use-maps';
import { aoiDeleteAllAtom } from './atoms';

const SelectorButton = styled(Button)`
&&& {
Expand All @@ -20,11 +22,13 @@ const SelectorButton = styled(Button)`
`;

function ResetAoI({ map }: { map: any }) {
const aoiDeleteAll = useSetAtom(aoiDeleteAllAtom)
const onReset = useCallback(() => {
const mbDraw = map?.instance?._drawControl;
const mbDraw = map?._drawControl;
if (!mbDraw) return;
mbDraw.trash();
}, [map]);
mbDraw.deleteAll();
aoiDeleteAll();
}, [map, aoiDeleteAll]);

return (
<>
Expand Down

0 comments on commit 26a98b6

Please sign in to comment.