-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
How to test for nulls with new expression syntax? #5761
Comments
Hmm, this method almost worked:
but didn't seem to always get the right result. This method worked:
It feels quite cumbersome and not very intuitive, considering the equivalent in the old syntax was:
|
I think you're right that having a There are three ways in the current API designed for this sort of null-handling:
Other, less cumbersome options we could consider:
|
Another option would be to replace the |
Yeah, @jfirebaugh's suggestion is intuitively how I expected it to work. It was confusing and unexpected to me that "value" is a distinct type, and that you have to explicitly use casts everywhere. It was also very unintuitive that |
A sort of similar problem to the one in this issue is doing something like The only benefit I can think of is that, if the arguments to Meanwhile, the most common case is likely just |
* Improve typing for ==, != expressions Closes #5761 Closes #5835 The overloads of == and != are now effectively: - `(T1: Comparable, T2: Comparable) => boolean { T1 == T2 }` - `(Comparable, value) => boolean` - `(value, Comparable) => boolean` Where `Comparable = string | number | boolean | null`. * Simplify comparability check * Add internal docs, fix possibleValues
Awesome, glad I was useful. |
Is this documented somewhere? I have data with null values and want to filter these out, the data can be string or numeric. |
+1 to @dominijk question |
@kuanb use |
After encountering the same problem, I thought it would be useful to provide examples: Use in an expression, to switch styling between normal and null value: This will keep the feature present (e.g. for hover purposes), but show it is as transparent:
The value for the normal state can itself be an expression, e.g. if you have a
Use as a filter when defining addLayer, to exclude features entirely: This will filter out null features entirely, i.e. not even shown/selectable at all.
See example at: |
I'm not sure if this is a support request, a comment on the new API or a feature request.
I'm loading a GeoJSON layer which contains some nulls. I want to create a color property which displays the null values differently from other values. (Yes, I could create two layers and a filter, as a workaround). My code looks like this:
Problem:
If I use
["!=", ["get", "Enrolments_2017_Total"], null],
, I get an error.Can this be right? Is it literally saying you can only compare a null literal to another null literal (
["!=", null, null]
)? Um, why would you want to do that? :)If I use
["has", "Enrolments_2017_Total"]
then that test always passes, because every feature "has" that property, it's just sometimesnull
.If I use
[">", ["get", "Enrolments_2017_Total"], 0],
I get:
Is there something I'm missing here?
The text was updated successfully, but these errors were encountered: