-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It's possible to style drawn polygons and polylines? #833
Comments
@EmiSan1998 Draw provides some default styles that are defined here. This JSON is the layer section of the Mapbox Style Spec without the To create a custom style for Draw you can either set the styles option when setting up Draw and follow these directions for styling. As you want custom per feature styles you'll want to set Another option is to use mapbox-gl-js's addLayer function. The Draw option will be a bit harder if you don't know the number of unique layers you will need and the |
I also need the same effect |
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.
The style json would be a paired down version of what is in the default styles, noting that
Would remove the style from the map as would Thoughts? |
Sorry for the late answer but I was very busy with more urgent features of my application. I'd love a styleFeature method and I hope to see it in future Mapbox versions. Keep me updated! |
I would also love to see this. |
There is any hope to have this feature? |
Hope this will be helpful. |
@sameerabit Yep I found it the other day - it was really helpful, thanks! |
Thank you, with proper modification for my particular application it did the trick for me! |
Hi, |
hi, i also hit this problem. i just want to add an custom style but do not want to replace the default styles. this is my current work-around: let drawDummy = new MapboxDraw();
let draw = new MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: true,
trash: true
},
userProperties: true,
styles: drawDummy.options.styles.concat({
'id': 'gl-draw-polygon-color-picker',
'type': 'fill',
'filter': ['all',
['==', '$type', 'Polygon'],
['has', 'user_portColor'],
],
'paint': {
'fill-color': ['get', 'user_portColor'],
'fill-outline-color': ['get', 'user_portColor'],
'fill-opacity': 0.5
}
})
}); but it floods the console for every default style with messages like this:
how can we handle this feature request? regards, volker. |
@skydiablo you can set the default styles like this while initializing mapboxDraw export const styles = (portColor) => { and when u want to add custom styles/colors in geofence you get do it like this: I hope this helps |
Hello, I just stumbled on this very problem, and while I managed to find a workaround, seeing this feature implemented would be a welcome addition. Any updates? |
This issue has become rather verbose, so let's move discussion of implementing this feature to #1109. |
@mcwhittemore |
I'm developing an application where I need to draw polygons/polylines on a Mapbox map and then style them programmatically changing their color/line width. I can easily draw using this library but I have no clue on how to style drawn objects (I need to give to each object its individual style, not to give the same style to every object generated by the Mapbox GL Draw instance), what's the best way to do it?
The text was updated successfully, but these errors were encountered: