-
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
Correct feature state id type to number #7106
Correct feature state id type to number #7106
Conversation
There was a problem hiding this 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?
There was a problem hiding this 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
.
src/style/style.js
Outdated
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.`))); |
There was a problem hiding this comment.
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:
mapbox-gl-js/src/source/geojson_wrapper.js
Lines 38 to 46 in 3b0a1a9
// 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); | |
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
@bfrengley can you please rebase on top of master for clean merging? |
@mourner done. |
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.