mapbox / mapbox/mapbox-gl-js

Issues when adding `in` expression to my filters.

Open
#12,763 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs information :pray:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

I have to get going to work so I want to make my bug report as brief as possible.

I have this code that works perfectly fine:
```js
map.current.addLayer({
id: 'countries-join',
type: 'fill',
source: 'mapbox-countries',
'source-layer': 'country_boundaries',
paint: {
'fill-color': [
'case',
['==', ['feature-state', 'hasData'], true],
'rgba(0, 0, 0, 0)',
'rgba(0, 0, 0, 0.14)'
]
},
filter: [
"all",
["==",["get", "disputed"],"false"],
[
"any",
[
"==",
"all",
["get", "worldview"]
],
[
"in",
"US",
["get", "worldview"]
]
]
]

},'waterway-label');
```

I have another layer I add right below it:

```js
// Find the codes of the selected countries.
const selectedCountryCodes = countriesFilter.map(name => countryNameToCode[name]);
console.log("Selected Country Codes Top", selectedCountryCodes)

map.current.addLayer({
id: 'country-borders',
type: 'fill',
source: 'mapbox-countries',
'source-layer': 'country_boundaries',
paint: {
'fill-color': 'rgba(100, 0, 0, 0.15)',
},
filter: [
"all",
["==",["get", "disputed"],"false"],
[
"any",
[
"==",
"all",
["get", "worldview"]
],
[
"in",
"US",
["get", "worldview"]
]
],
['in', 'iso_3166_1'].concat(selectedCountryCodes)
]
});
```
This layer causes all sorts of errors mostly along the lines of `Error: layers.country-borders.filter[1][1]: string expected, array found` for the nested filter conditions. But if I remove the `in` statement at the end (which I need, it's the whole purpose of the filter) I don't get any more errors. I have checked and selectedCountryCodes is always either [] or an array of valid ISO country codes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the second map.current.addLayer call with selectedCountryCodes both empty and populated, then inspect the filter validation path for the reported layers.country-borders.filter error. Done means the constructed filter is accepted and the layer restricts country_boundaries to the selected ISO codes without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.