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>FeatureLayer - applyEdits</title>

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

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

  <script>
    require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/layers/GraphicsLayer",
        "esri/widgets/Sketch/SketchViewModel",
        "esri/smartMapping/statistics/uniqueValues"
      ],
      function(
        Map, MapView,
        FeatureLayer, GraphicsLayer, SketchViewModel, uniqueValues
      ) {
      
      var graphicsLayer = new GraphicsLayer();
        var map = new Map({
          basemap: "gray", 
          layers: [graphicsLayer]
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-88.14, 41.77],
          zoom: 14
        });
       view.ui.add("select-by-polygon", "top-left");
       view.ui.add("editing", "top-right");
      
      const selectFeatureValue = document.getElementById("featureValues");
      
      const featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Crime_Map_Demo/FeatureServer/0",
          outFields: ["*"],
          // popupEnabled: false,
          id: "incidentsLayer",
          popupTemplate: {
            title: "{ucrdesc}",
            content: "This should be updated <br/><b>ucrdesc:</b> {ucrdesc} <br/> <b>neighborhood:</b> {neighborhood}"
          }
        });
      map.add(featureLayer);
      
      // read unique values from a field.
      uniqueValues({
        layer: featureLayer,
        field: "ucrdesc"
      }).then(function(response){
        var infos = response.uniqueValueInfos;
        infos.forEach(function(info){
          var el = document.createElement("option");
          el.textContent = info.value;
          el.value = info.value;   
          selectFeatureValue.appendChild(el);
        });
       selectFeatureValue.selectedIndex = 1;
      });
      
      let featureLayerView;
      let selectedFeatureForUpdate;
      view.whenLayerView(featureLayer).then(function(lv){
        featureLayerView = lv;
      });
      
       const selectButton = document.getElementById("select-by-polygon");
       selectButton.addEventListener("click", function () {
         graphicsLayer.removeAll();
         sketchViewModel.create("rectangle");
        });
      
        // create a new sketch view model set its layer
        const sketchViewModel = new SketchViewModel({
          view: view,
            layer: graphicsLayer
          });
        sketchViewModel.on("create", function (event) {
          if (event.state === "complete") {
            view.graphics.removeAll();
            graphicsLayer.remove(event.graphic);
            selectFeatures(event.graphic.geometry);
          }
        });
      
        function selectFeatures(geometry) {
            const query = {
              geometry: geometry,
              outFields: ["*"],
              returnGeometry: false
            };

            featureLayerView.queryFeatures(query)
              .then(function (results) {
                const graphics = results.features;
                if (results.features.length === 0) {
                  featureLayerView.effect = null;
                } else {
                  selectedFeatureForUpdate = results.features;
                  featureLayerView.effect = {
                    filter: {
                      geometry: query.geometry
                    },
                    excludedEffect: "blur(5px) grayscale(80%)"
                  };
                  results.features.forEach(function(feature){
                    console.log(feature.attributes.ucrdesc);
                    console.log("feature.geoemtry", feature.geometry);
                  })
                  document.getElementById("bulkUpdate").disabled = false;
                }
              })
              .catch(function(err){
              console.log("layer view err", err)
            });
        }

        document.getElementById("bulkUpdate").addEventListener("click", function() {
          
 var updateFeatures = selectedFeatureForUpdate.map(function(feature, i){
   feature.attributes["ucrdesc"] = document.getElementById("featureValues").value;
   feature.attributes["neighborhood"] = "new neigborhood";
   return feature;
 });
     
          featureLayer.applyEdits({
            updateFeatures: updateFeatures
          }).
          then(function(results){
            console.log("update results", results);
          }).
          catch(function(err){
            console.log(err);
          });
        });
      });
  </script>
</head>

<body>
  <div id="editing">
    <select id="featureValues"></select>
    <button id="bulkUpdate" disabled>Batch Update</button>
  </div>
  <div id="viewDiv"></div>
  <div id="select-by-polygon"
     class="esri-widget esri-widget--button esri-widget esri-interactive"
    title="Select features by polygon">
    <span class="esri-icon-checkbox-unchecked"></span>
  </div>
</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console