JSFiddle - React, Tailwind, and code Playground

by George Obregon

HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset='utf-8' />
  <title>Create a route using the Mapbox Directions API</title>
  <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
  <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.js'></script>
  <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.css' rel='stylesheet' />
  <style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
  </style>
</head>
<body>
<style>
  .info-box {
    height: 100px;
    width: 150px;
    position: absolute;
    top: 20px;
    left: 10px;
    background-color: rgba(255, 255, 255, .9);
    padding: 15px;
    text-align: left;
    font-family: 'Arial';
    margin: 0;
    font-size: 13px;
  }
</style>

<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.0.0/mapbox-gl-draw.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.0.0/mapbox-gl-draw.css' type='text/css'/>
<div id='map'></div>
<div class='info-box'>
  <p>Draw your route using the draw tools (25 points max)</p>
  <div id='calculated-line'></div>
</div>

<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZ3JhZmEiLCJhIjoiY2lvOHdtcDVlMDMwN3ZibHpucHczemQ4dSJ9.xfu_0kXfz1Nymp2LIyLS4Q';
var map = new mapboxgl.Map({
  container: 'map', // container id
  style: 'mapbox://styles/mapbox/streets-v9', //hosted style id
  center: [-122.675246,45.529431], // starting position
  zoom: 13, // starting zoom
  minZoom: 11 // keep it local
});

var draw = new MapboxDraw({
  displayControlsDefault: false,
  controls: {
    line_string: true,
    trash: true
  },
  styles: [
    // ACTIVE (being drawn)
    // line stroke
    {
      "id": "gl-draw-line",
      "type": "line",
      "filter": ["all", ["==", "$type", "LineString"], ["!=", "mode", "static"]],
      "layout": {
        "line-cap": "round",
        "line-join": "round"
      },
      "paint": {
       ...