A geoprocessing service on a stand-alone server running ArcGIS Server and a service on a federated server that powers a web tool can be consumed in a custom web app, providing the clients of your web app with geoprocessing and analysis solutions. A web app can be built from scratch using ArcGIS Maps SDK for JavaScript. Alternatively, you can deploy a configurable web app using the analysis widget ArcGIS Experience Builder in ArcGIS Enterprise.
Regardless of the method of building a web app, the communication of the underlying geoprocessing service occurs through REST and connects to the service end point on ArcGIS Server.
- The service end point is a URL, typically in the following format: https://organization.example.com/<context>/rest/<ServiceName>.
- Each service end point has information that describes the service, the operations that can be performed, and the resources that compose the service. In the geoprocessing context, one or more tools compose the resources of a service.
To learn more about using web tools with ArcGIS REST API, see Geoprocessing services.
If you do not want to build a web app but still want to have a rich web experience, you can use Map Viewer in ArcGIS Enterprise.
Web tools and geoprocessing services in custom web apps
Typically, a custom web app is constructed using ArcGIS Maps SDK for JavaScript. Although you can construct any app that can communicate with the service over REST, the following discussion focuses on JavaScript. If you're already comfortable with JavaScript and geoprocessing, you may want to review the samples and code snippets. Otherwise, the remainder of this section outlines the following process to add geoprocessing to a web app:
- Initializing the geoprocessing service
- Setting up input parameters
- Running the geoprocessing service
- Getting and handling the result or results
The following JavaScript code is taken from the Calculate Viewshed sample with only the relevant pieces to demonstrate the four steps required to run geoprocessing tools. The sample in the JavaScript help provides a complete example, whereas the following only produces a working web page with additional code:
// esri.tasks.Geoprocessor is required for using Geoprocessor.
// Add it along with other dojo.require statements.
dojo.require(esri.tasks.Geoprocessor);
// Step 1: Initialize the geoprocessing and point to the REST URL
var gpUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Elevation/ESRI_Elevation_World/GPServer/Viewshed";
var gp = new Geoprocessor(gpUrl);
// Set output spatial reference
gp.outSpatialReference = { wkid: 102100 };
function computeViewshed(event) {
graphicsLayer.removeAll();
// Step 2: Set up input parameters and assign or collect inputs from user
var point = new Point({
longitude: event.mapPoint.longitude,
latitude: event.mapPoint.latitude
});
var inputGraphic = new Graphic({
geometry: point,
symbol: markerSymbol
});
graphicsLayer.add(inputGraphic);
var inputGraphicContainer = [];
inputGraphicContainer.push(inputGraphic);
var featureSet = new FeatureSet();
featureSet.features = inputGraphicContainer;
var vsDistance = new LinearUnit();
vsDistance.distance = 5;
vsDistance.units = "miles";
var params = {
"Input_Observation_Point": featureSet,
"Viewshed_Distance": vsDistance
};
// Step 3: Run the service. In this instance, the service is Synchronous; Execute
// will be called. An Asynchronous service will use gp.submitJob.
gp.execute(params).then(drawResultData);
}
// Step 4: Render the result. Symbology is assigned and the graphics are added to the map.
function drawResultData(result) {
var resultFeatures = result.results[0].value.features;
// Assign each resulting graphic a symbol
var viewshedGraphics = resultFeatures.map(function(feature) {
feature.symbol = fillSymbol;
return feature;
});
// Add the resulting graphics to the graphics layer
graphicsLayer.addMany(viewshedGraphics);
}
In the sample above, the Geoprocessor class must be loaded, and the REST URL to the service is used with a global variable to define the geoprocessing task. The next step is to construct the parameters specific to the tool the app will be running. This example requires a point feature input and a distance that has a linear unit data type. The REST URL specific to the tool in the service will define input parameters. A service will be set up as either synchronous or asynchronous, and this setting controls whether the service is submitted as a job or run as a task. The output for each tool is also explained on the same page as the input parameters; information about the type and how it can be displayed is provided.
Web tools in Web AppBuilder
To use a web tool with Web AppBuilder, only the service URL of the web tool is necessary; no code is required. The URL is displayed in the portal, on the tool's item details page, in the URL section.
To use a web tool in Web AppBuilder, configure a geoprocessing widget. First create a web app in the portal. Once the style and map is selected, add a geoprocessing widget and configure it.
The widget configuration supports setting input and output options as they relate to a web tool. The input and output parameters that define the web tool determine the options that are available through the widget configuration. For example, the widget configuration allows you to control the type of feature (square, circle, freehand, and so on) that a user can enter if the web tool was published to accept feature input. The same premise applies to the output. A web tool that's set up to output features allows you to configure the symbology and how the web app will render the web tool output. A web tool that's configured with a result map layer will add the result to the web app and symbolize it based on settings you specify during the initial publishing process.
Note:
Do not build new apps using Web AppBuilder. If you have existing Web AppBuilder apps, consider migrating them into the ArcGIS Experience Builder.
Web tools and geoprocessing services in ArcGIS Experience Builder
When publishing a web tool to ArcGIS Enterprise 11.3 or later, use the Analysis widget after adding the web tool as a utility service. Most input and output parameters are available to use in the Analysis widget.
You can configure the input and output parameters behavior, such as allowing or disallowing the sketch functionality for an input feature parameter and displaying or hiding certain inputs and outputs. You can add multiple web tools in the analysis widget as utility services. To learn more about Experience Builder, see Create your first web experience.
Note:
Map Viewer is not available on a stand-alone server using ArcGIS Server.
To use ArcGIS Experience Builder from ArcGIS Online, or to use web tools and geoprocessing services on a different environment than the one with Experience Builder, add the URL of the stand-alone geoprocessing service, or the geoprocessing service of the web tool, like https://organization.example.com/<context>/rest/services/<serviceName>/GPServer while adding a utility. Do not provide a URL of an individual task of the geoprocessing service or the URL of the web tool portal item. Ensure that the geoprocessing service is accessible by ArcGIS Online or a portal.
Web tools and geoprocessing service items in Map Viewer
When publishing a web tool to ArcGIS Enterprise 11.3 or later, open Map Viewer from your portal and browse the custom tools in the Tools section of the Analysis ribbon. To run web tools in Map Viewer, the licensing requirements must be met. To learn more about web tools in Map Viewer, see Use custom web tools. Note, Map Viewer is not available on a stand-alone server running ArcGIS Server.
If the geoprocessing service is on a stand-alone server running ArcGIS Server or on a different portal than Map Viewer, add that geoprocessing service into the portal of Map Viewer first. To do that, provide the service URL, such as https://organization.example.com/<context>/rest/services/<serviceName>/GPServer, to add an item. Do not provide a URL of an individual task of the geoprocessing service or the web tool portal item.
To use Map Viewer from ArcGIS Online, add a service from a URL by providing the service URL of the stand-alone geoprocessing service, or the geoprocessing service of the web tool, such as https://organization.example.com/<context>/rest/services/<serviceName>/GPServer. Do not provide a URL of an individual task of the geoprocessing service. Ensure that the geoprocessing service is accessible by ArcGIS Online, which is always outside the firewall of your organization.