You will learn: how to use the ArcGIS API for Python to load a web map for display.

An ArcGIS web map is an interactive display of geographic information composed of a basemap, web layers, and other supporting information to help reveal data and patterns as you interact with it. Visit the product documentation for web maps to get a complete overview.

In this lab you will search ArcGIS Online for an existing web map and display it using the ArcGIS API for Python.

Before You Begin

The ArcGIS API for Python DevLabs use Jupyter Notebooks to execute Python code. If you are new to Python, please see the ArcGIS API for Python guide to Using the Jupyter notebook environment.


Display a web map with the ArcGIS API for Python

  1. Go to the Esri Juptyter Notebook and click New > Python 3 to create a new notebook.

    In each step below, type (or copy and paste) the commands into a new notebook cell and run the code by clicking run cell or pressing shift + Enter.

  2. Add the following code in a cell to import the ArcGIS API for Python.

    from arcgis.gis import *
  3. Make an anonymous connection to ArcGIS Online.

    dev_gis = GIS("https://www.arcgis.com")
  4. You will search for a publicly available web map titled 'LA Parks and Trails Map (sytled with popups)' owned by 'cheangerlove'. It contains datasets about Los Angeles, CA parks and trails. You'll use the wildcard capabilities of the search engine to narrow the search.

    webmap_search = dev_gis.content.search(query = "LA Parks and Trails *", item_type = "Web Map")
  5. Retrieve the web map item from the resulting list.

    webmap = webmap_search[2]
  6. Import the WebMap class from the arcgis.mapping module and visualize the web map.

    from arcgis.mapping import WebMap
    la_parks_trails = WebMap(webmap)

Congratulations, you're done!

Your map and layers (feature services) should look something like this.


Explore the layers in the Web Map with the REST API.

All hosted feature layers have a REST endpoint that you can use to access the data directly. This can be accomplished with a URL request from a web browser, a custom application, or the ArcGIS APIs.

Let's use the web map to retrieve the layers. You can query the web map as a dictionary.

  1. op_layers = la_parks_trails['operationalLayers']
    print("The web map has {} layers.".format(len(op_layers)))
  2. Query the list for the id and url values of each layer.

    for lyr in op_layers:
        print("{}\n\t{}".format(lyr['id'], lyr['url']))
  3. In your browser, add the URL for the Trails_7558 layer to the browser (or just copy/paste from below) to explore the REST endpoint:


  1. Explore the other layers through the same steps.

To learn more about querying data with the REST API, see the Query a feature layer lab.