Treat Strings as Arrays in GL JS Expressions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
This suggestion relates closely to the substring functionality discussed in https://github.com/mapbox/mapbox-gl-js/issues/4113, as well as the regex expression support in https://github.com/mapbox/mapbox-gl-js/issues/4089. I think these existing issues do a better job of addressing the underlying problem (lack of ability to work with substrings in expressions), but this feature request provides another option.
Programming languages commonly implement strings as arrays of characters. Mapbox GL JS expressions could treat strings in the same way to allow for existing expressions (i.e. `at`) to be used with strings. For example, this would allow filtering for streets whose name property starts with the string `"Ba"`.
## Design
If GL JS parsed strings in expressions as arrays, developers could make use of the current [`at` expression](https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions-at) to implement the filtering use case described above.
### Mock-Up
If a developer wanted to filter for features where the street name property starts with `"Ba"` , they could set the `opacity` attribute of the `road-label` layer to be determined by the following expression:
[
"case",
[
"all",
[
"==",
["at",
0,
["get", "name_en"]
],
"B"
],
[
"==",
["at",
1,
["get", "name_en"]
],
"a"
]
],
0,
1
]
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
Start by reading the existing `at` expression documentation and the related substring and regex issues, #4113 and #4089. Determine whether treating strings as arrays is the intended direction, then define and validate the expression behavior represented by the street-name filtering example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100