arcgis-python-api icon indicating copy to clipboard operation
arcgis-python-api copied to clipboard

ArcGIS API for Python WebMap method to combine layers into a Group Layer and also the ungroup.

Open Clubdebambos opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. I can workaround by manipulating the JSON from the operationalLayers to create a Group Layer in the WebMap. It can be quite cumbersome and you need to have in-depth knowledge of the JSON required and how to remove your layers as single layers and add as a Group Layer.

Current Solution...

from arcgis.gis import GIS
from arcgis.mapping import WebMap

## Access AGOL
agol = GIS("home")

## access webmap item
wm_item = agol.content.get("WM_ITEM_ID")

## create WebMap object
webmap = WebMap(wm_item)

## layers to group
lyr1 = webmap.get_layer(title="Layer 1")
lyr2 = webmap.get_layer(title="Layer 2")
lyr3 = webmap.get_layer(title="Layer 3")
lyr4 = webmap.get_layer(title="Layer 4")

## create a list of group layers
group_lyrs = [
        lyr1,
        lyr2,
        lyr3,
        lyr4
]

## get a list of layer names to be groupes
lyr_names = [lyr.title for lyr in group_lyrs]


## create the group layer JSON
group = {
    "title" : "NPWS Designated Boundaries",
    "layers" : group_lyrs,
    "layerType": "GroupLayer",
    "visibilityMode": "independent"
}

## we will use this list to overwrite current operationalLayers JSON
new_ol = [group]

## append all other layers into the list
for lyr in webmap.definition.operationalLayers:
    if lyr.title not in lyr_names:
        new_ol.append(lyr)

## update the operationalLayers list
webmap.definition.operationalLayers = new_ol

## update the properties and webmap
item_properties = {"text":webmap.definition}

wm_item.update(item_properties=item_properties)

Describe the solution you'd like a method for the WebMap object called group_layers() that takes in a list of layer names or layer ids from the operationalLayer.

layer_ids = [1,2,5]
webmap.group_layers(layer_ids)
webmap.update()

Building on from this is would be good to be able to remove a single layer or all layers (ungroup all) from a Group Layer, possible method names from_group_to_layer() or clear_group_layer()

Describe alternatives you've considered Shown in the python code further up.

Additional context Add any other context or screenshots about the feature request here.

Clubdebambos avatar Jan 10 '24 14:01 Clubdebambos

@Clubdebambos We are working on major mapping module updates and this will be in there. We don't have a set release date but I will keep you updated when we have one.

nanaeaubry avatar Jan 15 '24 07:01 nanaeaubry

@nanaeaubry, Any update on this?

JesseKHall avatar Jul 02 '24 02:07 JesseKHall

This will be in our Fall release :)

nanaeaubry avatar Jul 02 '24 05:07 nanaeaubry