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 http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,
      user-scalable=no">
    <title>MapView</title>

    <style type="text/css" media="screen">
    html,
    body,
    #viewDiv {
      width: 100%;
      height: 100%;
      padding: 0;
      margin: 0;
    }

    #options {
      max-width: 350px;
      font-size: 0.8em;
      position: absolute;
      top: 1em;
      right: 1em;
      background: white;
      padding: 1em;
    }
  </style>
    <link rel="stylesheet"
      href="https://js.arcgis.com/next/esri/css/main.css">
    <script src="https://js.arcgis.com/next"></script>
    <script>
    require([
      "esri/Graphic",
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer",
      "esri/core/Collection",
    ], function (
      Graphic,
      Map,
      MapView,
      FeatureLayer,
      Collection
    ) {

      map = new Map({
        basemap: "topo"
      });

      view = new MapView({
        container: "viewDiv",
        map: map,
        zoom: 4,
        center: [-100, 40]
      });

      var layer = new FeatureLayer({
        url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Testing/FeatureServer/0",
        outFields: ["*"]
      });

      map.add(layer);

      var selectedFeature = null;
      var addFeatures = [];
      var deleteFeatures = [];
      var updateFeatures = [];

      view.when(() => {
        view.on("click", (evt) => {
          var screenPoint = {
            x: evt.x,
            y: evt.y
          };

          view.hitTest(screenPoint)
            .then((response) => {
              if (!response) {
                return;
              }

              selectedFeature = response.results[0].graphic;
              document.getElementById("selectedFeatureOID").innerHTML = selectedFeature.attributes[layer.objectIdField];
              document.getElementById("selectedFeatureId").innerHTML = selectedFeature.attributes.GlobalID;

              var objectId = selectedFeature.attributes[layer.objectIdField];
              var query = { objectIds: [objectId] };
            });
        });
      });

      document.getElementById("addFeature").addEventListener("click", () => {
        document.getElementById("viewDiv").style.cursor = "crosshair";

        const handler = view.on("click", function (event) {
          // remove click event handler once user clicks on the view
          // to create a new feature
          handler.remove();
          event.stopPropagation();

          if (event.mapPoint) {
            point = event.mapPoint.clone();
            point.z = undefined;
            point.hasZ = false;

            var attributes = {
              SEVERITY: Number(document.getElementById("severity").value)
            };

            attributes[layer.globalIdField] = document.getElementById("parentGlobalId").value;

            // Create a new feature using one of the selected
            // template items.
            const feature = new Graphic({
              geometry: point,
              attributes: attributes
            });

            addFeatures.push(feature);
            selectedFeature = feature;
            console.log("addFeatures: ", addFeatures);
            console.log("selectedFeature: ", selectedFeature);
            document.getElementById("addFeatures").innerHTML = addFeatures.length;
            document.getElementById("selectedFeatureOID").innerHTML = selectedFeature.attributes[layer.objectIdField] || "new";
            document.getElementById("selectedFeatureId").innerHTML = selectedFeature.attributes[layer.objectIdField] || "new";
            document.getElementById("viewDiv").style.cursor = "auto";
          } else {
            console.error("event.mapPoint is not defined");
          }
        });
      });
      
       document.getElementById("updateFeature").addEventListener("click", () => {
        if (!selectedFeature) {
          alert("select a feature by clicking on it!");
          return;
        }
    
        selectedFeature.attributes.SEVERITY = Number(document.getElementById("severity").value);
        updateFeatures.push(selectedFeature);

        console.log("updateFeatures: ", updateFeatures);
        document.getElementById("updateFeatures").innerHTML = updateFeatures.map((f) => f.globalId).join(", ");
         
         
      });

      document.getElementById("deleteFeature").addEventListener("click", () => {
        if (!selectedFeature) {
          alert("select a Feature by clicking on it!");
          return;
        }
    
        var objectId = selectedFeature.attributes.OBJECTID;
        deleteFeatures.push({ objectId: objectId });

        // delete operation does not support globalIds at 4.15.
        // deleteFeatures.push({ globalId: id });

        console.log("deleteFeatures: ", deleteFeatures);
        document.getElementById("deleteFeatures").innerHTML = deleteFeatures.map((f) => f.objectId).join(", ");
      });

      document.getElementById("applyEdits").addEventListener("click", () => {

        console.log(deleteFeatures, deleteFeatures)
        const edits = {
          addFeatures: new Collection(addFeatures),
          deleteFeatures: deleteFeatures,
          updateFeatures: updateFeatures
        }
        const options = {
          globalIdUsed: true,
          rollbackOnFailureEnabled: true
        };

        layer.applyEdits(edits, options).then((result) => {
          console.log("edits added: ", result);

          selectedFeature = null;
          addFeatures = [];
          deleteFeatures = [];
          updateFeatures = [];

          document.getElementById("selectedFeatureId").innerHTML = null;
          document.getElementById("selectedFeatureOID").innerHTML = null;
          document.getElementById("addFeatures").innerHTML = null;
          document.getElementById("deleteFeatures").innerHTML = null;
          document.getElementById("updateFeatures").innerHTML = null;
        }).then(() => {
        }).catch((err) => {
          console.log("apply edits failed: ", err);
        });
      });

    });

  </script>
  </head>

  <body>
    <div id="viewDiv">
      <div id="options">
        Feature oid: <span id="selectedFeatureOID"></span><br/><br/>
            globalId: <span id="selectedFeatureId"></span>

            <br><br>
            <hr><br>

            Severity:
            <select id="severity">
              <option value="0">0</option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
            </select><br><br>
            Global Id: <input type="text" id="parentGlobalId"><br>
            <br>
            <button id="addFeature">Add Feature</button>
            <button id="deleteFeature">Delete Feature</button>
            <button id="updateFeature">Update Feature</button>

            <br><br>
            Add Features: <span id="addFeatures"></span></br><br/>
            Delete Features: <span id="deleteFeatures"></span><br/><br/>
            Update Features: <span id="updateFeatures"></span><br/>

            <br><br>
            <hr><br>
            <button id="applyEdits">Apply Edits</button>
          </div>
        </body>

      </html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console