mapbox / mapbox/mapbox-gl-draw

Can't set multiple selected coordinates when switching to Direct Select mode

Open
#967 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged feature
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.

https://github.com/mapbox/mapbox-gl-draw/blob/e3edcc29a5fffdcdc416cbad4dfe118f38f0c845/src/modes/direct_select.js#L131

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.

box-select-mapbox

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.