Esri Leaflet

Styling lines

Custom styles for line features with the style option. More information about Feature Layers can be found in the L.esri.FeatureLayer documentation.

Hover to inspect
<html>
<head>
  <meta charset=utf-8 />
  <title>Styling lines</title>
  <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />

    <!-- Load Leaflet from CDN -->
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css"
    integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ=="
    crossorigin=""/>
    <script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js"
    integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log=="
    crossorigin=""></script>


    <!-- Load Esri Leaflet from CDN -->
    <script src="https://unpkg.com/esri-leaflet@2.1.1/dist/esri-leaflet.js"
    integrity="sha512-ECQqaYZke9cSdqlFG08zSkudgrdF6I1d8ViSa7I3VIszJyVqw4ng1G8sehEXlumdMnFYfzY0tMgdQa4WCs9IUw=="
    crossorigin=""></script>


  <style>
    body { margin:0; padding:0; }
    #map { position: absolute; top:0; bottom:0; right:0; left:0; }
  </style>
</head>
<body>

<style>
  #info-pane {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 400;
    padding: 1em;
    background: white;
  }
</style>

<div id="map"></div>
<div id="info-pane" class="leaflet-bar">Hover to inspect</div>

<script type='text/javascript'>
  var map = L.map('map').setView([45.5275, -122.6717], 14);

  L.esri.basemapLayer('Streets').addTo(map);

  var bikePaths = L.esri.featureLayer({
    url: 'https://services.arcgis.com/uCXeTVveQzP4IIcx/ArcGIS/rest/services/Bike_Routes/FeatureServer/0',
    style: function (feature) {
      var c,o = 0.75;
      switch (feature.properties.BIKEMODE) {
        case 'Low traffic through street':
          c = '#007D7D';
          break;
        case 'Bike boulevard':
          c = '#00FF3C';
          break;
        case 'Caution area':
          c = '#FF0000';
          break;
        case 'Local multi-use path':
          c = '#00BEFF';
          break;
        case 'Regional multi-use path':
          c = '#b1a9d0';
          break;
        case 'Moderate traffic through street':
          c = '#FFEB00';
          break;
        case 'Planned multi-use path':
          c = '#000000';
          break;
        case 'Bike lane':
          c = '#328000';
          o = '0.70';
          break;
        case 'High traffic through street':
          c = '#FFA500';
          break;
        case 'Planned bike lane':
          c = '#000000';
          o = '1.0';
          break;
        default:
          c = '#C0C0C0';
      }
      return {color: c, opacity: o, weight: 5};
    }
  }).addTo(map);

  bikePaths.on('mouseout', function(e){
    document.getElementById('info-pane').innerHTML = 'Hover to Inspect';
  });

  bikePaths.on('mouseover', function(e){
    document.getElementById('info-pane').innerHTML = e.layer.feature.properties.BIKEMODE;
  });
</script>

</body>
</html>