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

Preserve id property on internal GeoJSON objects #3210

Closed
mike-marcacci opened this issue Sep 18, 2016 · 5 comments
Closed

Preserve id property on internal GeoJSON objects #3210

mike-marcacci opened this issue Sep 18, 2016 · 5 comments
Labels
GL native → GL JS For feature parity with Mapbox Maps SDK on a native platform

Comments

@mike-marcacci
Copy link
Contributor

When a call to queryRenderedFeatures returns features from a GeoJSON source, the properties field of matching features is provided in the response, but their id field is not. Since this is the recommend place to store such an identifier (per the GeoJSON spec) it would be great if this were also returned in the results!

@mike-marcacci
Copy link
Contributor Author

mike-marcacci commented Sep 18, 2016

I went to implement this assuming it would be quite trivial (and it was!)... but then I discovered that the protobuf type set for id is uint64, which isn't flexible enough given that the GeoJSON spec states no preference and it's quite common to use UUIDs, etc.

@mike-marcacci
Copy link
Contributor Author

It appears that the vector tile spec also has no preference of id type, but that it's quite established as an integer in the implementations. I submitted a quick PR to the spec to help clarify.

To get around this, I've whipped up PR #3211 which uses the index of the feature in the GeoJSON FeatureCollection as its id over the Protobuf layer, and maps it back in queryRenderedFeatures. This is probably NOT the cleanest way to handle it (the conditional logic in particular), but it provides a proof of concept.

@1ec5 1ec5 added the GL native → GL JS For feature parity with Mapbox Maps SDK on a native platform label Sep 18, 2016
@jfirebaugh
Copy link
Contributor

Hi Mike, thanks for the bug report and PR!

the properties field of matching features is provided in the response, but their id field is not

I believe integer ids are expected to be preserved, as of mapbox/geojson-vt#70 and mapbox/vt-pbf#8 -- although it looks as if our package.json is compatible with, but does not strictly require, vt-pbf v2.1.0.

Preservation of non-integer ids is #2716.

@mike-marcacci
Copy link
Contributor Author

Awesome! Thanks for linking #2716 - hadn't seen that one, and I definitely like the idea of its geobuf solution!

@mike-marcacci
Copy link
Contributor Author

@jfirebaugh - also, just to be clear, this is easily fixed by adding this.id = feature.id here, but this will break existing apps where the GeoJSON id is a string, hence my workaround.

Alternatively, you could just add a check for type, and only set it if it's a number until #2716 lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GL native → GL JS For feature parity with Mapbox Maps SDK on a native platform
Projects
None yet
Development

No branches or pull requests

3 participants