Atlaslog
Atlaslog / MapLibre GL JS / API / setFilter
MapLibre GL JS · API reference

setFilter

Quick answer

setFilter ( layerId : string , filter? : FilterSpecification , options? : StyleSetterOptions ): this

Last verified 2026-11-03 · MapLibre GL JS 4.x · Cite this page
Runnable examplesChinese noteAll API topics
setFilter()

setFilter(layerId: string, filter?: FilterSpecification, options?: StyleSetterOptions): this

Defined in: ui/map.ts:3673

Sets the filter for the specified style layer.

Filters control which features a style layer renders from its source. Any feature for which the filter expression evaluates to true will be rendered on the map. Those that are false will be hidden.

Use setFilter to show a subset of your source data.

To clear the filter, pass null or undefined as the second parameter.

Parameters

Parameter Type Description
layerId string The ID of the layer to which the filter will be applied.
filter? FilterSpecification The filter, conforming to the MapLibre Style Specification's filter definition. If null or undefined is provided, the function removes any existing filter from the layer.
options? StyleSetterOptions Options object.

Returns

this

Examples

Display only features with the 'name' property 'USA'

map.setFilter('my-layer', ['==', ['get', 'name'], 'USA']);

Display only features with five or more 'available-spots'

map.setFilter('bike-docks', ['>=', ['get', 'available-spots'], 5]);

Remove the filter for the 'bike-docks' style layer

map.setFilter('bike-docks', null);

See

Create a timeline animation


TutorialsAPI index
English reference text adapted from the official MapLibre GL JS documentation, © MapLibre contributors, licensed under BSD-3-Clause.
Original page: https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/ · Chinese note: /maplibre/api/set-filter.html
Cite this page

Atlaslog (2026). setFilter. https://www.jingweizhi.com/en/maplibre/api/set-filter.html (accessed 2026-11-03).