""" Performed some updates for newer versions of Python API in an ArcGIS Pro 3.1.x setting which got rid of the PropertyMap Attribute error.
Date: 10-23-2023
"""
def find_maps_with_layer(lyr_to_find, map_item_query='1=1'):
web_map_items = gis.content.search(query=map_item_query, item_type="Web Map", max_items=10000)
print(f"Searching {len(web_map_items)} web maps")
maps_with_layer = []
for item in web_map_items:
found_it = False
wm = WebMap(item)
lyrs = wm.layers
for lyr in lyrs:
if hasattr(lyr, 'url') and lyr.url is not None:
if lyr_to_find in lyr.url:
found_it = True
break
if found_it:
maps_with_layer.append(item)
print(f"Found {len(maps_with_layer)} maps which contain the layer")
return maps_with_layer
# Parameters:
lyr_to_find = 'https://<domainurl>/<webadaptor>/rest/services/<nameoffeatureservice>/FeatureServer'
map_item_query = "Title:*"
# Get a list of web maps with the layer:
maps_with_layer = find_maps_with_layer(lyr_to_find, map_item_query)
# Print the titles of web maps containing the layer:
for item in maps_with_layer:
print(f'Web Map Title: {item.title}')