mapbox / mapbox/mapbox-gl-js

Add "to-array" & "to-object" to expresions

Open
#6,546 5 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

## Motivation

As MVT spec does not allow passing arrays or objects as features property, the shortcut is to pass them serialized as string, and parse it later if needed.

The problem here is when trying to use one specific element of that specific property for filtering or styling, it looks back to the original info in the tile and it will find a string. So, no way.

## Proposal

Adding new casts to [expresions](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types)

* **to-object** (~ JSON.parse(value)):
* use: `["to-object", my_object_like_value ]`
* example:
```` javascript
fill-opacity:["get", "myopacity", ["to-object", ["get", "myproperty"]]]
````
* **to-array** (~ value.split(separator)):
* use: `["to-array", separator , my_array_like_value ]`
* example:
```` javascript
fill-opacity: ["number", ["at", 23, ["to-array", ",", ["get", "myproperty"]]]]
````

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

Start with the expressions type documentation linked in the issue and review the proposed to-object and to-array examples. Determine the intended inputs, outputs, and filtering or styling behavior for each cast, then add coverage for the documented cases and verify that serialized feature properties can be used as proposed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.