I have a MapLibre / Mapbox GL JS web application, where I load vector tile data for which I apply a style using a local JSON file. For the different layers I use filters like that:
"filter": [
"all",
["==", "size", "large"]
]
Now I want the user to be able to further filter the data, e.g. only view those data that have a specific category. Applying a further filter works easily, by getting the existing filter and appending the new filter.
map.setFilter('layerID', ["all", ["==", "size", "large"], ["==", "category", "A"]]
But how can I reset the filter so that it matches the initial value (where already the two filters are applied)? I know that I can completely remove the filter doing
map.setFilter('layerID', null)
but then, also the filter for size large is gone.
Is there a possibility to reset a filter to its initial value?
One "workaround" I could think of is to get the filter onInit and store it. When resetting the filter, do not set to null but to the stored value. But I thought maybe there is a built in function that I have overlooked?