Tutorial: Display a web map

Learn how to use the ArcGIS API for Python to load a for display.

Python mapping widget displaying a web map of trails Malibu, CA

A 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 a as an with a unique ID.

In this tutorial you will search the portal for an existing web map of trails, trailheads, and parks and display it.

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 to use the data in this tutorial.

  1. Go to the Create an API key tutorial to obtain an .
  2. Ensure that the following is enabled: Location services > Basemaps > Basemap styles service
  3. 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

  1. Import the arcgis.gis module. This module is the entry point into the GIS and provides the functionality to manage GIS , users, and groups.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    from arcgis.gis import GIS
    
    
  2. Log in to the portal and paste the API key you copied earlier.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    from arcgis.gis import GIS
    
    portal = GIS(api_key="<YOUR_ACCESS_TOKEN>")
    
    

Search for the web map

  1. Search for a publicly available web map titled LA Parks and Trails Map (styled) owned by esri_devlabs. It contains datasets of Los Angeles, CA parks and trails.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    from arcgis.gis import GIS
    
    portal = GIS(api_key="<YOUR_ACCESS_TOKEN>")
    
    webmap_search = portal.content.search(
      query="LA Parks and Trails Map (styled) tags:tutorial owner:esri_devlabs",
      item_type="Web Map"
    )
    webmap_search
    
    
  2. Create a variable from the first item in search results.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    webmap_search = portal.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

  1. Pass in web map item to the map widget constructor to display the web map.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    webmap_item = webmap_search[0]
    webmap_item
    
    map = portal.map(webmap_item)
    map

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:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close