▾
import DirectionsFeature from "@arcgis/core/rest/support/DirectionsFeature.js";const DirectionsFeature = await $arcgis.import("@arcgis/core/rest/support/DirectionsFeature.js");- Since
- ArcGIS Maps SDK for JavaScript 4.25
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".
- Example
- // 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()}`);
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
| inherited | Record<string, GeometryUnion> | null | undefined | |
| | ||
| readonly inherited | ||
| readonly inherited | ||
| DirectionsEvent[] | null | undefined | | |
| | ||
| readonly inherited | ||
| inherited | ||
| inherited | ||
| inherited | ||
| DirectionsString[] | null | undefined | | |
| inherited | SymbolUnion | null | undefined | |
| inherited |
aggregateGeometries
- Type
- Record<string, GeometryUnion> | null | undefined
The aggregateGeometries contains spatial aggregation geometries when statistics query is executed with
envelope-aggregate, centroid-aggregate and/or convex-hull-aggregate statistics type. Each property on aggregateGeometries is populated with
statistics field containing the aggregate geometry matching the aggregate statistics type.
- Example
- // average of age fields by regionsconst ageStatsByRegion = new StatisticDefinition({onStatisticField: field,outStatisticFieldName: "avgAge",statisticType: "avg"});// extent encompassing all features by regionconst aggregatedExtent = new StatisticDefinition({statisticType: "envelope-aggregate",outStatisticFieldName: "aggregateExtent",});// group the statistics by Region field// get avg age by Regions and extent of each regionconst query = layer.createQuery();query.groupByFieldsForStatistics = ["Region"];query.outStatistics = [consumeStatsByRegion, aggregatedExtent];layer.queryFeatures(query).then((results) => {results.features.forEach((feature) => {if (feature.attributes.Region === "Midwest") {view.goTo(feature.aggregateGeometries.aggregateExtent);}});});
attributes
- Type
- any
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. |
- Example
- let graphic = new Graphic();graphic.attributes = {"name": "Spruce","family": "Pinaceae","count": 126};
distance
- Since
- ArcGIS Maps SDK for JavaScript 5.2
Distance value returned in a query result when outDistance is specified. This value is calculated relative to the geometry defined by referenceGeometry, or to the Query.geometry when no reference geometry is specified.
- See also
geometry
The geometry of the Directions Feature.
- Example
- // First create a point geometrylet point = {type: "point", // autocasts as new Point()longitude: -71.2643,latitude: 42.0909};// Create a symbol for drawing the pointlet markerSymbol = {type: "simple-marker", // autocasts as new SimpleMarkerSymbol()color: [226, 119, 40]};// Create a graphic and add the geometry and symbol to itlet pointGraphic = new Graphic({geometry: point,symbol: markerSymbol});
isAggregate
- Type
- boolean
Indicates whether the graphic refers to an aggregate, or cluster graphic. Aggregate graphics represent clusters of features. If a graphic is an aggregate, you can use its Object ID to Query.aggregateIds the features comprising the cluster.
- See also
- Default value
- false
layer
- Type
- GraphicLayer | null | undefined
If applicable, references the layer in which the graphic is stored.
origin
- Type
- GraphicOrigin | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.29
Returns information about the origin of a graphic, when available.
Origin details may be returned by methods such as MapView.hitTest() or by calling queryFeatures() on a layer or layer view.
The available properties of the returned origin object depend on the origin type and may include the originating layer, sublayer, or other metadata. Before accessing these properties, check the origin type using a utility such as isMapImageGraphicOrigin, isFeatureGraphicOrigin, or isVectorTileGraphicOrigin.
If you only need the title of the originating layer or sublayer, use getGraphicOriginTitle. To get the popup template applicable to the graphic, use getEffectivePopupTemplate() instead of accessing a layer's or sublayer's template directly.
- Examples
Access the layer and sublayer of a graphic that originated from a MapImageLayer.
import { isMapImageGraphicOrigin } from "@arcgis/core/graphic/isMapImageGraphicOrigin.js";const origin = graphic.origin;// Check whether the graphic came from a Map Image layerif (isMapImageGraphicOrigin(origin)) {console.log(origin.layer.title);console.log(origin.sublayer.title);}Access the vector tile style layer associated with a hitTest result.
import { isVectorTileGraphicOrigin } from "@arcgis/core/graphic/isVectorTileGraphicOrigin.js";view.on("click", async (event) => {// Limit the hit test to the vector tile layer at the clicked locationconst response = await view.hitTest(event, { include: vectorTileLayer });for (const result of response.results) {// Only graphic results contain a graphic with origin informationif (result.type !== "graphic") {continue;}const origin = result.graphic.origin;// This check narrows origin to VectorTileGraphicOrigin in TypeScriptif (isVectorTileGraphicOrigin(origin)) {// layerId identifies a style layer within the vector tile layerconst styleLayer = origin.layer.getStyleLayer(origin.layerId);console.log(styleLayer);}}});
popupTemplate
- Type
- PopupTemplate | null | undefined
The template for displaying content in a Popup when the graphic is selected. The PopupTemplate may be used to access a graphic's attributes and display their values in the view's default popup. See the documentation for PopupTemplate for details on how to display attribute values in the popup.
As of 4.8, to get the actual popupTemplate of the graphic, see the getEffectivePopupTemplate()
method that either returns this value or the popupTemplate of the graphic's layer.
- See also
- Example
- // The following snippet shows how to set a popupTemplate// on the returned results (features) from identifyidResult.feature.popupTemplate = {title: "{NAME}",content: [{// Pass in the fields to displaytype: "fields",fieldInfos: [{fieldName: "NAME",label: "Name"}, {fieldName: "REGION",label: "Region"}]}]};
symbol
- Type
- SymbolUnion | null | undefined
The Symbol for the graphic. Choosing a symbol for a graphic depends on the View type (SceneView or MapView), and the geometry type of the graphic.
Each graphic may have its own symbol specified when the parent layer is a GraphicsLayer. For a FeatureLayer the symbol of each graphic should not be set by the developer since the graphics' rendering properties are determined by the layer's Renderer.
To change a graphic's Symbol in the GraphicsLayer and in the View.graphics at runtime, one of the following can be done:
- Clone the symbol and change its properties.
- Assign a new symbol to the graphic.
- Example
- view.on("click", function(event){let graphic = new Graphic({geometry: event.mapPoint,symbol: {type: "simple-marker", // autocasts as new SimpleMarkerSymbol()color: "blue",size: 8,outline: { // autocasts as new SimpleLineSymbol()width: 0.5,color: "darkblue"}}});});
Methods
| Method | Signature | Class |
|---|---|---|
| inherited static | fromJSON(json: any): any | |
| inherited | clone(): this | |
| inherited | getAttribute<T = any>(name: string): T | |
| inherited | getEffectivePopupTemplate(defaultPopupTemplateEnabled?: boolean): PopupTemplate | null | undefined | |
| inherited | getGlobalId(): string | null | undefined | |
| inherited | getObjectId(): ObjectId | null | undefined | |
| inherited | setAttribute(name: string, newValue: any): void | |
| inherited | toJSON(): any |
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. The object passed into the input json
parameter often comes from a response to a query operation in the REST API or a
toJSON()
method from another ArcGIS product. See the Using fromJSON()
topic in the Guide for details and examples of when and how to use this function.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects. | |
- Returns
- any
Returns a new instance of this class.
clone
- Signature
-
clone (): this
Creates a deep clone of this object. Any properties that store values by reference will be assigned copies of the referenced values on the cloned instance.
- Returns
- this
A deep clone of the class instance that invoked this method.
getAttribute
- Signature
-
getAttribute <T = any>(name: string): T
- Type parameters
- <T = any>
Returns the value of the specified attribute.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| name | The name of the attribute. | |
- Returns
- T
Returns the value of the attribute specified by
name.
getEffectivePopupTemplate
- Signature
-
getEffectivePopupTemplate (defaultPopupTemplateEnabled?: boolean): PopupTemplate | null | undefined
Returns the popup template applicable for the graphic.
It's either the value of popupTemplate or
the popupTemplate from the graphic's layer.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| defaultPopupTemplateEnabled | = false - Whether support for default popup templates is enabled. When true, a default popup template may be created automatically if neither the graphic nor its layer have a popup template defined. | |
- Returns
- PopupTemplate | null | undefined
Returns the popup template of the graphic.
getGlobalId
- Signature
-
getGlobalId (): string | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.33
Returns the Global ID of the feature associated with the graphic, if it exists.
getObjectId
- Signature
-
getObjectId (): ObjectId | null | undefined
Returns the Object ID of the feature associated with the graphic, if it exists. The Object ID can be either a numeric value or a string identifier.
setAttribute
- Signature
-
setAttribute (name: string, newValue: any): void
Sets a new value to the specified attribute.
toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.