require(["esri/rest/support/DirectionsFeature"], (DirectionsFeature) => { /* code goes here */ });
import DirectionsFeature from "@arcgis/core/rest/support/DirectionsFeature.js";
esri/rest/support/DirectionsFeature
DirectionsFeature is subclass of Graphic that contains routing specific attributes. This is accessible from the DirectionsFeatureSet.features property.
A DirectionsFeatureSet is only returned when a route is
solved with an
output type of "complete"
,
"complete-no-events"
, "instructions-only"
, "standard"
, or "summary-only"
.
// If I leave Esri now, what time will I arrive at the Redlands Bowl?
const apiKey = "<ENTER YOUR API KEY HERE>";
const url = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";
const spatialReference = SpatialReference.WebMercator;
const stops = new Collection([
new Stop({
name: "Esri",
geometry: new Point({ x: -13046165, y: 4036335, spatialReference })
}),
new Stop({
name: "Redland Bowl",
geometry: new Point({ x: -13045111, y: 4036114, spatialReference })
})
]);
const routeParameters = new RouteParameters({
apiKey,
stops,
startTime: new Date(),
outSpatialReference: spatialReference,
returnDirections: true,
directionsOutputType: "standard" // default value
});
const { routeResults } = await route.solve(url, routeParameters);
const { directions } = routeResults[0];
const directionFeatures = directions.features;
const lastDirectionFeature = directionFeatures[directionFeatures.length - 1];
const arriveTimeEpoch = lastDirectionFeature.attributes["arriveTimeUTC"];
const arriveTimeDate = new Date(arriveTimeEpoch);
console.log(`I will arrive at: ${arriveTimeDate.toLocaleTimeString()}`);
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
Name-value pairs of fields and field values associated with the Directions Feature. | DirectionsFeature | ||
An array of Direction Events. | DirectionsFeature | ||
The geometry of the Directions Feature. | DirectionsFeature | ||
An array of direction strings. | DirectionsFeature |
Property Details
-
attributes
attributes Object
-
Name-value pairs of fields and field values associated with the Directions Feature. Fields include the following:
Field name Type Description ETA Number The estimated arrival time in UTC in the local time zone. arriveTimeUTC Number The estimated arrival time in UTC. length Number The length of the route segment. maneuverType String The maneuver type. text String The driving direction text. time Number The time spent travelling along the route segment.
-
events
events DirectionsEvent[]
-
An array of Direction Events.
-
geometry
geometry Polyline
-
The geometry of the Directions Feature.
-
strings
strings DirectionsString[]
-
An array of direction strings.