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.Layers.FeatureLayer documentation.

<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="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
  <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>

  <!-- Load Esri Leaflet from CDN -->
  <script src="http://cdn-geoweb.s3.amazonaws.com/esri-leaflet/1.0.0-rc.2/esri-leaflet.js"></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: 10;
    padding: 1em;
    background: white;
  }
</style>

<div id="map"></div>
<div id="info-pane" class="leaflet-bar"></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('http://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/bike_rte/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').innerText = 'Hover to Inspect';
  });

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

</body>
</html>