Tutorial: Display a web map

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

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

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

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 content, users, and groups.

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    from arcgis.gis import GIS
    
    
  2. Log in anonymously to access publicly shared content. The data used in this tutorial is public so you do not need credentials to access it. If it were private data, you would be required to provide authentication.

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    from arcgis.gis import GIS
    
    gis = GIS()
    
    

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.

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    from arcgis.gis import GIS
    
    gis = GIS()
    
    webmap_search = gis.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.

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    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

  1. Import the WebMap class from the arcgis.mapping module and pass in the item returned from the search.

    Use dark colors for code blocks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    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:

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