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"
    />

    <!--
     ArcGIS API for JavaScript, https://js.arcgis.com
     For more information about the widgets-layerlist-actions sample,
     read the original sample description at developers.arcgis.com.
     https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-actions/
     -->
    <title>
      LayerList widget with actions | Sample | ArcGIS API for JavaScript 4.24
    </title>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
        overflow: hidden;
      }

      #filterDiv {
        background: #fff;
        padding: 10px;
      }
    </style>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.24/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.24/"></script>

    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/GroupLayer",
        "esri/layers/FeatureLayer",
        "esri/widgets/LayerList",
        "esri/widgets/Slider"
      ], (Map, MapView, GroupLayer, FeatureLayer, LayerList, Slider) => {
        const censusGroups = new FeatureLayer({
          url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/1",
          title: "Census Block Group",
          minScale: 0,
          maxScale: 0,
          definitionExpression:
            "STATE_FIPS = '06' OR STATE_FIPS = '04' OR STATE_FIPS = '32'"
        });

        const counties = new FeatureLayer({
          url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2",
          title: "Detailed counties",
          minScale: 0,
          maxScale: 0,
          definitionExpression:
            "STATE_FIPS = '06' OR STATE_FIPS = '04' OR STATE_FIPS = '32'"
        });

        const states = new FeatureLayer({
          url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3",
          title: "Detailed states",
          minScale: 0,
          maxScale: 0
        });

        const groupLayer0 = new GroupLayer({
          title: "US counties and states",
          visible: true,
          // visibilityMode: "exclusive",
          layers: [states, counties],
          opacity: 0.75
        });

        const groupLayer1 = new GroupLayer({
          title: "US census block points and groups",
          visible: true,
          // visibilityMode: "exclusive",
          layers: [censusGroups],
          opacity: 0.75
        });

        // Create a map and add the group layer to it
        const map = new Map({
          basemap: "gray-vector",
          layers: [groupLayer1, groupLayer0]
        });

        // Add the map to a MapView
        const view = new MapView({
          center: [-118, 36],
          zoom: 5,
          container: "viewDiv",
          map: map
        });

        view.ui.add("filterDiv", "top-left");

        document.getElementById("statesFIPS").addEventListener("change", () => {
          view.allLayerViews.forEach((lv) => {
            if (lv.layer.type === "feature") {
              lv.filter = {
                where:
                  "STATE_FIPS = '" +
                  document.getElementById("statesFIPS").value +
                  "'"
              };
            }
          });
        });

        // Creates actions in the LayerList.

        function defineActions(event) {
          const item = event.item;

          if (item.layer.type === "group") {
            item.actionsSections = [
              [
                {
                  title: "Go to full extent",
                  className: "esri-icon-zoom-out-fixed",
                  id: "full-extent"
                },
                {
                  title: "Layer information",
                  className: "esri-icon-description",
                  id: "information"
                }
              ],
              [
                {
                  title: "Increase opacity",
                  className: "esri-icon-up",
                  id: "increase-opacity"
                },
                {
                  title: "Decrease opacity",
                  className: "esri-icon-down",
                  id: "decrease-opacity"
                }
              ]
            ];
          }

          // Adds a slider for updating a group layer's opacity
          
          console.log(item.children.length, item.parent)
          if (item.layer.type === "group") {
            // console.log("here")
            const slider = new Slider({
              min: 0,
              max: 1,
              precision: 2,
              values: [1],
              visibleElements: {
                labels: true,
                rangeLabels: true
              }
            });

            item.panel = {
              content: slider,
              className: "esri-icon-sliders-horizontal",
              title: "Change layer opacity"
            };

            slider.on("thumb-drag", (event) => {
              const { value } = event;
              item.layer.opacity = value;
            });
          }
        }

        view.when(() => {
          // Create the LayerList widget with the associated actions
          // and add it to the top-right corner of the view.

          const layerList = new LayerList({
            view: view,
            // executes for each ListItem in the LayerList
            listItemCreatedFunction: defineActions
          });

          // Event listener that fires each time an action is triggered

          layerList.on("trigger-action", (event) => {
            
            //console.log(event, event.item.layer.fullExtent);
            // Capture the action id.
            const id = event.action.id;

            if (id === "full-extent") {
              view.goTo({
                center: [-118, 36],
                zoom: 5
              });
            } else if (id === "information") {
              // if the information action is triggered, then
              // open the item details page of the service layer
              window.open(event.item.layer.layers.getItemAt(0).url);
            } else if (id === "increase-opacity") {
              // if the increase-opacity action is triggered, then
              // increase the opacity of the GroupLayer by 0.25

              if (event.item.layer.opacity < 1) {
                event.item.layer.opacity += 0.25;
              }
            } else if (id === "decrease-opacity") {
              // if the decrease-opacity action is triggered, then
              // decrease the opacity of the GroupLayer by 0.25

              if (event.item.layer.opacity > 0) {
                event.item.layer.opacity -= 0.25;
              }
            }
          });

          // Add widget to the top right corner of the view
          view.ui.add(layerList, "top-right");
        });
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="filterDiv" class="esri-widget">
      <p>Filter by state</p>
      <select id="statesFIPS" class="esri-widget">
        <option value="04" selected>Arizona</option>
        <option value="06">Calfornia</option>
        <option value="32">Nevada</option>
      </select>
      <br />
    </div>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console