terra-draw
terra-draw copied to clipboard
[Documentation] Updating Feature Properties
Help!
Is it possible to update feature properties using terra-draw, with something like draw.setFeatureState, to update the properties object of a feature?
The docs only show adding/removing features. (Is the only way to "update" a feature to remove it then add it with updated properties? If so, the delete event gets called unnecessarily)
Hey @alexander-ye thanks for raising an issue, appreciate your interest in the project. At the moment setting properties isn't something we allow as we use properties internally in the library and would be problematic to allow arbitrary property setting.
Can I ask what you are trying to achieve and then maybe I can help? i.e. which properties are you trying to set and why?
I figured out a way to do it by leveraging deleteFeatures and addFeatures — although it triggers the delete event, which isn't ideal but I get why the event gets fired.
I update properties like color and label that I use to style the drawings I make, and there are times I want to update those properties.
Hi @JamesLMilner, I'm also interested in this feature. We are using properties for dynamic polygon styling. Right now, we have to do the above mentioned workaround to delete -> add any polygon feature if we want to change any of the properties.
We are in the process of migrating from mapbox-gl-draw to terra-draw.
@alexander-ye just a heads up you can style features for each modes like so: https://github.com/JamesLMilner/terra-draw/blob/main/guides/5.STYLING.md#drawing-modes
If you need to change the styles dynamically that's also possible: https://github.com/JamesLMilner/terra-draw/blob/main/guides/5.STYLING.md#dynamically-changing-styling
and if you need to make specific features styled in a certain way, styles support functions: https://github.com/JamesLMilner/terra-draw/blob/main/guides/5.STYLING.md#styling-specific-features
I'm just closing this in favour of https://github.com/JamesLMilner/terra-draw/issues/503 - feel free to continue the conversation on there 👍🏻