closestFacility

Function
import { closestFacility } from '@esri/arcgis-rest-routing';
//
closestFacility({
  incidents: [
    [-90.404302, 38.600621],
    [-90.364293, 38.620427],
   ],
  facilities: [
    [-90.444716, 38.635501],
    [-90.311919, 38.633523],
    [-90.451147, 38.581107]
   ],
   authentication
})
  .then(response) // => {routes: {features: [{attributes: { ... }, geometry:{ ... }}]}

Used to find a route to the nearest of several possible destinations. See the REST Documentation for more information.

Parameters

Parameter Type Default Notes
requestOptions Required IClosestFacilityOptions

Options to pass through to the routing service.

Available requestOptions

Property Type Notes
facilities Array<IPoint | ILocation | [number, number]> | IFeatureSet

Specify one or more locations that are searched for when finding the closest location.

incidents Array<IPoint | ILocation | [number, number]> | IFeatureSet

Specify one or more locations from which the service searches for the nearby locations. These locations are referred to as incidents.

returnCFRoutes boolean

Specify if the service should return routes.

barriers Optional Array<IPoint | ILocation | [number, number]> | IFeatureSet
directionsLengthUnits Optional "esriNAUCentimeters" | "esriNAUDecimalDegrees" | "esriNAUDecimeters" | "esriNAUFeet" | "esriNAUInches" | "esriNAUKilometers" | "esriNAUMeters" | "esriNAUMiles" | "esriNAUMillimeters" | "esriNAUNauticalMiles" | "esriNAUPoints" | "esriNAUYards"
directionsOutputType Optional "esriDOTComplete" | "esriDOTCompleteNoEvents" | "esriDOTInstructionsOnly" | "esriDOTStandard" | "esriDOTSummaryOnly" | "esriDOTFeatureSets"
outputLines Optional boolean
polygonBarriers Optional IFeatureSet
polylineBarriers Optional IFeatureSet
preserveObjectID Optional boolean
returnBarriers Optional boolean
returnDirections Optional boolean
returnFacilities Optional boolean
returnIncidents Optional boolean
returnPolygonBarriers Optional boolean
returnPolylineBarriers Optional boolean
travelDirection Optional "incidentsToFacilities" | "facilitiesToIncidents"
authentication Optional Inherited IAuthenticationManager

The instance of IAuthenticationManager to use to authenticate this request.

credentials Optional Inherited RequestCredentials

A string indicating whether credentials (cookies) will be sent with the request. Used internally for authentication workflows.

endpoint Optional Inherited string

Any ArcGIS Routing service (example: https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route/ ) to use for the routing service request.

fetch Optional Inherited function(input: RequestInfo, init: RequestInit) : Promise<Response>

The implementation of fetch to use. Defaults to a global fetch.

headers Optional Inherited [key: string]: any

Additional Headers to pass into the request.

hideToken Optional Inherited boolean

Prevents the token from being passed in a URL Query param that is saved in browser history. Instead, the token will be passed in POST request body or through X-Esri-Authorization header. NOTE: This will force POST requests in browsers since auth header is not yet supported by preflight OPTIONS check with CORS.

httpMethod Optional Inherited HTTPMethods

The HTTP method to send the request with.

maxUrlLength Optional Inherited number

If the length of a GET request's URL exceeds maxUrlLength the request will use POST instead.

params Optional Inherited IParams

Additional parameters to pass in the request.

portal Optional Inherited string

Base url for the portal you want to make the request to. Defaults to authentication.portal if authentication exists, otherwise to 'https://www.arcgis.com/sharing/rest'.

rawResponse Optional Inherited boolean

Return the raw response

Returns

A Promise that will resolve with routes and directions for the request.

Property Type Notes
messages string[] | string
barriers Optional IFeatureSet
directions Optional Array<{
features:
IFeature[] | IFeature
routeId:
number
routeName:
string
summary:
object
}>
facilities Optional IFeatureSet
incidents Optional IFeatureSet
polygonBarriers Optional IFeatureSet
polylineBarriers Optional IFeatureSet
routes Optional IFeatureSetWithGeoJson

REST API documentation for closestFacility() available at https://developers.arcgis.com/rest/network/api-reference/closest-facility-synchronous-service.htm
Function defined in packages/arcgis-rest-routing/src/closestFacility.ts:128