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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Dojo MultiSelect Dijit with ArcGIS JS API 3x v1</title>
    
    <link rel="stylesheet" href="https://js.arcgis.com/3.30/esri/css/esri.css" />
    <script src="https://js.arcgis.com/3.30/"></script>

    <style>
      body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
      }
      #bannerDiv {
        width: 100%;
        height: 190px;
        background-color: #FFCCCC;
        text-align: center;
        padding: 5px;
      }
      #viewDiv {
        position: absolute;
        width: 100%;
        height: calc(100% - 180px);
      }
    </style>

    <script>
      require([
        "esri/map",
        "esri/layers/FeatureLayer",
        "dijit/form/MultiSelect",
        "dojo/dom",
        "dojo/on"  
      ], function(Map, FeatureLayer, MultiSelect, dom, on) {
      
        var map = new Map("viewDiv", {
          center: [-73.95, 40.73], 
          zoom: 10,               
          basemap: "gray"
        });
                
        var flDistricts = new FeatureLayer(
          "https://services6.arcgis.com/0p6i4J6xhQas4Unf/arcgis/rest/services/NYC_Community_Districts/FeatureServer/0"
        );
        map.addLayer(flDistricts);
        
        
        function applyDefinition() {
          
          const selected = document.querySelectorAll('#boros option:checked');
          const values = Array.from(selected).map(el => el.value);

          var strDefinitionExpression = "";

          // build the where clause definition expression string based on user input
          if (values.length === 1) {
            strDefinitionExpression = "boroname = '" + values[0] + "'";
            flDistricts.setDefinitionExpression(strDefinitionExpression);
          }
          if (values.length > 1) {
            strDefinitionExpression = "boroname = '" + values[0] + "'";
            for (i=1; i<values.length; i++) {
              strDefinitionExpression = strDefinitionExpression + " OR boroname = '" + values[i] + "'";
              /// better maybe to use IN, rather than chaining ORs.
            }
               
            // filter the layer based on the where clause built from the multiselect box
            flDistricts.setDefinitionExpression(strDefinitionExpression);
          }
          
        } // end of function applyQueryDef()

        function clearDefinition() {

          var elemMultiSelect = dom.byId("boros");

          // deselect all elements in the multiselect box UI
          for (i=0; i<elemMultiSelect.length; i++) {
            elemMultiSelect[i].selected = false;
          }
          
          // clear out the definition expression so that all features draw
          flDistricts.setDefinitionExpression("");

        } // end of function clearQueryDef()

      // BUTTON CLICK EVENTS
          
        on(dom.byId("btnApplyDefinition"), "click", applyDefinition);
        on(dom.byId("btnClearDefinition"), "click", clearDefinition);
    
    
    
      }); //end of require
    </script>
  </head>

  <body>
    
    <div id="bannerDiv">
      <h4>How to use a dojo/MultiSelect box to apply a layer definition expression</h4>
      <h5>Use click, shift-click, ctrl-click to multi-select values, then click APPLY.</h5>

      <select data-dojo-type="dijit/form/MultiSelect" 
              multiple="true" style="height:80px;width:100px" 
              id="boros" name="boros" size="4">
        <option value="Manhattan">Manhattan</option>
        <option value="Bronx">Bronx</option>
        <option value="Brooklyn">Brooklyn</option>
        <option value="Queens">Queens</option>        
        <option value="Staten Island">Staten Island</option>
      </select>      
      <button class="btn" id="btnApplyDefinition">Apply</button>
      <button class="btn" id="btnClearDefinition">Clear</button>

    </div>
  
    <div id="viewDiv"></div>
      
  </body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console