Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Clubdebambos opened this issue Jan 10, 2024 · 1 comment
Assignees

Comments

@Clubdebambos
Copy link

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.

@nanaeaubry
Copy link
Contributor

@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 nanaeaubry self-assigned this Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants