mapbox / mapbox/mapbox-gl-draw
Can't set multiple selected coordinates when switching to Direct Select mode
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
I'm writing a custom mode that lets a user box select over a Line feature to select multiple vertices, then pass them off to direct_select so they can be moved around or deleted.
This is convenient when the Line feature is a windy road or otherwise contains lots of vertices where shift + clicking each one would be a hassle.
The problem I'm running into is that Direct Select only accepts a single coordPath in onSetup, which means we can only pass a single vertex off to Direct Select mode.
To make this work, I've forked Direct Select mode and tweaked the above line of code so that the caller is responsible for passing a coordPath array, instead of expecting onSetup to wrap it:
selectedCoordPaths: opts.coordPath ? opts.coordPath : []
This gives me my expected result.

If it makes sense, I'm happy to push up a PR with this small change. Or maybe there's a more idiomatic way to do this that I'm not seeing :)
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 in src/modes/direct_select.js around line 131, where onSetup handles the coordPath passed to Direct Select mode. Trace how selected coordinates are stored and used after switching modes, then verify that multiple coordPaths can be accepted while retaining the existing single-coordinate behavior. Done means a custom mode can pass several selected vertices for moving or deletion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100