Learn how to add the Directions component to a map.
Routing is finding the path from an origin to a destination in a street network. You can use the Directions component to find routes and directions between two or more locations. The component provides a user-friendly interface to find routes and directions. You can also use the route module to find routes and directions programmatically. See the Find a route and directions tutorial for more information on using the route service.
NoteTo learn more about routing, visit Route and directions in the Mapping and location services guide.
Prerequisites ArcGIS Accounts:You need an ArcGIS Location Platform or ArcGIS Online account.
Steps Create a new penYou need an access token with the correct privileges to access the location services used in this tutorial.
esriConfig.apiKey
to your access token.
Use dark colors for code blocks
1
2
3
4
5
6
7
8
9
var esriConfig = {
apiKey: "YOUR_ACCESS_TOKEN",
};
To learn about other ways to get an access token, go to Types of authentication.
Update the mapA streets basemap layer is typically used in routing applications. Update the basemap
attribute to use the arcgis/navigation
basemap layer and change the position of the map to center on Los Angeles.
basemap
, center
and zoom
attributes.
Expand
Use dark colors for code blocks1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<arcgis-map basemap="arcgis/navigation" center="-118.24532, 34.05398" zoom="12">
<arcgis-zoom position="top-left"></arcgis-zoom>
</arcgis-map>
Add the arcgis-directions
component with its position set to be the top-right corner of the map. Adding the use-default-route-layer
attribute will automatically create and associate a default RouteLayer with the map. Alternatively, you can manually set the layer
property to an existing RouteLayer
instance in the map.
Expand
Use dark colors for code blocks1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<arcgis-map basemap="arcgis/navigation" center="-118.24532, 34.05398" zoom="12">
<arcgis-zoom position="top-left"></arcgis-zoom>
<arcgis-directions position="top-right" use-default-route-layer></arcgis-directions>
</arcgis-map>
In CodePen, run your code to display the map.
You can add stops by searching for addresses or clicking a location on the map and set other options to find the appropriate route and directions between the stops.
What's next?Learn how to use additional API features and ArcGIS services in these tutorials:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4