-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
242 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import MapboxDraw from '@mapbox/mapbox-gl-draw'; | ||
import { useControl } from 'react-map-gl'; | ||
|
||
// import type { MapRef } from 'react-map-gl'; | ||
|
||
type DrawControlProps = ConstructorParameters<typeof MapboxDraw>[0] & { | ||
onCreate?: (evt: { features: object[] }) => void; | ||
onUpdate?: (evt: { features: object[]; action: string }) => void; | ||
onDelete?: (evt: { features: object[] }) => void; | ||
onSelectionChange?: (evt: { selectedFeatures: object[] }) => void; | ||
}; | ||
|
||
export default function DrawControl(props: DrawControlProps) { | ||
useControl<MapboxDraw>( | ||
() => new MapboxDraw(props), | ||
({ map }: { map: any }) => { | ||
map.on('draw.create', props.onCreate); | ||
map.on('draw.update', props.onUpdate); | ||
map.on('draw.delete', props.onDelete); | ||
map.on('draw.selectionchange', props.onSelectionChange); | ||
}, | ||
({ map }: { map: any }) => { | ||
map.off('draw.create', props.onCreate); | ||
map.off('draw.update', props.onUpdate); | ||
map.off('draw.delete', props.onDelete); | ||
map.off('draw.selectionchange', props.onSelectionChange); | ||
}, | ||
{ | ||
position: 'top-left' | ||
} | ||
); | ||
|
||
return null; | ||
} |
37 changes: 37 additions & 0 deletions
37
app/scripts/components/common/map/controls/hooks/use-aois.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useAtomValue, useSetAtom } from 'jotai'; | ||
import { useCallback } from 'react'; | ||
import { Polygon } from 'geojson'; | ||
import { toAoIid } from '../../utils'; | ||
import { aoisDeleteAtom, aoisFeaturesAtom, aoisSetSelectedAtom, aoisUpdateGeometryAtom } from '$components/exploration/atoms/atoms'; | ||
|
||
export default function useAois() { | ||
const features = useAtomValue(aoisFeaturesAtom); | ||
|
||
const aoisUpdateGeometry = useSetAtom(aoisUpdateGeometryAtom); | ||
const onUpdate = useCallback( | ||
(e) => { | ||
const updates = e.features.map((f) => ({ id: toAoIid(f.id), geometry: f.geometry as Polygon })); | ||
aoisUpdateGeometry(updates); | ||
}, | ||
[aoisUpdateGeometry] | ||
); | ||
|
||
const aoiDelete = useSetAtom(aoisDeleteAtom); | ||
const onDelete = useCallback( | ||
(e) => { | ||
const selectedIds = e.features.map((f) => toAoIid(f.id)); | ||
aoiDelete(selectedIds); | ||
}, | ||
[aoiDelete] | ||
); | ||
|
||
const aoiSetSelected = useSetAtom(aoisSetSelectedAtom); | ||
const onSelectionChange = useCallback( | ||
(e) => { | ||
const selectedIds = e.features.map((f) => toAoIid(f.id)); | ||
aoiSetSelected(selectedIds); | ||
}, | ||
[aoiSetSelected] | ||
); | ||
return { features, onUpdate, onDelete, onSelectionChange }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters