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

Function for custom styling of drawn polygons

Open SnailBones opened this issue 2 years ago • 0 comments

From https://github.com/mapbox/mapbox-gl-draw/issues/833#issuecomment-438673488

If this is something more people want, I could see a "styleFeature" function being added to Draw that would allow a user to set a features style. Internally this would add a style layer to the mapbox-gl-js that references that id of the feature.

draw.styleFeature('id', { style json })

The style json would be a paired down version of what is in the default styles, noting that filter, id and source would all need to be left off so that Draw could set them.

draw.styleFeature('id', null)

Would remove the style from the map as would draw.deleteFeature('id').

This issue is for discussing adding a new styleFeature() funciton to future versions of the library. For workarounds in the current version, see https://github.com/mapbox/mapbox-gl-draw/issues/833#issuecomment-437002873.

SnailBones avatar May 19 '22 23:05 SnailBones