You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have successfully used an expression to construct a filter based on a string property.
For example, when I have a GeoJSON layer where the data source is a featureCollection of polygons, the following filter shows only the polygons where there is a property aStringProperty with value showThis:
If I try and use a boolean property to filter it never works though.
map.setFilter('some-layer', ['==', 'aBooleanProperty', true]) // doesnt work
Steps to Trigger Behavior
Add a data source to a layer where all of the features in the feature collection have a property, lets call it 'X' which happens to be a boolean, true or false. For example:
Set a filter that should show only the features in the layer where the property 'X' is true
map.setFilter('layer', ['==', 'X', true])
Expected Behavior
Only the features where 'X" is true should be shown
Actual Behavior
Either all or none are shown (depends on how I attempt to construct the filter - was experimenting with using a boolean to change the colour as well, and using the not operator, etc.) As a general rule, no items are shown when I attempt to compare a boolean property
Note that here, map.setFilter('layer', ['==', 'S', 'A']) has the desired effect but I would have thought it unnecessary to have to add a string property emulating a boolean to do this...
I've also tried using ['to-boolean', ['get', 'X']] and ['boolean', ['get', 'X'] and simply ['get', 'X'] and they don't work as expected - all items are not shown.
Note, if S is a number then comparing S to some number does work. So it is not a problem to compare string or number types, only boolean
The text was updated successfully, but these errors were encountered:
Thanks @asheemmamoowala
It will take a little work to extract from my app, so I'll try and find a jsbin that demonstrates something similar and modify it to see if it repeats
Sorry. I made a jsbin after yesterday and in there it works, so I'm going to need to try and work out whats different. I'm happy to close this for now as its probably my bad, I'll reopen if it turns out not to be me after all.
mapbox-gl-js version: 0.44.2
I have successfully used an expression to construct a filter based on a string property.
For example, when I have a GeoJSON layer where the data source is a featureCollection of polygons, the following filter shows only the polygons where there is a property
aStringProperty
with valueshowThis
:If I try and use a boolean property to filter it never works though.
Steps to Trigger Behavior
Expected Behavior
Only the features where 'X" is true should be shown
Actual Behavior
Either all or none are shown (depends on how I attempt to construct the filter - was experimenting with using a boolean to change the colour as well, and using the not operator, etc.) As a general rule, no items are shown when I attempt to compare a boolean property
Note that here,
map.setFilter('layer', ['==', 'S', 'A'])
has the desired effect but I would have thought it unnecessary to have to add a string property emulating a boolean to do this...I've also tried using
['to-boolean', ['get', 'X']]
and['boolean', ['get', 'X']
and simply['get', 'X']
and they don't work as expected - all items are not shown.Note, if S is a number then comparing S to some number does work. So it is not a problem to compare string or number types, only boolean
The text was updated successfully, but these errors were encountered: