Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queryRenderedFeatures stringifies nested properties #4380

Closed
dougajmcdonald opened this issue Mar 8, 2017 · 3 comments
Closed

queryRenderedFeatures stringifies nested properties #4380

dougajmcdonald opened this issue Mar 8, 2017 · 3 comments

Comments

@dougajmcdonald
Copy link

I have some GeoJSON with nested properties, something like this:

{
  type: 'Polygon',
  geometry: ...,
  properties: {
    id: 1,
    ratings: [
      { year: 1, score: 5 },
      { year: 2, score: 10 }
    ]
  }
}

When I used queryRenderedFeatures and return this feature I get a JSON object which looks like this:

{
  type: 'Polygon',
  geometry: ...,
  properties: {
    id: 1,
    ratings: "[{ "year": 1, "score": 5 },{ "year": 2, "score": 10 }]"
  }
}

So it looks like it's stringified my ratings array. I would expect to have the original feature returned with it's original structure. Is this stringification expected?

At the moment I have a workaround by doing this:

    filteredFeatures.forEach((filter) => {
      filter.properties.ratings = JSON.parse(filter.properties.ratings);
    });

But it feels like I shouldn't need to. Any thoughts?

@dougajmcdonald dougajmcdonald changed the title queryRenderedFeatures doesn't parse nested properties queryRenderedFeatures stringifies nested properties Mar 8, 2017
@Scarysize
Copy link

AFAIK the documentation states that "...For GeoJSON sources, only string and numeric property values are supported..." (https://www.mapbox.com/mapbox-gl-js/api/#Map#queryRenderedFeatures)

@dougajmcdonald
Copy link
Author

@Scarysize aha, thank you. Sorry I missed that one. Is there a specific need to not support objects / arrays etc? Wonder if it's worth submitting as a feature request?

@jfirebaugh
Copy link
Contributor

We're tracking the feature request in #2434.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants