Select to view content in your preferred language

Looking for equivalent to layers.layerType in API version 2.4

404
2
Jump to solution
01-07-2025 10:16 AM
tmichael_wpjwa
Regular Contributor

I am trying to update an ArcGIS Notebook to use the 2.4 API version and am getting stuck on determining if a layer in a web map is a group layer.  In the previous version of the API I used this method:

tmichael_wpjwa_0-1736273394606.png

But in the new version of the API I'm not seeing a "layerType" property that I can use to do the same thing.  I can see there's a Group Layer in my map by using content.layers (below), but I'm not sure how to do the same thing I was doing in the 2.3 version.

tmichael_wpjwa_1-1736273678353.png

 

0 Kudos
1 Solution

Accepted Solutions
Clubdebambos
MVP Regular Contributor

Hi @tmichael_wpjwa 

I'd use the JSON definition directly. See below...

from arcgis.gis import GIS

agol = GIS("home")

## return WebMap JSON definition as a dictionary.
wm_item = agol.content.get("WM_ITEM_ID")

for op_layer in wm_item.get_data()["operationalLayers"]:
    if op_layer["layerType"] == "GroupLayer":
        grouplayer_layers = op_layer["layers"]
        for lyr in grouplayer_layers:
            if lyr["itemId"] in search_layers:
                ...

This is pretty much what up to version 2.3.0 was doing except it had it nicely packaged using the WebMap class methods. 2.4.0 lacks as the MapContent class layers property returns a list of objects rather than the dictionary/JSON definition of the layer in the Map.

Hope that helps.

Glen

~ learn.finaldraftmapping.com

View solution in original post

2 Replies
Clubdebambos
MVP Regular Contributor

Hi @tmichael_wpjwa 

I'd use the JSON definition directly. See below...

from arcgis.gis import GIS

agol = GIS("home")

## return WebMap JSON definition as a dictionary.
wm_item = agol.content.get("WM_ITEM_ID")

for op_layer in wm_item.get_data()["operationalLayers"]:
    if op_layer["layerType"] == "GroupLayer":
        grouplayer_layers = op_layer["layers"]
        for lyr in grouplayer_layers:
            if lyr["itemId"] in search_layers:
                ...

This is pretty much what up to version 2.3.0 was doing except it had it nicely packaged using the WebMap class methods. 2.4.0 lacks as the MapContent class layers property returns a list of objects rather than the dictionary/JSON definition of the layer in the Map.

Hope that helps.

Glen

~ learn.finaldraftmapping.com
tmichael_wpjwa
Regular Contributor

Thanks Glen!  I'll give that method a try, it looks like it will do what I need.

Determining layer type seems like basic useful functionality and it's a shame it got axed in the new version.

0 Kudos