Geoprocessing - hotspot analysis

This sample demonstrates how to use the geoprocessor asynchronously to calculate a hotspot analysis based on the frequency of 911 calls. It calculates the frequency of these calls within a given study area during a specified constrained time period set between 1/1/1998 and 5/31/1998. To run the hotspot analysis, click on the Analyze 911 Calls button.

How it works

When the Analyze 911 Calls button is clicked, an event listener triggers the function findHotspot(), which accesses the user-defined dates and passes it as a parameter to geoprocessor. The submitJob() method is subsequently called and performs asynchronously. This method returns immediately after the job is submitted with a JobInfo object that contains information relating to the state of the execution of geoprocessor. The waitForJobCompletion() method recognizes when the geoprocessor has finished processing, then calls the function to draw the result on the map.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
const params = {
  Query: buildDefinitionQuery()
};
geoprocessor.submitJob(gpUrl, params).then((jobInfo) => {
  const options = {
    statusCallback: (jobInfo1) => {
      progTest(jobInfo1);
    }
  };
  jobInfo.waitForJobCompletion(options).then((jobInfo2) => {
    drawResultData(jobInfo2);
  });
});

While the submitJob() method is running, the progTest function pushes updates from the method to the sidebar div.

Use dark colors for code blocksCopy
1
2
3
function progTest(value) {
  message.innerText = "Job status: " + "'" + value.jobStatus + "'";
}

The drawResultData callback function obtains the result as a MapImageLayer when the method completes successfully. It then adds the MapImageLayer to the map.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
function drawResultData(result) {
  // use the result (JobInfo object) to fetch a MapImageLayer
  result.fetchResultMapImageLayer(result.jobId).then((resultLayer) => {
    resultLayer.opacity = 0.7;
    resultLayer.title = "HotspotLayer";

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

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.