Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression doesn't seem to work as expected when property is a boolean #6551

Closed
pastcompute opened this issue Apr 21, 2018 · 3 comments
Closed

Comments

@pastcompute
Copy link

pastcompute commented Apr 21, 2018

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 value showThis:

map.setFilter('some-layer', ['==', 'aStringProperty', '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

  1. 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:
    features = [{ /* ... */, properties: {S: 'A', X: true }, { /* ... */, properties: {S: 'B', X: false }];
    const source: any = {type: 'geojson', data: turf.featureCollection(features)};
    this.map.addSource('source', source);
    this.map.addLayer({ /*...*/, id: 'layer', source: 'source'});
  1. 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

@asheemmamoowala
Copy link
Contributor

@pastcompute I am not seeing this issue on either master or v0.44.2. Could you please provide a self-contained example that reproduces the issue?

@pastcompute
Copy link
Author

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

@pastcompute
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants