Issues when adding `in` expression to my filters.
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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