terra-draw icon indicating copy to clipboard operation
terra-draw copied to clipboard

[Documentation] Updating Feature Properties

Open alexander-ye opened this issue 8 months ago • 4 comments
trafficstars

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)

alexander-ye avatar Mar 18 '25 15:03 alexander-ye

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?

JamesLMilner avatar Mar 19 '25 21:03 JamesLMilner

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.

alexander-ye avatar Mar 20 '25 19:03 alexander-ye

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.

rczobor avatar Apr 15 '25 11:04 rczobor

@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

JamesLMilner avatar Apr 23 '25 21:04 JamesLMilner

I'm just closing this in favour of https://github.com/JamesLMilner/terra-draw/issues/503 - feel free to continue the conversation on there 👍🏻

JamesLMilner avatar Aug 19 '25 18:08 JamesLMilner