Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/workers
Class: ClosestFacilityTask

require(["esri/tasks/ClosestFacilityTask"], function(ClosestFacilityTask) { /* code goes here */ });

Description

(Added at v2.0)
Helps you find closest facilities around any location (incident) on a network.

When finding closest facilities, you can specify how many to find and whether the direction of travel is toward or away from them. Once you've found the closest facilities, you can display the best route to or from them, return the travel cost for each route, and display directions to each facility.

You can also specify a cutoff cost beyond which ArcGIS Network Analyst should not search for a facility. For instance, you can set up a closest facility problem to search for hospitals within a 15-minute drive time of the site of an accident. Any hospitals that take longer than 15 minutes to reach will not be included in the results.

Note: ClosestFacilityTask, and other closest facility related classes, requires ArcGIS Server 10.0 or above and a "closest facility" layer. A closest facility layer is a layer of type esriNAServerClosestFacilityLayer.

See also
Closest Facility ArcGIS Desktop Help.

Samples

Search for samples that use this class.

Constructors

NameSummary
new ClosestFacilityTask(url)Creates a new ClosestFacilityTask object.

Methods

NameReturn typeSummary
getServiceDescription()ObjectReturns an object describing a Closest Facility service endpoint (URL of the endpoint is specified in the constructor).
solve(params, callback?, errback?)DeferredSolve the closest facility.

Events

[ On Style Events | Connect Style Event ]
All On Style event listeners receive a single event object. Additionally, the event object also contains a 'target' property whose value is the object which fired the event.

Events

NameEvent ObjectSummary
solve-complete
{
  result: <ClosestFacilitySolveResult>
}
Fires when ClosestFacilityTask has completed.
Constructor Details

new ClosestFacilityTask(url)

Creates a new ClosestFacilityTask object.
Parameters:
<String> url Required URL to the ArcGIS Server REST resource that represents a network analysis service. Use the Service Directory to obtain the URL.
Sample:
require([
  "esri/tasks/ClosestFacilityTask", ... 
], function(ClosestFacilityTask, ... ) {
  var closestFacilityTask = new ClosestFacilityTask("http://174.129.22.43/ArcGIS/rest/services/Network/USA/NAServer/Closest Facility");
  ...
});
Method Details

getServiceDescription()

Returns an object describing a Closest Facility service endpoint (URL of the endpoint is specified in the constructor). The description contains information about the default solver settings, underlying network dataset, available cost and restriction attributes, supported travel modes, etc. If the targeted Network Analyst Server is federated with a Portal or ArcGIS Online, the returned supportedTravelModes array will include user-specific travel modes. If the Network Analyst Server works in a standalone configuration, the supportedTravelModes will come from the original Closest Facility service description.
A few properties returned in this object include: attributeParameterValues, impedance, restrictUTurns, restrictions, supportedTravelModes, travelDirection, and useHierarchy.
(Added at v3.14)
Return type: Object

solve(params, callback?, errback?)

Solve the closest facility.
Return type: Deferred
Parameters:
<ClosestFacilityParameters> params Required The ClosestFacilityParameters object.
<Function> callback Optional The function to call when the method has completed. The arguments in the function are the same as the onSolveComplete event.
<Function> errback Optional An error object is returned if an error occurs on the Server during task execution.
Sample:
closestFacilityTask.solve(params,function(solveResult){
  //do something with the solve results here
});
Event Details
[ On Style Events | Connect Style Event ]

solve-complete

Fires when ClosestFacilityTask has completed. Should be used in favor of onSolveComplete. (Added at v3.5)
Event Object Properties:
<ClosestFacilitySolveResult> result The results from the ClosestFacilityTask solve operation.