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
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.
sorry for the delay & thanks for pointing this out 鈥撀燼 fix was released under v4.8.2
sorry for the delay & thanks for pointing this out 鈥撀燼 fix was released under v4.8.2
Much appreciated sir
Hello @mklopets,
seems geojson-layer has the same problem.
I've created a PR with a small fix.
Thanks
Most helpful comment
sorry for the delay & thanks for pointing this out 鈥撀燼 fix was released under v4.8.2