MapContent class move() method does not move a layer into a GroupLayer and errors

Open Beginner friendly
#2,513 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api

Research direction

Start in arcgis/map/map_widget.py at the MapContent.move() method around line 2794, then reproduce the issue with the provided Map, GroupLayer, and layer setup. Done means the script runs without AttributeError and the selected layer is moved into the existing group layer.

Written by the indexing model from the issue text.

Description

bug

Describe the bug
The Map class content property is a MapContent object that has a move() method as per documentation here to move a layer into an existing GroupLayer’s list of layers. However, this has never worked since its introduction in version 2.4.0.

To Reproduce
Steps to reproduce the behavior:

Have a WebMap where the top layer is a group layer and the bottom is a normal layer. Or alter the indexes below to suit.

from arcgis.gis import GIS
from arcgis.map import Map

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

## Access the WebMap Item
wm_item = agol.content.get("WM_ITEM_ID")

## Create a Map object from WebMap Item
webmap = Map(wm_item)

## Get the GroupLayer object
gl = webmap.content.layers[1]

## move to group
webmap.content.move(
    index=0,
    group=gl
)

## update the webmap
webmap.update()

error:

Traceback (most recent call last):
  File "<module1>", line 17, in <module>
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\map\map_widget.py", line 2794, in move
    group._layer.layers.append(pydantic_layer)
    ^^^^^^^^^^^^
AttributeError: 'GroupLayer' object has no attribute '_layer'. Did you mean: 'layers'?

Screenshots
N/A

Expected behavior
The script runs without error and the layer is moved into the group layer. Although it is not clear if the layer will be added to the top or bottom of the layers in the group layer.

Platform (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome/Edge
  • Python API Version: 2.4.0, 2.4.2, 2.4.3

Additional context
Add any other context about the problem here, attachments etc.

Dominant language
Python
Stars
2.2k
Forks
1.1k
Avg merge
2h 40m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Esri/arcgis-python-api

All issues in Esri/arcgis-python-api

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.