-
Hello guys, I was searching for documentation on how to add the Traffic v1 tileset to the map instance on a CRA project and did not get so far. Have anyone here implemented it already? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
LucasBSC
Mar 19, 2021
Replies: 1 comment
-
Update on this Managed to get it working with the following sample code if it can help someone: const layerStyle = {
id: 'traffic',
type: 'line',
source: 'mapbox-traffic',
'source-layer': 'traffic',
};
<ReactMapGL
{...viewport}
width="100%"
height="100%"
style={cssStyle}
onClick={handleMapClick}
ref={mapRef as any}
mapStyle={mapStyle}
onViewportChange={onViewportChange}
mapboxApiAccessToken={process.env.REACT_APP_MAPBOX_API_KEY!}
>
<Source
type="vector"
url="mapbox://mapbox.mapbox-traffic-v1"
id="mapbox-traffic"
>
<Layer
{...layerStyle}
paint={{
'line-width': 1.5,
'line-color': [
'case',
['==', 'low', ['get', 'congestion']],
'#aab7ef',
['==', 'moderate', ['get', 'congestion']],
'#4264fb',
['==', 'heavy', ['get', 'congestion']],
'#ee4e8b',
['==', 'severe', ['get', 'congestion']],
'#b43b71',
'#000000',
],
}}
/>
</Source>
</ReactMapGL> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
LucasBSC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update on this
Managed to get it working with the following sample code if it can help someone: