I want to fetch all layers that a Web map uses from a Map service.
If I have a Web map with a Map service - the Map service contains 10 layers but only 5 of them are used in the Web map. How do I fetch these in the API?
Here is my code for fetching the Web map, but it only gets the Map services, nothing about wich layers in the Map service that are used:
from arcgis.gis import GIS
from arcgis.mapping import WebMap, WebScene
gis = GIS(url="https://geoportal.website.se/portal/", username="*****", password="****")
web_maps = gis.content.search(query="", item_type="Web Map", max_items = 5)
for map in web_maps:
maptitle = map['title']
mapid = map['id']
web_map = WebMap(gis.content.get(map.id))
layers = web_map.layers
for layer in layers:
layerType = layer.layerType
url = layer.url
itemId = layer.itemId
Solved! Go to Solution.
To get that information, you can take a look at the item data.
Example:
from arcgis import GIS
import json
conn = GIS("https://machine.domain.com/portal", "admin", "password")
item = conn.content.get(<itemID>)
item_data = item.get_data()
# Include the below line for prettified JSON
print(json.dumps(item_data, indent=4, sort_keys=True))
In your case, the information you're looking for will be in:
item_data["operationalLayers"]
To get that information, you can take a look at the item data.
Example:
from arcgis import GIS
import json
conn = GIS("https://machine.domain.com/portal", "admin", "password")
item = conn.content.get(<itemID>)
item_data = item.get_data()
# Include the below line for prettified JSON
print(json.dumps(item_data, indent=4, sort_keys=True))
In your case, the information you're looking for will be in:
item_data["operationalLayers"]
If you need to perform this action on a large number of web maps and possibly web apps, I would suggest looking at GeoJobe Admin tools as I think they are a great investment and are designed to perform tasks like this without having to do your own code development.