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

Correct feature state id type to number #7106

Merged
merged 6 commits into from
Aug 16, 2018
Merged

Correct feature state id type to number #7106

merged 6 commits into from
Aug 16, 2018

Conversation

bfrengley
Copy link
Contributor

Currently, string feature ids are not propagated through the transformation from GeoJSON to vector tiles (#2716, #6960) and are not supported by vector tiles at all. However, setFeatureState / getFeatureState indicate that they require string ids.

This pull request updates setFeatureState / getFeatureState to require unsigned numeric ids.

  • briefly describe the changes in this PR
  • document any changes to public APIs

Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

I was wondering the same thing! @asheemmamoowala any objections?

Copy link
Contributor

@asheemmamoowala asheemmamoowala left a comment

Choose a reason for hiding this comment

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

@bfrengley Thank you for submitting this PR! Just one small change to the allowed input types for Map#setFeatureState.

if (feature.id == null || feature.id === "") {
this.fire(new ErrorEvent(new Error(`The feature id parameter must be provided.`)));
if (feature.id == null || feature.id < 0) {
this.fire(new ErrorEvent(new Error(`The feature id parameter must be provided and non-negative.`)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Map#setFeatureState should still accept string types that can be coerced to integers. This would allow what is otherwise a valid id for a GeoJSON feature to be input to the API without explicit conversion.

Based on #4581:

// If the feature has a top-level `id` property, copy it over, but only
// if it can be coerced to an integer, because this wrapper is used for
// serializing geojson feature data into vector tile PBF data, and the
// vector tile spec only supports integer values for feature ids --
// allowing non-integer values here results in a non-compliant PBF
// that causes an exception when it is parsed with vector-tile-js
if ('id' in feature && !isNaN(feature.id)) {
this.id = parseInt(feature.id, 10);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I am making this change: is there a reason Map#getFeatureState does not do the same validation of feature.id that is done in Map#setFeatureState? I see #6959 only addresses requiring an id in Map#setFeatureState

Copy link
Contributor

@asheemmamoowala asheemmamoowala Aug 14, 2018

Choose a reason for hiding this comment

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

@bfrengley that seems like a fix worth putting in as well. Thank you!

@mourner
Copy link
Member

mourner commented Aug 15, 2018

Rebasing the commits of this branch on top of the base branch cannot be performed automatically due to conflicts encountered while reapplying the individual commits from the head branch.

@bfrengley can you please rebase on top of master for clean merging?

@bfrengley
Copy link
Contributor Author

@mourner done.

@asheemmamoowala asheemmamoowala merged commit 103a2e7 into mapbox:master Aug 16, 2018
@bfrengley bfrengley deleted the feature-state-id-type branch August 16, 2018 22:59
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.

3 participants