Hello.
I've worked out code below (to run in ArcGIS Pro Workbook) to list the layers in a Web Map. This works fine for Classic Web Map, but if I'm using a New Web Map, with the layers services all added to Groups, then what is listed is just the Group names.
Can the code be modified to list the Group name, then the layers in each group?
Appreciate your support, please note I'm a bit of a novice so grateful for any detailed suggestions to modifying the code.
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import arcpy
gis = GIS("pro")
# Search for web maps based on the query. Set max_items to -1 for all maps
webmaps_contents = gis.content.search("*",item_type="Web Map", max_items=500)
print('Number of Web Maps found: ' + str((len(webmaps_contents))))
n=0
#create web map objects from search results and print the web map title and layer name
for webmap_item in webmaps_contents:
if webmap_item.content_status != "deprecated": # Optional to include
n=n+1
print(n,webmap_item.title,webmap_item.content_status)
webmap_obj = WebMap(webmap_item)
l=0
for layer in webmap_obj.layers:
l=l+1
print('\t',l,layer.title)
print("Finished")
Solved! Go to Solution.
Hi, this small update should work well for your needs:
l = 0
for layer in webmap_obj.layers:
l += 1
print(l, layer.title)
if hasattr(layer, "layers"):
for sublayer in layer.layers:
print("\t", sublayer.title)
Hi, this small update should work well for your needs:
l = 0
for layer in webmap_obj.layers:
l += 1
print(l, layer.title)
if hasattr(layer, "layers"):
for sublayer in layer.layers:
print("\t", sublayer.title)
Thanks @EarlMedina , that worked.
Really appreciate the help.