-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Documentation improvement: make clearer that feature.id can be string, but only if string can be cast as int #7632
Comments
This seems like an odd limitation of this feature. Would be good to see what is involved in getting any string value to work with this. In many data driven applications where features might be coming from an external GeoJSON feed, the developer won't have control over the ids on the features. The really odd thing is that setFeatureState works fine with any string. |
Pretty sure I found a bug: Looking at removeFeatureState function in the SourceFeatureState class, it does use the number feature id, but the if statements would fail if the id is 0. Lines 65, 70. Will need to test this to verify. |
@rbrundritt There is a lengthy discussion at #2716 |
was closed by #8550 |
Question
Our documentation on
feature.id
insetFeatureState
andgetFeatureState
states thatfeature.id
can be a string or a number. However, if you try a string that cannot be cast as an integer (i.e. "d-32-a"), you'll run into this error (The feature id parameter must be provided and non-negative
).A blog post on the Mapbox blog by @lobenichou and @asheemmamoowala confirms that
The ids also have to be integers or strings cast as integers (e.g. “03989” or 3989)
.I think it might be helpful to update the documentation to state that if you use a string, it must be valid when cast as an integer. If folks agree/I'm not missing anything, I'm happy to open up a PR that states this.
Links to related documentation
https://www.mapbox.com/mapbox-gl-js/api/#map#setfeaturestate
mapbox-gl-js/src/ui/map.js
Line 1393 in aab7551
https://www.mapbox.com/mapbox-gl-js/api/#map#getfeaturestate
mapbox-gl-js/src/ui/map.js
Line 1414 in aab7551
The text was updated successfully, but these errors were encountered: