-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Set the feature state for all features in a source #9709
Comments
I've tweaked your title, hope that's okay, because feature states apply at the source level not the layer level (eg. if you have two layers using one source). |
Very true. Thanks! |
@itko Have you tried doing this with a single layer and a configuration where the paint property expression is updated to change the color for all circles and uses |
@asheemmamoowala Good point. Using
This solution is a little less clean than setting all the feature-states in a source, but considering how niche this use case is, maybe For what it's worth, I've noticed a slight delay with |
#7122 would result in quite a performance hitting when using source/source-layer wide state values.
Thinking about this further, the use case described here would be well served by global state variables in expressions, discussed in #7946. |
I was also just thinking that if this is easier to implement, it could be a workaround for the lack of configurable global state. :) |
@itko The usecase you described is similar to something I am doing currently. As far as I am aware it is currently not possible to load a source with feature state already set, right? Perhaps there is a something I am missing... My current style expression uses feature-state to change the colour of layers. I have a scenario whereby multiple sources are loaded, 2 layers are added for each, I need to set the feature-state for all features in a particular source. I can use My current solution is using Any advice would be appreciated :) |
Motivation
Sometimes, it is necessary to change the state of all features at once. As an example, let's take a layer with circle elements. We would like to create an effect where clicking on one of the circles will change the color of all the other circles (except for the one that is clicked).
Currently, there are two ways to accomplish this:
queryRenderedFeatures
and then loop through each feature in order to set its state. This is incomplete, becausequeryRenderedFeatures
does not retrieve all features.If one could change all states at once, then a user could use that in order to recolor all circles, and then change the state of the circle that was clicked in order to return that circle to its previous state.
Design Alternatives
Make the
id
argument optional forsetFeatureState()
, just likeremoveFeatureState()
. When theid
argument is excluded,setFeatureState()
would be applied to the entire layer.The text was updated successfully, but these errors were encountered: