Closed RWParsons closed 4 months ago
So if you change this line:
list("in", "CNTY_ID", ids)
To:
c("in", "CNTY_ID", ids)
It does work.
This is because Mapbox expects a single array for in
like ["in", "property_name", "value1", "value2", "value3", ...]
For example:
> values <- c("a", "b", "c")
> jsonlite::toJSON(list("in", "column", values), auto_unbox = TRUE)
["in","column",["a","b","c"]]
> jsonlite::toJSON(c("in", "column", values), auto_unbox = TRUE)
["in","column","a","b","c"]
I'd like to think of ways to make this easier for users, but I want to keep the powerful capabilities of Mapbox's expression system exposed. So we'll want to think this through.
Perfect - thanks @walkerke!
As mentioned in the discussion of #12, it seems that the "in" operator does not work as desired when used for filtering the source data against a vector of possible values.
reprex:
Note that the filter works when the
ids
is of length 1: change the range to be from 0.03 to 0.043 to observe this effect on the map.I'm not at all familiar with the mapbox API but perhaps it needs to be wrapped with some "any" condition as described here? https://stackoverflow.com/questions/62477327/how-to-use-in-expression-in-mapbox-gl-map-setfilter
Thanks!
Rex