Skip to content

Commit

Permalink
feat: add 100km validation to drawn areas
Browse files Browse the repository at this point in the history
  • Loading branch information
Prajwalism committed Jul 24, 2024
1 parent d4abdb9 commit f3b0e87
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { FeatureCollection } from 'geojson';
import { uploadAreaOptions } from '@Constants/createProject';
import { validateGeoJSON } from '@Utils/convertLayerUtils';
import Icon from '@Components/common/Icon';
import { toast } from 'react-toastify';
import MapSection from './MapSection';

export default function DefineAOI({
Expand Down Expand Up @@ -60,6 +61,20 @@ export default function DefineAOI({
dispatch(setCreateProjectState({ drawProjectAreaEnable: true }));
return;
}
const drawnArea =
drawnProjectArea && area(drawnProjectArea as FeatureCollection);
if (drawnArea && drawnArea > 1000000) {
toast.error('Drawn Area should not exceed 100km²');
dispatch(
setCreateProjectState({
drawProjectAreaEnable: false,
drawnProjectArea: null,
}),
);
// @ts-ignore
resetDrawTool();
return;
}
dispatch(
setCreateProjectState({
projectArea: drawnProjectArea,
Expand All @@ -77,6 +92,20 @@ export default function DefineAOI({
dispatch(setCreateProjectState({ drawNoFlyZoneEnable: true }));
return;
}
const drawnNoFlyZoneArea =
drawnProjectArea && area(drawnNoFlyZone as FeatureCollection);
if (drawnNoFlyZoneArea && drawnNoFlyZoneArea > 1000000) {
toast.error('Drawn Area should not exceed 100km²');
dispatch(
setCreateProjectState({
drawNoFlyZoneEnable: false,
drawnNoFlyZone: null,
}),
);
// @ts-ignore
resetDrawTool();
return;
}
dispatch(
setCreateProjectState({
noFlyZone: drawnNoFlyZone,
Expand Down Expand Up @@ -208,7 +237,7 @@ export default function DefineAOI({
Reset Project Area
</Button>
<p className="naxatw-mt-2 naxatw-text-body-md">
Total Area: {Math.trunc(totalProjectArea as number)} m2
Total Area: {Math.trunc(totalProjectArea as number)}
</p>
<div className="naxatw-mt-2">
<RadioButton
Expand Down

0 comments on commit f3b0e87

Please sign in to comment.