Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Filter with Mapbox GL JS

Tags:

mapbox-gl-js

Using Mapbox GL JS 0.39.1, I set a filter on my layer:

map.setFilter('myLayer', ['!=', 'myKey', 'myValue'])

I cannot find a way to remove the filter. I would have thought there would be a map.removeFilter... function but have found nothing in the docs or in web searches. I could apply a fake filter (>'') so that it always matches but that seems inefficient. Surely there is a way to remove a filter.

EDIT: I have found that using the following code will achieve what I am trying to accomplish. Not sure if this is the recommended approach.

map.setFilter('myLayer');
like image 308
Tony Lugg Avatar asked Jan 04 '23 13:01

Tony Lugg


1 Answers

The docs were just updated, personally I would recommend using

map.setFilter('myLayer', null)

as it's more explicit and in my opinion makes the code more readable. Though your approach of just map.setFilter('myLayer'); is also acceptable.

like image 182
AndrewHarvey Avatar answered Jan 06 '23 04:01

AndrewHarvey