Learn how to use the ArcGIS API for Python to load a web map for display.
A web map is a JSON structure that contains the properties required to display a 2D map. ArcGIS and custom applications can load web maps and automatically configure the map extent, basemap, layers, styles, pop-ups, labels and more. Web maps can be created interactively with the Map Viewer and ArcGIS Pro. Web maps are stored in ArcGIS Online or ArcGIS Enterprise as an item with a unique ID.
In this tutorial you will search ArcGIS Online for and display an existing web map of trails, trailheads and parks.
Prerequisites
The ArcGIS API for Python tutorials use Jupyter Notebooks to execute Python code. If you are new to this environment, please see the guide to install the API and use notebooks locally.
Steps
Get an access token
You need an access token to use the data in this tutorial.
- Go to the Create an API key tutorial to obtain an access token.
- Ensure that the following privilege is enabled: Location services > Basemaps > Basemap styles service
- Copy the key as it will be used in a following step.
To learn more about other ways to get an access token, go to Types of authentication.
Import modules and log in
-
Import the
arcgis.gis
module. This module is the entry point into the GIS and provides the functionality to manage GIS content, users, and groups.Use dark colors for code blocks from arcgis.gis import GIS
-
Log in to the portal and paste the API key you copied earlier.
Use dark colors for code blocks from arcgis.gis import GIS gis = GIS(api_key="<YOUR_ACCESS_TOKEN>")
Search for the web map
-
Search for a publicly available web map titled
L
owned byA Parks and Trails Map (styled) esri
. It contains datasets of Los Angeles, CA parks and trails._devlabs Use dark colors for code blocks from arcgis.gis import GIS gis = GIS(api_key="<YOUR_ACCESS_TOKEN>") webmap_search = gis.content.search( query="LA Parks and Trails Map (styled) tags:tutorial owner:esri_devlabs", item_type="Web Map" ) webmap_search
-
Create a variable from the first item in search results.
Use dark colors for code blocks webmap_search = gis.content.search( query="LA Parks and Trails Map (styled) tags:tutorial owner:esri_devlabs", item_type="Web Map" ) webmap_search webmap_item = webmap_search[0] webmap_item
Display the web map
-
Import the
Web
class from theMap arcgis.mapping
module and pass in the item returned from the search.Use dark colors for code blocks webmap_item = webmap_search[0] webmap_item from arcgis.mapping import WebMap la_park_trails = WebMap(webmap_item) la_park_trails
You should see a map containing symbolized trailheads, trails and parks located in the Santa Monica Mountains.
What's next?
Learn how to use additional functionality in these tutorials: