-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support nested objects and arrays for GeoJSON features in query*Features #2434
Comments
Looks like a valid bug to me! The queryRenderedFeatures results are definitely coming out JSON-encoded and entering as objects. |
Not right now. Why: The vector tile spec doesn't support array or object values. After geojson is tiled, it gets converted to a vector tile pbf so that it can be transferred from the worker to the main thread efficiently for querying. Converting it to a vector tile might not be the best idea, but that's why it's happening.
I think so. I'm not 100% sure, but I think so Related questions:
|
Is this even possible? To get the full geojson all the tiles of the feature would have to be loaded. We could do this for geojson sources, but its more important that the api is consistent across source types than reporting full geojson. This API being sync is also a very crucial thing so that it can play with mouse events nicely. That said, what a user expects is to have the feature that is being rendered be returned and while we can't return the geometry, we can return the properties. Returning these how the user originally represented it would be good for clarity. |
This is a limitation of the vector-tile-spec — there's no "JSON" value. We could add an extension (a new field type that would encode stringified JSON including arrays), but it's a hack and we would have to add support for this upsteam in |
Has there been any further resolution to this issue? |
Just got hit by this, adding a GeoJSON layer with features like: {
"properties": {
"picture": {
"url": "https://example.com/image.jpg"
},
},
"geometry": {
"coordinates": [
-59.98021487775259,
2.8771639400161804
],
"type": "Point"
},
"type": "Feature",
"id": "7b8f0c7d-0d08-4029-ab66-eca3517e8aea"
} What I get from {
"properties": {
"picture": "[object Object]",
},
"geometry": {
"coordinates": [
-59.98021487775259,
2.8771639400161804
],
"type": "Point"
},
"type": "Feature",
"id": "7b8f0c7d-0d08-4029-ab66-eca3517e8aea"
} This needs to be documented as a breaking change in The API docs also need updating, they currently incorrectly state:
|
@gmaclennan Did |
Yes, in |
On a related note, |
@gmaclennan yep, looks like it. I'd gladly merge a PR for this. :) |
Stringifying was to get around this issue: mapbox/mapbox-gl-js#2434 Removing since this is now resolved.
Note: I believe mapbox/vt-pbf#6 (published in vt-pbf 2.1.0) should change the behavior that @gmaclennan described: non-primitive properties will now get serialized as JSON (but note that they won't get automatically _de_serialized, as there's no mechanism for recording the encoding) |
What is the status of this feature? Is there any support for nested arrays? |
bump |
Adding support for this would be especially useful now that expressions are supported per #4777. Is there any way of working with array properties yet, or plans for it? |
|
@anandthakker there is no |
@janbaykara apologies, the
Could you please provide a minimal working example that reproduces this? |
@anandthakker ignore me, I'm a moron. I was searching (a <- b) rather than (b <- a) (i.e. |
👍 glad it's working! |
Can someone point me to the area in the docs that explains how to use nested objects within the |
Sorry, missed the reference to |
I see people discussing styling data using nested Objects within a feature's properties. I opened an issue, #7620 and was referred here. Are expressions with nested objects just "sort-of" implemented? |
This comment applies for how to convert a vector tileset to a geojson source and run an expression on it. If anyone is wondering on a possible way to do this using one of the composite/vector layers then you'll need to make a copy of the vector layer then add it is a geojson source. Update the data by doing a In our case we were unable to query an array of objects since it was being converted to a JSON string on the property. This is definitely hacky but maybe an option for someone who doesn't have control of the data going into Mapbox.
Then in your filter expression you can do
An alternative to this if you have control of the data going into Mapbox is to format the properties like this instead:
|
Is this working now? |
Am I wrong to assume this will be "broken" for a while to come? |
There should be at least a way to intercept and custom process the tile data. A way to insert a middleware basically. This should be very simple for you to implement I think. |
Whats the status here concerning the OP question? Is there a currently a workaround to get nested objects out of feature properties using query*Features? |
I've just run into this issue too, a whole 6 years later. Object/array data stored in my ----- EDIT -----
|
6 years later still not supported... running into the same issue here |
Hello, I believe we still have this same old issue...? |
Yeah, I think im experiencing the same/similar issue on a feature :: #11629 "properties": { cant read the inner "2019" property when trying to set 'fill-color' as that object is showing as a string in the feature. |
What I find interesting about this is that the rendering doesn't seem to care, so using nested properties seems to work just fine until you try to query the features (or use mouse-events). Would it be possible to update the documentation (geojson-source / get expression) to make this clear, or maybe throw an error? Example here: https://codepen.io/usefulthink/pen/PorYQEK?editors=0010 |
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
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.
The text was updated successfully, but these errors were encountered: