-
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
An expression to check if an array contains a given value #4698
Comments
Yes, I have run into this need as well. The use case was a map of events, where each event had several categories. I would like to do:
and
The workaround in my case was to split all the categories out:
I think that workaround is probably always possible, although it would get cumbersome for large sets. |
Yeah, for my use case, it will be an evergrowing large set of IDs. For example: So filtering on boolean values is not an option :/ |
This could be subsumed by #4715 |
#4715 will help with one aspect of this, but actually I think the more challenging issue is that the vector tile specification does not support arrays or objects as feature property values. (See #2434, mapbox/vector-tile-spec#75) |
Oh, doesn't support arrays or objects, that's a kinky thing to work around :/ Ok, how about a function to match a concated string using regex? :p So, in my case (#4698 (comment)) and filter:
The boolean at the end could be used to easily inverse the filter? Just throwing out ideas here... |
GeoJSON properties do support arrays, and we have support for parsing them, so I think accessing them as part of the expression syntax is something we should also incorporate. |
Tracked in #4089. |
Related: #2434 |
@anandthakker a feature request, not a bug? |
Whoops, my mistake - thanks @stevage |
I don't think that Since the first parameter should be the feature property name (string), it is not possible to change the parameters order, like: A |
@gabrielmsdiniz I think I'm confused because what you're describing sounds like what the If you have a feature
you could use |
@ryanhamley I don't know why, but I can't do it... |
@gabrielmsdiniz The filter syntax has been deprecated; it will still work but you can't mix the filter syntax with the newer expression syntax. You'd probably want something like a
That being said, the filter docs are confusing because they reference an old |
@ryanhamley Yes, I'd like to do something like this:
So, how am I supposed to solve this without using |
Wait, there's a new |
@stevage Yes, it was implemented in #8876 Here's an example I made https://codepen.io/rsh412/pen/yLygeZR I didn't realize that it wasn't appearing in the docs. It was added in the PR so I'm going to have to dig into this to figure out what's up. Obviously we need to retool the docs a bit around this expression. Sorry for the confusion. cc @mapbox/docs |
Oh, cool! I really should start keeping an eye on https://github.com/mapbox/mapbox-gl-js/blob/master/CHANGELOG.md |
Did you ever get an answer? I am having a similar problem where my "in" expression filter is not reading my property array. |
@gabrielmsdiniz @ColeAmodeo The functionality you're attempting to do is possible. See https://jsfiddle.net/rsh412/hue2783p/1/ The original fiddle posted in an earlier comment that appeared not to work was using GL JS 1.4.1 but the |
Example:
A feature has properties:
now, I want to filter the features that has one or more of the colors I want to filter on.
or
It seems like the inverse variant of the membership filter 'in' and '!in'
The text was updated successfully, but these errors were encountered: