mapbox / mapbox/mapbox-gl-draw
Expose extra drawing mode events (e.g. onDragVertex, clickOnVertex, onMouseMove, clickAnywhere etc.)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
Hi There,
I have been working on extending the Mapbox GL Draw library to include some measuring tools (line and polygon) and have been building my own custom modes in order to enable this functionality.
Rather than having to build a custom mode, I initially explored trying to obtain the data that is currently being drawn through some of the callback events that are available with Mapbox GL Draw. Discovering that this is impossible, I had to go down the path of building my own custom modes.
I have built my custom measuring tools by extending the existing "draw_line_string" and "draw_polygon" modes that comes with Mapbox GL Draw. I wanted the measurements to be calculated 'live' as in while the user is actually drawing the line/polygon (not after the entire line/polygon has been drawn).
However now I am stuck with the issue of not being able to properly update the measurements when the user goes to re-edit the line. I have determined that this is due to the fact that when a geometry is being edited, Mapbox GL Draw is actually in "direct_select" mode, so in order to keep this functionality consistent I am now required to modify and extend the "direct_select" mode as well.
It seems that it would be simpler instead to include additional events which correspond to some of the events that internally available within the mode interface. In my particular case, I didn't actually need anything different than what was provided out-of-the-box for drawing lines and polygons. The only reason why I had to create a custom mode was to be able to access the geometry _while_ the user is drawing it.
I believe that most of the events (if not all) that are found within the mode interface should be exposed and accessible in the same way as the other draw events, i.e.
```
map.on('draw.#event_name#', (e) => {
...
});
```
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 by reading the existing draw_line_string, draw_polygon, and direct_select modes, then trace how their internal mode-interface events become public draw events. Define the event surface and behavior for drawing and editing, including access to geometry while it is in progress; done means the needed callbacks work without custom modes.
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