mapbox / mapbox/mapbox-gl-js

Support nested objects and arrays for GeoJSON features in query*Features

Open
#2,434 42 comments 40 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

**v0.16.0**:

Hi! This is my first issue report, so I hope I get it right.

Basically I'm trying to use the function queryRenderedFeatures to get the underlying data in JSON format to present on a popup. This works for the higher level of the JSON data (I can show the data on the popup), but fails to get the more deeply nested data - a console.log suggests that the objects have been converted into a string instead.

Here's the link to the issue as demonstrated using the example on "popup on hover": [jsbin](https://jsbin.com/leroki/edit?html,console,output)

I've edited the data such that there is only a single marker and also added an array of objects called "list" under "properties" a la feature.properties.list. I've also changed the popup HTML to display the first element of what is supposed to be a list.
### Expected Behavior

I expect that on hover the popup should display the first object, {"id":1,"name":"A"}.
### Actual Behavior

Instead, it shows "[", which confirms that it returns a string instead of the object.

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 behavior with the linked jsbin and the popup-on-hover example, starting at the queryRenderedFeatures API. Trace how feature.properties values are returned and verify that nested objects and arrays remain structured; done means the popup displays the first list object as {"id":1,"name":"A"} rather than "[".

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.