JSFiddle - React, Tailwind, and code Playground

by Tristen Brown

HTML

<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.0/mapbox-gl.js"></script>
<link rel="stylesheet" href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.0/mapbox-gl.css">
<div id="map"></div>

CSS

body {
    margin: 0;
    padding: 0;
  }

  #map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
  }

  .marker {
    background: #E9F3FF;
    color: #3C77C0;
    border: 2px solid #70A5E7;
    border-radius: 3px;
    display: inline-block;
    padding: 3px 6px;
  }

JavaScript

mapboxgl.accessToken = 'pk.eyJ1IjoidHJpc3RlbiIsImEiOiJjajZoOXU4Z2kwNnppMnlxd2d6bTFvZ2xtIn0.PP7AoUakMfeqdXFHdsY0oA';

const map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v11',
  center: [-79.4339, 43.7483],
  zoom: 10
});

const data = {
  'type': 'FeatureCollection',
  'features': [{
      'type': 'Feature',
      'properties': {
        'color': 'red',
        'sort': 1
      },
      'geometry': {
        'type': 'LineString',
        'coordinates': [
          [
            -79.55749511718749,
            43.87017822557581
          ],
          [
            -79.35012817382812,
            43.678797753207235
          ]
        ]
      }
    },
    {
      'type': 'Feature',
      'properties': {
        'color': 'yellow',
        'sort': 3
      },
      'geometry': {
        'type': 'LineString',
        'coordinates': [
          [
            -79.31716918945312,
            43.86126736277113
          ],
          [
            -79.57672119140625,
            43.69468677385367
          ]
        ]
      }
    },
    {
      'type': 'Feature',
      'properties': {
        'color': 'blue',
				'sort': 2
      },
      'geometry': {
        'type': 'LineString',
        'coordinates': [
          [
            -79.56710815429688,
            43.765143524274066
          ],
          [
            -79.27871704101562,
            43.7859669617277
          ]
        ]
      }
    }
  ]
};

map.on('load', function() {
  map.addLayer({
    id: 'route',
    type: 'line',
    source: {
      type: 'geojson',
      data,
    },
    layout: {
			'line-color': ['get', 'color'],
    },
    paint: {
      'line-color': ['get', 'color'],
      'line-width': 8
    }
  });
});