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
{{ message }}
Repository navigation
An expression to check if an array contains a given value #4698
#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)
Reacted by Konstantin Käfer, Molly Lloyd and Tudor Maxim
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.
Reacted by Minh Nguyễn, Andrew Harvey, Katie Smillie, Matt, Zoran Pesic, Lucas Dolsan, gabrielmsdiniz and Egor
changed the title [-]Style API: Ability to set a style filter by a looking in a feature property array[/-][+]An expression to check if an array contains a given value[/+]on Apr 19, 2018
I don't think that in operator solves this problem...
Since the first parameter should be the feature property name (string), it is not possible to change the parameters order, like:
['in', 'green', 'colors'] (different behavior)
A contains operator that evaluates the existence of a string in a feature property which type is an array could help...
you could use ['in', 'green', 'colors'] to determine if the string green is in the property colors which is of type array. I'm not sure how the order of the arguments makes a difference.
That being said, the filter docs are confusing because they reference an old in function which was removed from GL JS a long time ago. The docs need to be updated to remove those references since they do not refer to the new in expression. Sorry for that confusion.
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.
Activity
stevage commentedon May 11, 2017
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:
{ categories: ['Arts','Money','Sport'] }and
filter: ['inArray', 'categories','Sport']The workaround in my case was to split all the categories out:
sportCategory:true, artCategory: true, moneyCategory: trueI think that workaround is probably always possible, although it would get cumbersome for large sets.
dagjomar commentedon May 11, 2017
Yeah, for my use case, it will be an evergrowing large set of IDs. For example:
{ categories: [32,44,53,66,235,434] }
So filtering on boolean values is not an option :/
kkaefer commentedon May 23, 2017
This could be subsumed by #4715
anandthakker commentedon May 23, 2017
#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)
dagjomar commentedon May 24, 2017
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))
Instead of the array
{ categories: [32,44,53,66,235,434] }it would be:
{ categoriesStr: '|32|44|53|66|235|434|' }and filter:
The boolean at the end could be used to easily inverse the filter?
Just throwing out ideas here...
kkaefer commentedon May 24, 2017
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.
1ec5 commentedon May 24, 2017
Tracked in #4089.
anandthakker commentedon Aug 7, 2017
Related: #2434
stevage commentedon Aug 7, 2017
@anandthakker a feature request, not a bug?
anandthakker commentedon Aug 8, 2017
Whoops, my mistake - thanks @stevage
[-]Style API: Ability to set a style filter by a looking in a feature property array[/-][+]An expression to check if an array contains a given value[/+]gabrielmsdiniz commentedon Jan 13, 2020
I don't think that
inoperator solves this problem...Since the first parameter should be the feature property name (string), it is not possible to change the parameters order, like:
['in', 'green', 'colors'] (different behavior)
A
containsoperator that evaluates the existence of a string in a feature property which type is an array could help...ryanhamley commentedon Jan 13, 2020
@gabrielmsdiniz I think I'm confused because what you're describing sounds like what the
inoperator does.If you have a feature
you could use
['in', 'green', 'colors']to determine if the stringgreenis in the propertycolorswhich is of type array. I'm not sure how the order of the arguments makes a difference.gabrielmsdiniz commentedon Jan 13, 2020
@ryanhamley I don't know why, but I can't do it...
https://jsfiddle.net/gabrielmsd/q4zndpmh/5/
ryanhamley commentedon Jan 14, 2020
@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
caseexpression withinsub-expressions.That being said, the filter docs are confusing because they reference an old
infunction which was removed from GL JS a long time ago. The docs need to be updated to remove those references since they do not refer to the newinexpression. Sorry for that confusion.gabrielmsdiniz commentedon Jan 14, 2020
@ryanhamley Yes, I'd like to do something like this:
So, how am I supposed to solve this without using
filter?stevage commentedon Jan 14, 2020
Wait, there's a new
"in"expression that does exactly what this issue is requesting? But it's not documented?ryanhamley commentedon Jan 14, 2020
@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
stevage commentedon Jan 14, 2020
Oh, cool! I really should start keeping an eye on https://github.com/mapbox/mapbox-gl-js/blob/master/CHANGELOG.md
ColeAmodeo commentedon May 8, 2020
Did you ever get an answer? I am having a similar problem where my "in" expression filter is not reading my property array.
ryanhamley commentedon May 8, 2020
@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
inoperator was not added until1.6.0. Newer versions of GL JS should work as expected. If you believe there's a bug, please open a new ticket with a reproducible test case.