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

Allow null as a filter value #4410

Closed
jingsam opened this issue Mar 13, 2017 · 12 comments
Closed

Allow null as a filter value #4410

jingsam opened this issue Mar 13, 2017 · 12 comments
Labels
cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) feature 🍏

Comments

@jingsam
Copy link
Contributor

jingsam commented Mar 13, 2017

mapbox-gl-js: 0.33.1
When I tried to filter out null values like this:

filter: [
  "!=",
  "name",
  null
]

But it warns:

string, number, or boolean expected, null found
@mourner
Copy link
Member

mourner commented Mar 13, 2017

You can do this currently with ['has', 'name'] filter. However we might want to support null as a valid value too. Did we consider this @jfirebaugh?

@mourner mourner added cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) needs discussion 💬 labels Mar 13, 2017
@jfirebaugh
Copy link
Contributor

Yes, see mapbox/mapbox-gl-style-spec#421. Main reason we haven't implemented it is in most cases you want ['has', 'name'], not ["!=", "name", null], because vector tiles don't support null (mapbox/vector-tile-spec#62).

@jfirebaugh jfirebaugh changed the title Filter seems not working with null Allow null as a filter value Mar 13, 2017
@jingsam
Copy link
Contributor Author

jingsam commented Mar 14, 2017

But geojson does suuport null

@stevage
Copy link
Contributor

stevage commented Mar 14, 2017

What would the semantics of has be for a null value then? Does a feature has a value, if that value is null? And is it really useful to be able to distinguish "", null and not-present?

@lucaswoj
Copy link
Contributor

@stevage I spent some time thinking about this while implementing mapbox/mapbox-gl-style-spec#451. My conclusion was that we should be as true to the Javascript semantics as possible. This would suggest that we should support null in Map#setFilter. (undefined is a sticker case because it isn't supported in JSON.)

@stevage
Copy link
Contributor

stevage commented Mar 16, 2017

Ah, thanks for pointing me to that.

@zuo1188
Copy link

zuo1188 commented Jun 6, 2017

image

image

so it's awkward

@zuo1188
Copy link

zuo1188 commented Jun 6, 2017

or please do not render it when property==null

@benstadin
Copy link

@zuo1188 I can top this! ;)

null

To me this is an important feature for data-driven styling. Because you get GeoJSON data often from external data sources, and null is a valid value.

I think an isNUll comparator would be handy.

@anandthakker
Copy link
Contributor

Closing this, as it will be covered by the upcoming 'arbitrary expressions' feature #4777

@qrohlf
Copy link

qrohlf commented Dec 17, 2021

Correct me if I'm wrong, but after reading this, #421, and #4777, it appears that the intent in these discussions was to support a filter like ["==", "temp", null] for asserting that a feature has the property temp and it is equal to null, but the actual functionality doesn't appear to have made it into the product. As far as I can tell, map.setFilter("mylayer", ["==", "temp", null]) is currently a no-op and does not result in any filtering being applied to my data.

@Dimi4ek
Copy link

Dimi4ek commented Mar 29, 2022

I think has using when we need to check existing field in properties.
Can we use filter: ['to-boolean', ['get', 'fieldName']] ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) feature 🍏
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants