You will learn: how to build an app to load and display a web map from ArcGIS Online.
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.
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.
Go to Esri Juptyter Notebooks 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.
Import the GIS
module.
from arcgis.gis import GIS
Make an anonymous connection to ArcGIS Online.
gis = GIS()
Get a publicly available web map titled LA Parks and Trails Map (styled with popups)
owned by esri_devlabs
. It contains datasets about Los Angeles, CA parks and trails. Use item ID 41281c51f9de45edaf1c8ed44bb10e30
for the web map.
webmap = gis.content.get('41281c51f9de45edaf1c8ed44bb10e30')
webmap
Import the WebMap
class from the arcgis.mapping
module and visualize the web map.
from arcgis.mapping import WebMap
la_parks_trails = WebMap(webmap)
la_parks_trails
Your map and layers (feature services) should look something like this.
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.
operational_layers = la_parks_trails.layers
n = len(operational_layers)
print("The webmap has {} layers.".format(n))
Query the list for the id
and url
values of each layer.
for layer in operational_layers:
print("{}\n\t{}".format(layer['id'], layer['url']))
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:
https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0
Explore the other layers through the same steps.
To learn more about querying data with the REST API, see the Query a feature layer tutorial.