Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.28/esri/css/main.css">
  <script src="https://js.arcgis.com/4.28/"></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/rest/support/Query"
], (Map, MapView, FeatureLayer, Graphic, SimpleFillSymbol, Query) => {

  const whereClause = "NO_FARMS87 > 500";

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

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

  const listNode = document.getElementById("list_counties");
  
  const popupInfo = {
    title: "{NAME} County",
    content: "<b> Farms: {NO_FARMS87} </b>"
  }
  
  const counties = new FeatureLayer({
    portalItem: {
      id: "0875e77a2ff54dd689e169d7798d0905"
    },
    popupTemplate: popupInfo
  });
  
  map.add(counties);
  
  view.when(function() {
    const farmQuery = new Query({
      where: whereClause,
      returnGeometry: true,
      outFields: ["NAME", "NO_FARMS87"],
      orderByFields: ["NAME"],
      outSpatialReference: view.map.basemap.baseLayers.items[0].spatialReference
    });    
    counties.queryFeatures(farmQuery).then(displayResults);
  });
  
  const graphics = [];
  
  function displayResults(results) {
    const fragment = document.createDocumentFragment();
    
    results.features.forEach(function(county, index) {
      county.popupTemplate = popupInfo;
      
      graphics.push(county);
      
      const attributes = county.attributes;
      const name = attributes.NAME + " (" +
        attributes.NO_FARMS87 + ")";
        
      const 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);    
    
    const selLayer = new FeatureLayer({
      source: graphics,
      fields: counties.fields,
      objectIdField: "FID",
      renderer: {
        type: "simple",
        symbol: {
          type: "simple-fill", 
          color: "yellow"
        }
      }
    });
    map.add(selLayer);
  }  

  listNode.addEventListener("click", onListClickHandler);

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

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

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

Console