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 load and display a pre-configured web map stored in ArcGIS Online.
Prerequisites
You need a free ArcGIS developer account to access your dashboard and API keys. The API key must be scoped to access the services used in this tutorial.
In the require statement, delete the Map module. Add the WebMap, ScaleBar, and 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.
Update the map property in the MapView with the webmap element. Remove the center and zoom properties, since the web map provides positioning information.
At the top-right, click Run to verify that the web map has been successfully loaded and displays.
Add widgets
Use the Legend and ScaleBar widgets to add more context to the application. The Legend widget displays labels and symbols for layers visible in the view. The ScaleBar can display units in either metric or non-metric values.
Create a ScaleBar. Add the scalebar to the bottom-left of the view.