dimapio / map-gl

Interactive maps in the browser
MIT License
0 stars 0 forks source link

Can't set feature-state on Source w. generateId #6

Closed garretteklof closed 1 week ago

garretteklof commented 1 week ago

Console error Attempted to set the feature state of a feature with no ID on Layer with case statement in paint for a Source with generateId: true.

Note: when logging the feature in HoverPopup, the id is in fact generated:

Screenshot 2024-09-26 at 5 20 44 PM Screenshot 2024-09-26 at 5 20 33 PM

The paint statement is not executed (e.g. change in fill-color) and error leads to believe that mapbox-gl is never properly updated with the feature state.

(promoteId does not seem to work either, in this specific case it'd be promoteId: 'Id')

nsiebenaller commented 1 week ago

@garretteklof I can't reproduce this issue, however, I found another issue relating to the map not loading sources/layers on initial load. I pushed a fix to canary - can you test again using that?

Otherwise I'll need a link to the code you're working on.

garretteklof commented 1 week ago

I pulled and unfortunately it does not seem to resolve the feature-state issue.

The platform code can be accessed here. It's right now the /demo page.

nsiebenaller commented 1 week ago

@garretteklof I see the problem. When the layer checks if a GeoJSON feature has an id it uses a falsey check. Since 0 is a falsey value it triggers the "feature does not have id" warning.

https://github.com/dimapio/map-gl/blob/69d04e685e3bc2bdcb25fedbbe7006d473e893da/src/components/Layer.tsx#L56-L69

nsiebenaller commented 6 days ago

@garretteklof Additionally, I think it would help to improve this console warning for better DX. I've opened https://github.com/dimapio/map-gl/issues/10 to improve this warning.