Muddy dash stroke
by Tristen Brown
HTML
<link rel="stylesheet" href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.0/mapbox-gl.css">
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.0/mapbox-gl.js"></script>
<div id="map"></div>
CSS
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
JavaScript
mapboxgl.accessToken = 'pk.eyJ1IjoidHJpc3RlbiIsImEiOiJjajZoOXU4Z2kwNnppMnlxd2d6bTFvZ2xtIn0.PP7AoUakMfeqdXFHdsY0oA';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [-78, 44],
zoom: 5
});
const data = {
'type': 'FeatureCollection',
'features': [{
'type': 'Feature',
'properties': {
'mode': 'none'
},
'geometry': {
'type': 'LineString',
'coordinates': [
[
-75,
40.40
],
[
-75.92,
41.66
]
]
}
},
{
'type': 'Feature',
'properties': {
'mode': 'tunnel'
},
'geometry': {
'type': 'LineString',
'coordinates': [
[
-75.92,
41.66
],
[
-77.90,
42.98
]
]
}
},
{
'type': 'Feature',
'properties': {
'mode': 'none'
},
'geometry': {
'type': 'LineString',
'coordinates': [
[
-77.90,
42.98
],
[
-79.65,
43.69
]
]
}
}
]
};
map.on('load', function() {
map.addLayer({
id: 'route-case',
type: 'line',
source: {
type: 'geojson',
data,
},
layout: {
'line-cap': 'round'
},
paint: {
'line-color': 'black',
'line-width': 3,
'line-gap-width': 1
}
});
map.addLayer({
id: 'route',
type: 'line',
source: {
type: 'geojson',
data,
},
layout: {
'line-cap': 'round'
},
paint: {
'line-color': 'black',
'line-width': 3
}
});
map.addLayer({
id: 'route-dash',
type: 'line',
source: {
type: 'geojson',
data,
},
layout: {
'line-cap': 'round'
},
paint: {
'line-color': 'white',
'line-dasharray': [3, 3],
...