mapbox / mapbox/mapbox-gl-draw
How to pass `state` of mode to a custom mode method from outside of mode? (i.e. button on map)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
Hello,
I'm forking draw_polygon and direct_select modes into a single custom draw mode. While adding undo/redo feature I came into a problem. I can't access the state of draw mode from outside.
All native methods like onStop, onClick, onDrag etc. receive state, e as arguments. But if I add custom methods, I have to pass the state from native methods to them. It worked well for now, but when I added undo button to the map, I can't access pass the state from it cause I don't have it.
I probably need to create actionable. I can see them here, but I'm not sure how to add one of my own.
Or maybe I should scrap the idea of using state created by draw mode and implement it with my own state manager?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with docs/API.md and src/modes/object_to_mode.js, then trace how native methods such as onStop, onClick, and onDrag receive mode state. Determine whether custom actionables can expose the state to an external undo button or whether the issue requires a separate state manager; the result should establish and document one supported approach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100