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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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>Geoprocessing - hotspot analysis - 4.12</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #sidebar {
        position: absolute;
        top: 0;
        right: 0;
        height: 85%;
        width: 320px;
        overflow-y: auto;
      }

      .label {
        color: white;
      }

      #hotspotButton {
        border: none;
        background-color: rgba(229, 89, 52, 0.75);
        color: #fff;
        margin: 1px;
        width: 50%;
        padding: 10px;
        overflow: auto;
        text-align: center;
        cursor: pointer;
        font-size: 1em;
      }
    </style>

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

  <body>
    <div id="viewDiv">
      <div id="sidebar" class="esri-widget">
        <div id="text">
          <div id="info">
            <div style="padding-bottom:20px; padding-left:10px;">
              <br />
              <input type="date" id="dateFrom" name="dateFrom" min="1998-01-01" max="1998-05-31" value="1998-01-01" required ><br />
              <br /><br />
              <input type="date" id="dateTo" name="dateTo" min="1998-01-01" max="1998-05-31" value="1998-01-07" required ><br />
            </div>
            <div align="center">
              <br />
              <button id="hotspotButton" class="esri-widget">
                Analyze 911 Calls
              </button>
            </div>
            <div style="padding-bottom:20px; padding-left:10px;">
              <br /><br />
              <label id="message" class="label"></label>
            </div>
            <div id="legendDiv" class="esri-widget"></div>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

              
            
!

CSS

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

      #sidebar {
        position: absolute;
        top: 0;
        right: 0;
        height: 85%;
        width: 320px;
        overflow-y: auto;
      }

      .label {
        color: white;
      }

      #hotspotButton {
        border: none;
        background-color: rgba(229, 89, 52, 0.75);
        color: #fff;
        margin: 1px;
        width: 50%;
        padding: 10px;
        overflow: auto;
        text-align: center;
        cursor: pointer;
        font-size: 1em;
      }
              
            
!

JS

              
                      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/tasks/Geoprocessor",
        "esri/widgets/Legend",
        "esri/layers/support/ImageParameters"
      ], function(Map, MapView, Geoprocessor, Legend, ImageParameters) {
        document
          .getElementById("hotspotButton")
          .addEventListener("click", findHotspot);

        var message = document.getElementById("message");

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

        var view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-122.812, 45.474],
          zoom: 12
        });

        // initialize geoprocessor task
        var gpUrl =
          "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot";

        var gp = new Geoprocessor(gpUrl);
        gp.outSpatialReference = {
          // autocasts as new SpatialReference()
          wkid: 102100
        };

        function findHotspot() {
          var params = {
            Query: buildDefinitionQuery()
          };

          // clean up previous results
          cleanup();
          gp.submitJob(params).then(drawResultData, errBack, progTest);
        }

        function buildDefinitionQuery() {
          var defQuery;
          // get dates and build definition expression

          var startDate = document.getElementById("dateFrom").value;
          var endDate = document.getElementById("dateTo").value;

          var def = [];
          def.push("(Date >= date '" + startDate + "' and Date <= date '" +
            endDate + "')");
          def.push(
            "(Day = 'SUN' OR Day= 'SAT' OR Day = 'FRI' OR Day ='MON' OR Day='TUE' OR Day='WED' OR Day ='THU')"
          );

          if (def.length > 1) {
            defQuery = def.join(" AND ");
          }
          
          return defQuery;
        }

        function cleanup() {
          // remove the geoprocessing result layer from the map
          map.layers.forEach(function(layer, i) {
            if (layer.title === "HotspotLayer") {
              map.layers.remove(layer);
            }
          });
        }

        function drawResultData(result) {
 gp.getResultData(result.jobId, "Output_Features").then(function(data){
  console.log("Analyzed " + data.value.features.length + " points");
});         
          
          
          // add wait message
          message.innerText = "Adding MapImageLayer to the map...";
          // set imageParameters
          var imageParams = new ImageParameters({
            format: "png32",
            dpi: 300
          });

          // get the task result as a MapImageLayer
          var resultLayer = gp.getResultMapImageLayer(result.jobId);
          resultLayer.opacity = 0.7;
          resultLayer.title = "HotspotLayer";

          // add the result layer to the map
          map.layers.add(resultLayer);

          // once the MapImageLayer is added to the map,
          // update the message and add the legend
          resultLayer.on("layerview-create", function() {
            message.innerText = "Job status: 'job-succeeded'";
            // initialize a legend widget for the geoprocessing service result
            var legend = new Legend({
              view: view,
              container: "legendDiv"
            });
          });
        }

        function progTest(value) {
          message.innerText = "Job status: " + "'" + value.jobStatus + "'";
          console.log(value.jobStatus);
        }

        function errBack(error) {
          message.innerText = "";
          console.log("gp error: ", error);
        }
      });
              
            
!
999px

Console