visgl / visgl/react-map-gl

Source and Layer update dynamically not working

Open
#2,433 6 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.