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

Add id feature property to tiles #60

Closed
wants to merge 2 commits into from

Conversation

gmaclennan
Copy link

@gmaclennan gmaclennan commented May 16, 2016

Replaces #59

fixes mapbox/mapbox-gl-js#2716

@gmaclennan
Copy link
Author

@jfirebaugh like this?

@jfirebaugh
Copy link
Contributor

Yes, thanks! This looks good to me, but I'll wait for @mourner to merge and release.

@gmaclennan
Copy link
Author

@mourner would love to see this merged and potentially make it into the next release of mapbox-gl-js so that queryRenderedFeatures returns the id as well - that will make it much easier to reference the original geojson feature given that queryRenderedFeatures only returns 'flattened' geojson.

};
if (typeof feature.id !== 'undefined') {
clippedFeature.id = feature.id;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern will probably negatively affect performance in V8. I think it'll be fine to just do id: feature.id === undefined ? null : feature.id in place.

Copy link
Author

@gmaclennan gmaclennan May 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is it increases the size of the tiles with lots of id: undefined keys, when the original geojson has no id. I can just set id: feature.id and then delete undefined ids in the last step in tile creation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you serializing the tiles on disk, or are you concerned about memory footprint? The overhead shouldn't be significant. delete is not an option because it harms performance significantly. Also, I'd prefer id: null for non-existing ids rather than id: undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer !('id' in feature) for non-existing ids. A low-level library like geojson-vt should be very precise about the difference between !in, undefined, and null, not assume that it won't make a difference to downstream consumers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfirebaugh it's important for properties, but I don't think that's the case for feature ids. Also, if we add the id property after defining the object without it, like in the code above, V8 has to switch a hidden class for the object every time, slowing things down, so it's a performance antipattern. It may not be significant but we should measure and make a call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of mapbox/mapbox-gl-js#2874 what if a feature has no id provided, or any properties for that matter, it would be good to still be able to do feature highlights on hover in this case. Would this require geojson-vt to generate ids where the don't exist so that GL JS can use them in a hover filter?

@mourner
Copy link
Member

mourner commented Jul 29, 2016

Planning to do some benchmarking and then merge early next week.

@gmaclennan
Copy link
Author

That would be great @mourner, thanks.

@mourner mourner mentioned this pull request Aug 9, 2016
@mourner
Copy link
Member

mourner commented Aug 9, 2016

I wanted to take a slightly different angle to implementation of this, so opened a #70 instead (using ideas from your PR). Thanks again for the PR!

@mourner mourner closed this Aug 9, 2016
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

Successfully merging this pull request may close these issues.

query*Features should preserve non-integer feature IDs
4 participants