Fetch wich layers in a map service are used in a web map

473
2
Jump to solution
09-29-2023 05:58 AM
ÅsaBlomberg
New Contributor II

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

 

0 Kudos
1 Solution

Accepted Solutions
EarlMedina
Esri Regular Contributor

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"]

View solution in original post

2 Replies
EarlMedina
Esri Regular Contributor

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"]

MichaelVolz
Esteemed Contributor

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.