The Analysis Widgets provide access to the ArcGIS Spatial Analysis Service, which allows you to perform common spatial analyses on your hosted data, via the ArcGIS API for JavaScript. The analysis widgets feature:
Currently there are 22 analysis widgets available in the ArcGIS API for JavaScript, as well as in the ArcGIS REST API.
Widget (Links to documentation) |
Usage | Input Feature Layer Names and Types |
---|---|---|
AggregatePoints [ JavaScript API | REST API ] (added at v3.6) |
![]() |
|
CalculateDensity [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
ConnectOriginsToDestinations [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
CreateDriveTimeAreas [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
CreateBuffers [ JavaScript API | REST API ] (added at v3.6) |
![]() |
|
CreateViewshed [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
CreateWatersheds [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
DeriveNewLocations [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
DissolveBoundaries [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
EnrichLayer [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
ExtractData [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
FindExistingLocations [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
FindHotSpots [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
FindNearest [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
FindSimilarLocations [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
InterpolatePoints [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
MergeLayers [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
OverlayLayers [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
PlanRoutes [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
SummarizeNearby [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
SummarizeWithin [ JavaScript API | REST API ] (added at v3.7) |
![]() |
|
TraceDownstream [ JavaScript API | REST API ] (added at v3.12) |
![]() |
|
An ArcGIS.com subscription is required. Not only will you need to store data using your ArcGIS.com account, but also sign-in is always required to run an analysis job as a credit-based service. Executing analysis tasks and hosting feature services are not available to personal account users. See ArcGIS.com - Plans and ArcGIS Developers - Plans for more information.
In this section, we will build a sample that uses the SummarizeNearby widget to analyze the socioeconomic conditions near input locations. Before starting, you should already know how to build a simple map and add feature layers to the map. If not, check out Build your first application and Vector Feature Layer Samples.
Choose a widget that fits your needs. In this tutorial, we would like to analyze the median income near five proposed locations for a new retail store. SummarizeNearby is the widget best suited to complete this analysis.
Configure the layout of your application. We need to leave a room for the analysis widget to be added. A recommended way is to use Dojo's BorderContainer and ContentPanes. In the example below, we put two ContentPanes inside a BorderContainer. One ContentPane is anchored to the left to accomodate the widget, while the other is centered and will be used by the map. You may also use any other approach to layout your app.
<!DOCTYPE html>
<html>
<head>
...
<style>
html, body, #border-container {
height: 100%;
margin: 0;
}
</style>
<script src="//js.arcgis.com/3.46/"></script>
<script>
require([
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", ...
], function(){
...
};
</script>
</head>
<body class="claro">
<div id="border-container" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline',gutters:false">
<div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'" style="padding: 0;"></div>
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'left'" style="width: 300px;">
<div id="toolPane"></div>
</div>
</div>
</body>
</html>
Add the input feature layers to the map. Each of the analysis widgets requires specific feature input layers and geometry types. Refer to the Available Widgets table above to see which layers are needed for each analysis widget.
Keep in mind that you should construct the widget after all the input layers are loaded. A recommended way to do so is to use the map.addLayers() method to add all layers at once, and then listen to the map.on("layers-add-result") event.
var pointLayer = new FeatureLayer("http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/New_Store_Location/FeatureServer/0");
var polygonLayer = new FeatureLayer("https://demographics5.arcgis.com/arcgis/rest/services/USA_Consumer_Expenditures_2015/MapServer/48", {
opacity: 0.5
});
map.addLayers([polygonLayer, pointLayer]);
map.on("layers-add-result", function(){
...
});
Construct the widget. Load the module at "esri/dijit/analysis/SummarizeNearby"
, construct the widget in the callback function of map.on("layers-add-result"), and place the widget at a DOM node (In this case, <div id="toolPane"></div>
).
var summarizeNearby;
map.on("layers-add-result", function(){
summarizeNearby = new SummarizeNearby({
...
}, "toolPane");
});
If using only one layer, construct the widget in the callback function of map.on("layer-add-result").
var summarizeNearby;
map.on("layer-add-result", function(response){
if response.layer=== layerName {
summarizeNearby = new SummarizeNearby({
...
}, "toolPane");
}
});
Configure the widget. As many other widgets, you can specify properties in the first parameter of the constructor. These properties are used to configure the widget when initialized.
portalUrl
is recommended. You may set portalUrl
as either "https://www.arcgis.com"
or your organization's URL. The widget will figure out the path to its corresponding geoprocessing server. If you know which geoprocessing server you would like to use, specify analysisGpServer
instead.false
.showSelectFolder
is false
by default. The other three are true
if not specified.
map.on("layers-add-result", function(){
summarizeNearby = new SummarizeNearby({
sumNearbyLayer: pointLayer,
summaryLayers: [polygonLayer],
portalUrl: "https://www.arcgis.com",
map: map
}, "toolPane");
});
Listen to the .on("job-result") event and add results to the map. This event fires when an analysis job is completed. It returns an object with a property named value, from which you can get the resulted data and add them to the map.
false
or not set, value contains a url property. You can use this URL to create a feature layer.true
, value itself is a feature collection, which you can pass into the feature layer constructor.summarizeNearby.on("job-result", parseResult);
...
function parseResult(result){
var resultLayer = new FeatureLayer(result.value.url || result.value, {
outFields: ['*'],
infoTemplate: new InfoTemplate()
});
map.addLayer(resultLayer);
};