function addRoute(coords) {
  // If a route is already loaded, remove it
  if (map.getSource('route')) {
    map.removeLayer('route');
    map.removeSource('route');
  } else {
    // Add a new layer to the map
    map.addLayer({
      id: 'route',
      type: 'line',
      source: {
        type: 'geojson',
        data: {
          type: 'Feature',
          properties: {},
          geometry: coords
        }
      },
      layout: {
        'line-join': 'round',
        'line-cap': 'round'
      },
      paint: {
        'line-color': '#FF0000',
        'line-width': 8,
        'line-opacity': 0.8
      }
    });
  }
}
// Draw the Map Matching route as a new layer on the map
Draw the Map Matching route as a new layer on the map
Draw the Map Matching route as a new layer on the map
function addRoute(coords) {
  if (map.getSource('route')) {
    map.removeLayer('route');
    map.removeSource('route');
  } else {
    map.addLayer({
      id: 'route',
      type: 'line',
      source: {
        type: 'geojson',
        data: {
          type: 'Feature',
          properties: {},
          geometry: coords
        }
      },
      layout: {
        'line-join': 'round',
        'line-cap': 'round'
      },
      paint: {
        'line-color': '#FF0000',
        'line-width': 8,
        'line-opacity': 0.8
      }
    });
  }
}
function addRoute ( coords ) { if ( map . getSource ( 'route' ) ) { map . removeLayer ( 'route' ) ; map . removeSource ( 'route' ) ; } else { map . addLayer ( { id : 'route' , type : 'line' , source : { type : 'geojson' , data : { type : 'Feature' , properties : { } , geometry : coords } } , layout : { 'line-join' : 'round' , 'line-cap' : 'round' } , paint : { 'line-color' : '#FF0000' , 'line-width' : 8 , 'line-opacity' : 0.8 } } ) ; } }
Draw the Map Matching route as a new layer on the map
Draw the Map Matching route as a new layer on the map
// If a route is already loaded, remove it // Add a new layer to the map