Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Clickable sidebar demo</title>
  
  <link rel="stylesheet" href="https://js.arcgis.com/4.12/esri/css/main.css">
  <script src="https://js.arcgis.com/4.12/"></script>
</head>



<body>
  <div class="panel-container">
    <div class="panel-side">
      <h2>Selected Counties</h2>
      <ul id="list_counties">
        <li>Loading&hellip;</li>
      </ul>
    </div>
    <div id="viewDiv"></div>
  </div>
</body>
</html>
              
            
!

CSS

              
                
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
    
    .panel-container {
      position: relative;
      width: 100%;
      height: 100%;
    }

    .panel-side {
      padding: 2px;
      box-sizing: border-box;
      width: 300px;
      height: 100%;
      position: absolute;
      top: 0;
      right: 0;
      color: #fff;
      background-color: rgba(0, 0, 0, 0.6);
      overflow: auto;
      z-index: 60;
    }

    .panel-side h2 {
      padding: 0 20px;
      margin: 20px 0;
    }

    .panel-side ul {
      list-style: none;
      margin: 0;
      padding: 0;
    }

    .panel-side li {
      padding: 5px 20px;
    }

    .panel-result {
      cursor: pointer;
      margin: 2px 0;
      background-color: rgba(0, 0, 0, 0.3);
    }

    .panel-result:hover,
    .panel-result:focus {
      color: orange;
      background-color: rgba(0, 0, 0, 0.75);
    }    
              
            
!

JS

              
                require([
  "esri/Map",
  "esri/views/MapView",
  "esri/layers/FeatureLayer",
  "esri/Graphic",
  "esri/symbols/SimpleFillSymbol",
  "esri/layers/GraphicsLayer",
  "esri/tasks/support/Query",
  "dojo/domReady!"
], function(Map, MapView, FeatureLayer, Graphic, SimpleFillSymbol, GraphicsLayer, Query) {

  var whereClause = "NO_FARMS87 > 500";

  var map = new Map({
    basemap: "dark-gray"
  });

  var view = new MapView({
    container: "viewDiv",
    map: map,
    zoom: 7,
    center: [-78, 41]
  });

  var listNode = document.getElementById("list_counties");
  
  var popupInfo = {
    title: "{NAME} County",
    content: "<b> Farms: {NO_FARMS87} </b>"
  }
  
  var counties = new FeatureLayer({
    portalItem: {
      id: "63606938ae2245b1b293c60cfb9c0d30"
    },
    popupTemplate: popupInfo
  });

  var resultsLayer = new GraphicsLayer();
  
  map.addMany([counties, resultsLayer]);

  var farmQuery = new Query({
    where: whereClause,
    returnGeometry: true,
    outFields: ["NAME", "NO_FARMS87"]
  });
  
  counties.when(function() {
    return counties.queryFeatures(farmQuery);
  }).then(displayResults);  

  var graphics = [];
  
  function displayResults(results) {
    var fragment = document.createDocumentFragment();
    
    results.features.forEach(function(county, index) {
      county.symbol = new SimpleFillSymbol({
        color: "yellow"
      });
      
      graphics.push(county);
      
      var attributes = county.attributes;
      var name = attributes.NAME + " (" +
        attributes.NO_FARMS87 + ")";
        
      var li = document.createElement("li");
      li.classList.add("panel-result");
      li.tabIndex = 0;
      li.setAttribute("data-result-id", index);
      li.textContent = name;

      fragment.appendChild(li);
    });

    listNode.innerHTML = "";
    listNode.appendChild(fragment);    
    
    resultsLayer.addMany(graphics);   
  }  

  listNode.addEventListener("click", onListClickHandler);

  function onListClickHandler(event) {
    var target = event.target;
    var resultId = target.getAttribute("data-result-id");

    var result = resultId && graphics && graphics[parseInt(resultId,
      10)];

    if (result) {
      view.popup.open({
        features: [result],
        location: result.geometry.centroid
      });
    }
  }
});
              
            
!
999px

Console