Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/analysis flow #677

Merged
merged 18 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
25 changes: 22 additions & 3 deletions app/scripts/components/analysis/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FeatureCollection, Polygon } from 'geojson';
import { makeFeatureCollection } from '$components/common/aoi/utils';
import { featureCollection } from '@turf/helpers';

export type RegionPreset = 'world';
export type RegionPreset = 'world' | 'north-america';

export const FeatureByRegionPreset: Record<
RegionPreset,
FeatureCollection<Polygon>
> = {
world: makeFeatureCollection([
world: featureCollection([
{
type: 'Feature',
id: 'world',
Expand All @@ -25,6 +25,25 @@ export const FeatureByRegionPreset: Record<
type: 'Polygon'
}
}
]),
'north-america': featureCollection([
{
type: 'Feature',
id: 'north-america',
properties: {},
geometry: {
coordinates: [
[
[-180, 0],
[-180, 89],
[-60, 89],
[-60, 0],
[-180, 0]
]
],
type: 'Polygon'
}
}
])
};

Expand Down
43 changes: 34 additions & 9 deletions app/scripts/components/analysis/define/aoi-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState
} from 'react';
import styled from 'styled-components';
Expand All @@ -19,20 +20,19 @@ import {
import { Button, ButtonGroup } from '@devseed-ui/button';
import { Dropdown, DropMenu, DropTitle } from '@devseed-ui/dropdown';
import {
CollecticonArrowLoop,
CollecticonTrashBin,
CollecticonHandPan,
CollecticonMarker,
CollecticonPencil,
CollecticonUpload2
} from '@devseed-ui/collecticons';
import { FeatureByRegionPreset, RegionPreset } from '../constants';
import AoIUploadModal from './aoi-upload-modal';
import { FoldWGuideLine, FoldTitleWOAccent } from '.';
import {
Fold,
FoldHeader,
FoldHeadline,
FoldHeadActions,
FoldTitle,
FoldBody
} from '$components/common/fold';
import MapboxMap, { MapboxMapRef } from '$components/common/mapbox';
Expand All @@ -43,6 +43,7 @@ import {
import DropMenuItemButton from '$styles/drop-menu-item-button';
import { makeFeatureCollection } from '$components/common/aoi/utils';
import { variableGlsp } from '$styles/variable-utils';
import { useEffectPrevious } from '$utils/use-effect-previous';

const MapContainer = styled.div`
position: relative;
Expand Down Expand Up @@ -76,6 +77,19 @@ export default function AoiSelector({
}: AoiSelectorProps) {
const { drawing, featureCollection } = aoiDrawState;

// TODO revise this. This is not a great hack aimed at initializing the AoI with North America when
// no qs AoI is set. Ideally this would be set in use-analysis-params initialState.
const timeOutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => {
if (!qsAoi) {
timeOutRef.current = setTimeout(() => {
setFeatureCollection(FeatureByRegionPreset['north-america']);
}, 100);
} else {
if (timeOutRef.current) clearTimeout(timeOutRef.current);
}
}, [qsAoi]);

// For the drawing tool, the features need an id.
const qsFc: FeatureCollection<Polygon> | null = useMemo(() => {
return qsAoi
Expand Down Expand Up @@ -120,24 +134,28 @@ export default function AoiSelector({
const [aoiModalRevealed, setAoIModalRevealed] = useState(false);

return (
<Fold>
<FoldWGuideLine number={1}>
<AoIUploadModal
setFeatureCollection={setFeatureCollection}
revealed={aoiModalRevealed}
onCloseClick={() => setAoIModalRevealed(false)}
/>
<FoldHeader>
<FoldHeadline>
<FoldTitle>Area</FoldTitle>
<FoldTitleWOAccent>Select area of interest</FoldTitleWOAccent>
<p>
Use the pencil tool to draw a shape on the map or upload your own
shapefile.
</p>
</FoldHeadline>
<AoiHeadActions>
<Toolbar>
<ToolbarIconButton
variation='primary-fill'
variation='danger-fill'
onClick={() => onAoiEvent('aoi.clear')}
disabled={!featureCollection?.features.length}
>
<CollecticonArrowLoop title='Clear map' meaningful />
<CollecticonTrashBin title='Clear map' meaningful />
</ToolbarIconButton>
<VerticalDivider variation='dark' />
<ButtonGroup variation='primary-fill'>
Expand Down Expand Up @@ -170,7 +188,7 @@ export default function AoiSelector({
</ToolbarIconButton>
)}
>
<DropTitle>Select a region (BETA)</DropTitle>
<DropTitle>Select a region</DropTitle>
<DropMenu>
<li>
<DropMenuItemButton
Expand All @@ -179,6 +197,13 @@ export default function AoiSelector({
World
</DropMenuItemButton>
</li>
<li>
<DropMenuItemButton
onClick={() => onRegionPresetClick('north-america')}
>
North America
</DropMenuItemButton>
</li>
</DropMenu>
</Dropdown>
</Toolbar>
Expand All @@ -194,6 +219,6 @@ export default function AoiSelector({
/>
</MapContainer>
</FoldBody>
</Fold>
</FoldWGuideLine>
);
}
Loading