Layer filters
The Felt SDK allows you to filter which features are visible in a layer using expressions that evaluate against feature properties. Filters can come from different sources and are combined to determine what's visible.
By understanding how filters work and combine, you can create dynamic views of your data that respond to user interactions and application state.
Understanding filter sources
Layer filters can come from multiple sources, which are combined to create the final filter:
Style filters: Set by the map creator in the Felt UI
Component filters: Set through interactive legend components
Ephemeral filters: Set temporarily through the SDK
You can inspect these different filter sources using getLayerFilters
:
Setting filters
Use setLayerFilters
to apply ephemeral filters to a layer:
Filter operators
The following operators are available:
Comparison:
lt
(less than),gt
(greater than),le
(less than or equal),ge
(greater than or equal),eq
(equal),ne
(not equal)Text:
cn
(contains),nc
(does not contain)Boolean:
and
,or
Compound filters
You can combine multiple conditions using boolean operators:
Practical example: Filtering by selected feature
Here's a common use case where we filter a layer to show only features that match a property of a selected feature:
Best practices
Clear filters: Set filters to
null
to remove them entirely:
Check existing filters: Remember that your ephemeral filters combine with existing style and component filters:
Type safety: Use TypeScript to ensure your filter expressions are valid:
Last updated