Reputation: 374
I want to use setFilter expression to filter by substring for a given feature property inside a tileset. Note: I do NOT want to have to load an array of features external to the tileset, I want it to use setFilter only, not getFeatures functions and no looping. If user begins typing, "smith ..
" it would filter out features as they typed using setFilter
only.
I only see "=="
or "match"
but neither do case insensitive substring filtering, such as indexOf
, contains
, Like
, etc. Something like ['contains', feature.prop, 'smi']
then ['contains', feature.prop, 'smith']
, for example.
I see the example on mapbox examples, for filtering as you type, but I want to only use setFilter
. It doesn't look like it supports what I want to do, but I thought I'd ask anyway. It is a waste of client-side resources to have to populate any local array of features from the tileset. It defeats the purpose of putting the data inside a tileset to begin with.
Any standard expression for parsing a feature property by a partial string, not an exact match?
Upvotes: 3
Views: 2641
Reputation: 181
Now mapbox support to filter for tyle layer for sub string from string
expression code is
['in', {filter-substring-value}, ['string', ['get', {mapbox-property-field-string}]]]
Upvotes: 8
Reputation: 126205
As you have noticed, Mapbox-GL expressions don't support substrings or regexes. So I think the only workaround is along the lines you mentioned: getting a list of attribute values and using that as an autocomplete.
There are two ways to get that list of attribute values that don't require making separate, arguably redundant, queries.
querySourceFeatures()
to fetch all features within the current viewport, then filter down to find the values of the attribute you care about. This won't help if the user wants to filter towards something which is currently outside the viewport.Upvotes: 1