Feature request: expression for string.split(<separator>)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
*Underlying problem: The MVT format does not support array properties*
I want to send 48 numbers (between 0 and 1) along with every feature. These values represent congestion in electrical grid lines over 48 hours. I want to have a time slider to pick the hour, and style every feature according to their individual congestion at that hour.
*A workaround for this that I've used in OpenLayers is to ***use a string property, which contains all the values separated by semicolon. They are then split up in the style function***, and the "current congestion" (according to the slider) is used to style each line individually.*
It seems like this is not easily doable in Mapbox GL, which is why I'm making this feature request.
## Design Alternatives
It might be the case that there is some good alternative to this approach that I'm not seeing (that does not severely affect performance or scalability).
## Design
Proposition: implement the following expression:
```js
["split", separator_string, string]: array
```
Example:
```js
["split", ";", "1;0.5;0.33;0.101;0.2"]
-> ["1", "0.5", "0.33", "0.101", "0.2"]
```
The behavior should essentially be the same as the following (javascript):
```js
// ";" is the separator_string:
"1;0.5;0.33;0.101;0.2".split(";")
// ["1", "0.5", "0.33", "0.101", "0.2"]
```
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 locating the expression evaluator and the existing expression test coverage for array-producing expressions. Implement the proposed split(separator_string, string) behavior, then verify that the example returns the expected string array and that edge cases match JavaScript split semantics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100