Source and Layer update dynamically not working
Open
Nobody has claimed this yet.
bug
- Dominant language
- TypeScript
- Stars
- 8.5k
- Forks
- 1.4k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 3
Description
Description
Hi.
I still have issue with react-map-gl to update the Source dynamically. It may be super silly but I can't figure out whats wrong with this approach. Let's say I have multiple "tilesets" that are referenced by an id named tileName
Expected Behavior
No response
Steps to Reproduce
const sprayedLayer = {
id: `sprayed-layer-${props.tileName}`, // Add id that's unique per map
type: 'fill',
source: `sprayed-tiles-${props.tileName}`,
'source-layer': getSourceLayerId(),
paint: {
'fill-color': [
'interpolate',
['linear'],
['get', 'ratio'],
0, '#30dc30', // Green at low values
0.5, '#FFFF00', // Yellow at medium values
1, '#e60b0b' // Red at high values
],
'fill-opacity': fillOpacity
}
};
<Map
{...viewport}
style={{width: '100%', height: '100%'}}
mapStyle="mapbox://styles/mapbox/satellite-streets-v11"
mapboxAccessToken={process.env.REACT_APP_MAPBOX_TOKEN}
>
<Source
key={`source-${props.tileName}`}
id={`sprayed-tiles-${props.tileName}`} // Add id that's unique per map
type="vector"
tiles={[`${process.env.REACT_APP_TILE_SERVER_HOST}/data/${props.tileName}/{z}/{x}/{y}.pbf`]}
minzoom={0}
maxzoom={12}
>
<Layer key={`layer-${props.tileName}`}
{...sprayedLayer} />
</Source>
<ScaleControl/>
</Map>
Environment
- Map library: react-map-gl@7.1.7
- Browser: Chrome 129
- OS: MacOS
Logs
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported and nested reproduction in react-map-gl@7.1.7, changing tileName and observing whether the source and layer update. Check the component update behavior and use the provided vector-tile example to verify that dynamic tilesets render with the corresponding source and layer IDs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- data-visualization, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100