Skip to content
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

setFeatureState and the need for removeFeatureState #6889

Closed
cammanderson opened this issue Jun 29, 2018 · 5 comments
Closed

setFeatureState and the need for removeFeatureState #6889

cammanderson opened this issue Jun 29, 2018 · 5 comments
Assignees
Labels

Comments

@cammanderson
Copy link
Contributor

Hi Guys,

Working with the new setFeatureState, and I noticed that there isn't a way to remove the state supplied. You must always provide a value to merge it, and can't reset to the original values.

Use cases are varied, and not sure of the overall impact, but I am updating a react project to offer the function, but I can't 'reset' the state back to 'pre' application of the setFeatureState. Ideally, I would be able to remove the feature state completely, and then assumingly it would source from the original value of the underlying source data. If not, you'd have to track the original property value of the object to work around it. Not sure if we need to add a removeFeatureState() ?

Cheers
Cam

mapbox-gl-js version:
0.46.0

browser:
N/A

Steps to Trigger Behavior

  1. setFeatureState({ source: 'composite', layer: 'water', id: 0 }, { value: true })
  2. setFeatureState({ source: 'composite', layer: 'water', id: 0 }, null)

Expected Behavior

Remove feature state entirely

Actual Behavior

Because underlying it is using an extend, the null || {} values have no effect.

featureState: { value: true }

@asheemmamoowala
Copy link
Contributor

@cammanderson this should be possible by getting the current state with Map#getFeatureState() and setting all values to null or undefined before calling Map#setFeatureState().

@strech345
Copy link

strech345 commented Jul 26, 2018

does this mean the states will be alive after features is removed by tile is unload?
I need to load states dynamically at tile load (for features of the coresponding tiles) and also to unload the states after tile is unload.

It would be nice to have the possibilty to automatically remove states if the feature is removed. Or to say in other word. The lifesycle may be the same to reduce memory space.

@peterqliu
Copy link
Contributor

@cammanderson @asheemmamoowala from a design perspective, should the removeFeatureState reset the entire state object, or allow users to reset specific keys within the object?

@peterqliu
Copy link
Contributor

peterqliu commented Nov 29, 2018

Making some progress for a key-level removeStateKey over at 3740971

@asheemmamoowala
Copy link
Contributor

Closed by #7761

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants