Skip to content

Commit

Permalink
Remove obsolete code and add a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dzole0311 committed Oct 25, 2024
1 parent ae793f7 commit 588fd8b
Showing 1 changed file with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,34 +325,21 @@ export default function CustomAoIControl({
const { main } = useMaps();
const { isDrawing } = useAois();

// Start/stop the drawing.
// Start the drawing mode when isDrawing is true
// There's no need to switch back to 'simple_select' mode when !isDrawing
// as Mapbox Draw handles this internally when the drawing is completed
useEffect(() => {
if (!main) return;

const changeDrawMode = () => {
const mbDraw = main._drawControl;
if (!mbDraw) return;
const mbDraw = main._drawControl;

if (isDrawing) {
mbDraw.changeMode(DRAW_POLYGON);
} else {
mbDraw.changeMode(SIMPLE_SELECT, {
featureIds: mbDraw.getSelectedIds()
});
}
};
if (!mbDraw) return;

if (main.loaded()) {
changeDrawMode();
} else {
main.on('load', changeDrawMode);
return () => {
main.off('load', changeDrawMode);
};
if (isDrawing) {
mbDraw.changeMode(DRAW_POLYGON);
}
}, [main, isDrawing]);


useThemedControl(
() => <CustomAoI map={main} disableReason={disableReason} />,
{
Expand Down

0 comments on commit 588fd8b

Please sign in to comment.