地理处理 - 热点分析

尝试一下在线预览

此示例演示了如何异步使用地理处理器根据 911 呼叫频率计算热点分析。它计算在 1998 年 1 月 1 日至 1998 年 5 月 31 日之间设置的指定约束时间段内给定研究区域内这些呼叫的频率。要运行热点分析,请单击 Analyze 911 Calls 按钮。

工作原理

单击 Analyze 911 Calls 按钮时,事件侦听器将触发函数 findHotspot(),该函数访问用户定义的日期并将其作为参数传递给地理处理器。随后调用 submitJob() 方法并以异步方式执行。在提交作业后,此方法将立即返回 JobInfo 对象,该对象包含与地理处理器执行状态相关的信息。waitForJobCompletion() 方法识别地理处理器何时完成处理,然后调用该函数在地图上绘制结果。

             
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);
  });
});

submitJob() 方法运行时,progTest 函数将更新从方法推送到侧边栏 div。

   
1
2
3
function progTest(value) {
  message.innerText = "Job status: " + "'" + value.jobStatus + "'";
}

当方法成功完成时,drawResultData 回调函数将获取作为 MapImageLayer 的结果。然后,它将 MapImageLayer 添加到地图中。

          
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.