Select to view content in your preferred language

Return All Operational Layers of Web Map Item

648
0
04-24-2023 09:52 AM
Status: Open
Labels (1)
mpboyle
Frequent Contributor

Please have the all the operational layers within a web map returned when using "layers" of a Web Map item. 

It seems that any layers within a Group Layer are skipped, meaning the user has to check whether the layer is a group layer and then further iterate over the layers within the group to truly retrieve all layers within the web map. 

Below is an example.  The grouped layers are expanded to show all the layers within the web map:

mpboyle_0-1682354409126.png

In the code below, the layers within the "PLSS", "Annotation", and "Political Township" group layers are not returned.

 

import arcgis

# portal connection variables
portal_url = r'...portal url...'
portal_user_name = '...user name...'
portal_user_password = '...user password...'

# target web map
web_map_id = '...web map id...'

# connect to portal
p = arcgis.GIS(portal_url, portal_user_name, portal_user_password)

# set web map item
item = p.content.get(web_map_id)
# set web map item
web_map = arcgis.mapping.WebMap(item)
# get operational layers
layers = web_map.layers
for l in layers:
    layer_name = l.get('title')
    layer_type = l.get('layerType')
    print(f'{layer_name} ({layer_type})')

 

mpboyle_1-1682354588856.png

None of the layers within the group layers (green line) are returned.  It would be nice if they were returned without having to iterate through each group layer object.