-
Notifications
You must be signed in to change notification settings - Fork 6
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
Reset AoIs #707
Reset AoIs #707
Conversation
✅ Deploy Preview for veda-ui ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
export default function ResetAoIControl() { | ||
useThemedControl( | ||
() => { | ||
return <ResetAoI />; | ||
}, | ||
{ | ||
position: 'top-left' | ||
} | ||
); | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to access the context here and pass it as a prop to ResetAoI
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion: d102d80
However instance
doesn't exist on this map ref for some reason.
I could create a specific context for this map implementation in order for the draw control to expose its internals for other draw-related controls, but this really feels like a hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is instance
coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous ref
implementation had an instance
because we added it since it served our needs.
veda-ui/app/scripts/components/common/mapbox/index.tsx
Lines 168 to 175 in 1bb5c5e
useImperativeHandle(ref, () => ({ | |
resize: () => { | |
mapRef.current?.resize(); | |
mapCompareRef.current?.resize(); | |
}, | |
instance: mapRef.current, | |
compareInstance: mapCompareRef.current | |
})); |
And then the map stored the draw control so we can act on it, but none of this is default.
veda-ui/app/scripts/components/common/mapbox/aoi/mb-aoi-draw.js
Lines 32 to 40 in 1bb5c5e
const newMbDraw = new MapboxDraw({ | |
modes: MapboxDraw.modes, | |
displayControlsDefault: false, | |
styles: computeDrawStyles(theme) | |
}); | |
mbDrawRef.current = newMbDraw; | |
mbMap.addControl(newMbDraw, 'top-left'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A solution for this implementation could be to add a reference to the control when it is mounted:
@app/scripts/components/common/map/controls/aoi/index.tsx
useControl<MapboxDraw>(
- () => {
+ ({map}) => {
control.current = new MapboxDraw(props);
+ map._drawControl = control.current;
return control.current;
},
Then you could access it via map._drawControl
on the reset button
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However for the clear button I don't think you need to access the trash
method. Using this without a selection does nothing.
I'd imagine that deleting all the feature via the atom would do the trick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a brief conversation with Erik at the end of last week and this is at a point where it is working. For example: veda-ui/app/scripts/components/common/map/controls/aoi/reset-aoi-control.tsx Lines 25 to 30 in 2f1e5f0
Here, the features are being deleted from the draw plugin and at the same time from the atom that stores them. There no absolutely clean way to do this though. We are working with a mapbox plugin that is imperative by nature. This same behavior could be migrated to this implementation but it would require some additional work and changes. Do you have any thoughts @hanbyul-here @sandrahoang686? Do you feel that this is worth it? |
We would eventually want to have one place that syncs these states, but I think it is acceptable to file this as a tech debt and move on for now. |
2f1e5f0
to
479b719
Compare
Rebased to fix the conflict and logged the tech debt. |
479b719
to
733f10c
Compare
This adds a reset button as suggested here
Unfortunately, I couldn't get this to work. The control needs access to the map ref, which is stored in the MapsContext (reachable via the
useMaps
hook), butuseThemedControls
creates a separated React root, hence without access to any context.I've been looking for hours for a clean solution but I'm stuck, sorry :(