How do I get the ID of a web map layer?

21370
9
Jump to solution
08-13-2015 06:54 AM
JonathanBailey
Occasional Contributor III

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?

2 Solutions

Accepted Solutions
HerdisGudbrandsdottir
New Contributor III

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  🙂

View solution in original post

IJsbrandGroeneveld
Esri Contributor

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.

IJsbrand Groeneveld
Esri Nederland Support

View solution in original post

9 Replies
BrandonKeinath1
Occasional Contributor III

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

webmapid2.JPG

And then when you look at the details of a map it is also in the browser link

webmapid.JPG

The id is the same just called a little different in the browser link.  Hope this helps.

Best,


Brandon

JonathanBailey
Occasional Contributor III

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.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

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;
    }
})
0 Kudos
JonathanBailey
Occasional Contributor III

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.

0 Kudos
HerdisGudbrandsdottir
New Contributor III

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  🙂

JonathanBailey
Occasional Contributor III

Perfect. That's exactly what I was looking for. Thanks, Herdis.

ChristopherSchreiber
Occasional Contributor II

Jonathan Bailey‌,

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 

YaronCohen1
New Contributor II

hi,

Take the following steps to get the id of all layers/services in a web map:

  •    First share the map as public and then use the following URL

                https://<your portal url>/sharing/rest/content/items/web map id/data/?f=pjson

  •    Set the share back to its original definition
0 Kudos
IJsbrandGroeneveld
Esri Contributor

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.

IJsbrand Groeneveld
Esri Nederland Support