Tutorial: Display a map

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

Web map of Malibu, CA generated with the ArcGIS API for Python map widget.

A map contains of geographic data. A map contains a and, optionally, one or more . You can display a specific area of a map using a map view and setting the location and zoom level.

This tutorial shows you how to create and display a map of the Santa Monica Mountains in California using the topographic basemap layer.

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 used 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
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    from arcgis.gis import GIS
    
    
    
  2. Use the GIS class to log in. Replace YOUR_API_KEY with the API key you previously copied from the developer dashboard as a value to the api_key parameter.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    from arcgis.gis import GIS
    
    
    gis = GIS(api_key="YOUR_API_KEY")
    
    
    

Display the map

  1. Create an instance of the map widget and set the basemap.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    gis = GIS(api_key="YOUR_API_KEY")
    
    
    map = gis.map()
    map.basemap.basemap = "arcgis-streets"
    
    
    
  2. Set the map center and zoom level.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    map = gis.map()
    map.basemap.basemap = "arcgis-streets"
    
    
    map.center = [34.027, -118.805]
    map.zoom = 12
    
    map  # display the map
    
    
  3. Optional: Use the export_to_html method to export the current state of the map widget to a static HTML file which can be viewed in any web browser.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    from os import path, getcwd
    
    export_dir = path.join(getcwd(), "home")
    if not path.isdir(export_dir):
        os.mkdir(export_dir)
    
    export_path = path.join(export_dir, "display-a-map.html")
    
    map.export_to_html(export_path, title="Display a map")

You should see a map with the topographic basemap layer centered on the Santa Monica Mountains in California.

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