This is the completed solution for the Display a Web Map ArcGIS DevLab. ArcGIS DevLabs are short introductory tutorials to guide you through the three phases of building geospatial apps: Data, Design, Develop
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com")
Let's search for a Los Angeles Parks and Trails Map.
webmaps = gis.content.search(query="LA Parks and Trails *", item_type="Web Map")
webmaps
[<Item title:"Tree Canopy by City in Minnesota" type:Web Map owner:vikalpa>, <Item title:"San Diego Shortlist-Copy" type:Web Map owner:opsdashboarddemo>, <Item title:"LA Parks and Trails Map (styled with popups)c" type:Web Map owner:cheangerlove>, <Item title:"Location Map Telematica" type:Web Map owner:roberto.arbanil>, <Item title:"Vaals6" type:Web Map owner:haicao1975>, <Item title:"ADFCA Short List Map Story" type:Web Map owner:developer5>, <Item title:"San Diego Places To Go-复制" type:Web Map owner:win_001>, <Item title:"San Diego Places To Go-Copy" type:Web Map owner:hayam_osama>, <Item title:"Vaals9" type:Web Map owner:haicao1975>, <Item title:"San Diego Shortlist-Copia" type:Web Map owner:paoloprova>]
The index position for the LA Parks and Trails Map in your search list may vary from the example.
webmap = webmaps[2]
webmap
WebMap
object.¶from arcgis.mapping import WebMap
la_parks_trails = WebMap(webmap)
la_parks_trails
op_layers = la_parks_trails['operationalLayers']
print("The webmap has {} layers.".format(len(op_layers)))
The webmap has 3 layers.
for lyr in la_parks_trails['operationalLayers']:
print("{}\n\t{}".format(lyr['id'], lyr['url']))
Parks_and_Open_Space_8268 https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0 Trails_7558 https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0 Trailheads_8053 https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0