mapbox-gl-draw icon indicating copy to clipboard operation
mapbox-gl-draw copied to clipboard

Ability to support custom control points (modify createSupplementaryPoints)

Open stevage opened this issue 4 years ago • 0 comments

I'm currently implementing a custom mode to draw and edit curves following the WKT model (three points on a circular arc).

One issue that is quite awkward to deal with is that that createSupplementaryPoints is called by simple_select and direct_select and always places a control point (draggable vertex) on every vertex in the feature. The only way to change this behaviour is to duplicate and modify that createSupplementaryPoints function with a slightly different one, and then duplicate and monkey-patch simple_select and direct_select to call it. (It's not possible to monkey-patch createSupplementaryPoints because it's a function, not a method...)

You can see this same approach taken by someone else here:

https://github.com/iamanvesh/mapbox-gl-draw-circle/blob/master/lib/modes/SimpleSelectModeOverride.js#L41

I imagine other custom mode designers have run into similar issues: there are probably other kinds of shapes that want to have custom control points that aren't necessarily at every vertex (nor necessarily even at vertices).

I'm not sure exactly what the best design would be, but perhaps something like:

  • an optional property on features, controlPoints. If this is present, draggable vertices are placed there rather than at the default vertices.
  • simple_select and direct_select modified to call this.

I'm not sure what the default behaviour for direct_select should be if those control points are dragged though, since it wouldn't really know what to do with them. Maybe it should call a new method dragControlPoint which just logs a warning that this method should be overridden?

Happy to have a go at implementing this with some guidance/commentary about whether this is an acceptable path. @mourner ?

stevage avatar Aug 19 '21 01:08 stevage