For various reasons it's useful to know the ID of a web map layer. So what's the easiest way to find it?
I've learned by debugging that the ID of one of my web map layers is "Development_2055". How would I find this without debugging?
Solved! Go to Solution.
Hi Jonathan, you can find the id's of the operationalLayers in the json of your webmap :
<portalurl>/sharing/rest/content/items/<webmapid>/data?f=json&token=
I'm not sure if I would call it an easy way to find them - but it is a way without writing code or debugging 🙂
You can use the following code in Jupyter Notebook to get the ID of the operationalLayers in your Web Map.
from arcgis.gis import GIS
gis = GIS("home")
from arcgis.mapping import WebMap
wm_item = gis.content.get('itemID of the WebMap')
wm = WebMap(wm_item)
print(wm.layers[0].id)
This will print Development_2055 in your case if this is the first layer in your Web Map.
Hi Jonathan,
Edit: Sorry Jonathan, I guess I failed the reading comprehension portion of geonet. I thought you meant the map id, not a layer id. My apologies.
Two easy ways that I know about: When you save the map and then when you look at the details of the map.
After you save the map the link will change to show the id
And then when you look at the details of a map it is also in the browser link
The id is the same just called a little different in the browser link. Hope this helps.
Best,
Brandon
Hi Brandon,
I have the web map ID -- I'm looking for the ID of specific layer within the web map, so that I can do something like:
var layer = this.map.getLayer(<insert layer ID here>);
or, in order to configure the GeoForm template fields, something like:
fields:{
<insert layer ID here>: [{
"name": "email", // field ID
"alias": "Email", // label
"fieldDescription": "Let us contact you.", // help text
"visible": true, // show this field?
"typeField": false, // subtype field?
"tooltip": "test@test.com", // placeholder text
"displayType": "email" // text, checkbox, radio, textarea, url, email
}]
}
Thanks,
Jon.
Hi Jonathan,
You could so something like below:
var map = this.map; array.forEach(map.itemInfo.itemData.operationalLayers, function(layer){ if(layer.title == 'Parcels'){ layerID = layer.id; } })
Hi Jake,
Yes, that does work. I'm wondering if there's a way to do it a priori, as in the second case that I identified above?
Thanks,
Jon.
Hi Jonathan, you can find the id's of the operationalLayers in the json of your webmap :
<portalurl>/sharing/rest/content/items/<webmapid>/data?f=json&token=
I'm not sure if I would call it an easy way to find them - but it is a way without writing code or debugging 🙂
Perfect. That's exactly what I was looking for. Thanks, Herdis.
Esri has released the ArcGIS Online Assistant app that allows you to view the JSON of an object.
Link: ArcGIS Online Assistant
To view a webmap's JSON:
1.Login
2. Select the "I want to..." list in the top menu
3. Select "View an Item's JSON" from the list.
4. Select the map or item from the lists on the left of the page.
I had been using the method that Herdis Gudbrandsdottir had posted for a while now and this method seems helpful as well.
Thanks,
Chris
hi,
Take the following steps to get the id of all layers/services in a web map:
https://<your portal url>/sharing/rest/content/items/web map id/data/?f=pjson
You can use the following code in Jupyter Notebook to get the ID of the operationalLayers in your Web Map.
from arcgis.gis import GIS
gis = GIS("home")
from arcgis.mapping import WebMap
wm_item = gis.content.get('itemID of the WebMap')
wm = WebMap(wm_item)
print(wm.layers[0].id)
This will print Development_2055 in your case if this is the first layer in your Web Map.