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

Can't clear layer filter after being set #796

Closed
agusterodin opened this issue Oct 24, 2019 · 4 comments
Closed

Can't clear layer filter after being set #796

agusterodin opened this issue Oct 24, 2019 · 4 comments

Comments

@agusterodin
Copy link

agusterodin commented Oct 24, 2019

You are currently not able to clear a layer filter after it has been set.

For example: you set a filter on a layer to show a subset of the features by setting the prop. At some point, you want to clear your filter to show all features in that layer again. Setting the filter prop back to null does nothing.

The issue lies in this part of the componentWillReceiveProps

if (props.filter && filter && !isEqual(props.filter, filter)) {
    map.setFilter(id, props.filter || [])
}

This would fix the issue

if (!isEqual(props.filter, filter)) {
    map.setFilter(id, props.filter || [])
}

Mapbox says that map.setFilter(null) or map.setFilter(undefined) is the intended way to remove any existing filters off of a layer. See: https://docs.mapbox.com/mapbox-gl-js/api/#map#setfilter

@agusterodin
Copy link
Author

agusterodin commented Nov 4, 2019

Also passing setFilter [] is invalid. Mapbox throws console errors when you try to do that. The proper way to set to an empty filter is by passing null.

@mklopets
Copy link
Collaborator

mklopets commented Jan 8, 2020

sorry for the delay & thanks for pointing this out – a fix was released under v4.8.2

@agusterodin
Copy link
Author

sorry for the delay & thanks for pointing this out – a fix was released under v4.8.2

Much appreciated sir

@sergei-zelinsky
Copy link

Hello @mklopets,
seems geojson-layer has the same problem.
I've created a PR with a small fix.
Thanks

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

No branches or pull requests

3 participants