Correct feature state id type to number - #7106
Conversation
mourner
left a comment
There was a problem hiding this comment.
I was wondering the same thing! @asheemmamoowala any objections?
asheemmamoowala
left a comment
There was a problem hiding this comment.
@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.`))); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@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/getFeatureStateindicate that they require string ids.This pull request updates
setFeatureState/getFeatureStateto require unsigned numeric ids.