Display a web map

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 settings required to display a 2D map. ArcGIS and custom applications can load web maps and automatically configure the map extent, basemap, layers and 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 an existing web map 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

  1. Import the GIS module. arcgis.gis is the ArcGIS API for Python GIS model.

    Use dark colors for code blocks
                     
    Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    from arcgis.gis import GIS
    
    
  2. Make an anonymous connection to ArcGIS Online. You can search ArcGIS online for items shared publicly without using credentials.

    Use dark colors for code blocks
                     
    Add line.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    from arcgis.gis import GIS
    
    gis = GIS()
    
    
  3. Search for a publicly available web map titled LA Parks and Trails Map (styled) owned by esri_devlabs. It contains datasets about Los Angeles, CA parks and trails.

    Use dark colors for code blocks
                     
    Add line.Add line.Add line.Add line.Add line.
    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
    
    
  4. Retrieve the web map item from the resulting list.

    Use dark colors for code blocks
                     
    Add line.Add line.
    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
    
    webmap_item = webmap_search[0]
    webmap_item
    
    
  5. Import the WebMap class from the arcgis.mapping module and visualize the web map.

    Use dark colors for code blocks
                     
    Add line.Add line.Add line.
    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
    
    webmap_item = webmap_search[0]
    webmap_item
    
    from arcgis.mapping import WebMap
    la_park_trails = WebMap(webmap_item)
    la_park_trails

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