Display a web map
Learn how to display a map from a web map stored in ArcGIS.
A web map is a map stored as an item in ArcGIS Online. A web map item contains all of the configuration settings for the map (in JSON format) such as the basemap layer, data layers, layer styles, and pop-up settings. Applications can access and display a web map using its item ID.
In this tutorial, you will load and display a pre-configured web map stored in ArcGIS Online.
Prerequisites
You need an ArcGIS Developer or ArcGIS Online account to access the dashboard and create an API key.
Steps
Create a new pen
- To get started, either complete the Display a map tutorial or .
Set the API key
To access ArcGIS services, you need an API key.
Go to your dashboard to get an API key.
In CodePen, set the
api
to your key, so it can be used to access basemap layer and location services.Key Use dark colors for code blocks Change line
Add modules
In the
require
statement, delete theMap
module. Add theWeb
,Map Scale
, andBar Legend
modules.The ArcGIS Maps SDK for JavaScript is available as AMD modules and ES modules, but this tutorial is based on AMD. The AMD
require
function uses references to determine which modules will be loaded – for example, you can specify"esri/Map"
for loading the Map module. After the modules are loaded, they are passed as parameters (e.g.Map
) to the callback function where they can be used in your application. It is important to keep the module references and callback parameters in the same order. For more information on the different types of modules, visit the Introduction to Tooling guide topic.Use dark colors for code blocks Remove line Add line. Add line. Add line. Change line
Load the web map
You can use the portal item ID to create a Web
. The web map will be passed to the view.
Delete the code that creates the
Map
.Use dark colors for code blocks Remove line Remove line Remove line Create a
Web
. Set theMap portal
ID toItem 41281c51f9de45edaf1c8ed44bb10e30
.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Update the
map
property in theMap
with theView webmap
element. Remove thecenter
andzoom
properties, since the web map provides positioning information.Use dark colors for code blocks Remove line Remove line Remove line Change line At the top-right, click Run to verify that the web map has been successfully loaded and displays.
Add widgets
Use the Legend
and Scale
widgets to add more context to the application. The Legend
widget displays labels and symbols for layers visible in the view. The Scale
can display units in either metric or non-metric values.
Create a
Scale
. Add theBar scalebar
to thebottom-left
of theview
.Use dark colors for code blocks Add line. Add line. Add line. Add line. Add line. Create a
Legend
to display feature information. Add thelegend
to thetop-right
of theview
.Use dark colors for code blocks Add line. Add line. Add line. Add line.
Run the App
In CodePen, run your code to display the map.
You should now see a scale bar displaying scale (in miles), along with a legend that displays layer information contained in the web map.
What's next?
Learn how to use additional API features and ArcGIS services in these tutorials: