Skip to content

MapContent update_layer() with options parameter does not target specific updates for layerDefinition and overwrites its entirety #2264

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

Open
Clubdebambos opened this issue Apr 21, 2025 · 2 comments
Labels

Comments

@Clubdebambos
Copy link

Describe the bug
When using the Map object content property (MapContent object) update_layer() method to update the layerDefinition property, you cannot specifically choose which layerDefinition properties to update it overwrites the entire layerDefinition. For example, I update the layerDefinition minScale and maxScale to alter the scale range, the entire layerDefinition is overwritten removing any drawingInfo, filterExpression etc. If this is by design it is poorly documented.

To Reproduce
Steps to reproduce the behavior:
Here's the layer definition

        "layerDefinition": {
            "minScale": 10000000,
            "maxScale": 100000,
            "definitionExpression": "COUNTY = 'GALWAY'",
            "drawingInfo": {
                "renderer": {
                    "type": "simple",
                    "symbol": {
                        "type": "esriSFS",
                        "color": [
                            110,
                            110,
                            110,
                            191
                        ],
                        "outline": {
                            "type": "esriSLS",
                            "color": [
                                0,
                                0,
                                0,
                                255
                            ],
                            "width": 0.75,
                            "style": "esriSLSSolid"
                        },
                        "style": "esriSFSSolid"
                    }
                }
            }

Let's update the filterExpression

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

agol = GIS("home")

wm_item = agol.content.get("WM_ITEM_ID")

webmap = Map(wm_item)

filter_exp = "COUNTY = 'KILDARE'"

options_dict = {
    "layerDefinition" : {
        "definitionExpression" : filter_exp
    }
}

webmap.content.update_layer(
    index=0,
    options=options_dict
)

webmap.update()

error:
No error code. The JSON definition is cleared for layerDefinition with the exception of the update.

"layerDefinition": {
"definitionExpression": "COUNTY = 'KILDARE'"
}

Screenshots
If applicable, add screenshots to help explain your problem.

Expected behavior
I expect the filterExpression to be updated and the rest of the properties in the layerDefinition to remain as they were

Platform (please complete the following information):

  • OS: Windows 11 Home
  • Browser Chrome
  • Python API Version 2.4.0

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

@nanaeaubry
Copy link
Contributor

@Clubdebambos Thanks for reporting this however I don't feel this is a bug but rather an enhancement.

The update will take the options dictionary, see if the attributes are in the layer and, if yes, assign the value given. So this updates the definition to the value given by the user.

It seems for layer definition this may be too radical of an update and I see why a user would want to pass in just a key, value rather than the whole definition.

We can look at either adding a new parameter or having the method recognize if 'layerDefinition' is passed into option dictionary and treat it differently.

Do you have an opinion on which workflow would be of preference?

Also please feel free to provide feedback if you believe there is a more straightforward way to provide this to the user as we are open to discussion on this.

@Clubdebambos
Copy link
Author

Hi @nanaeaubry,
The options parameter is certainly an enhancement. I think it would be great to be able to target single elements in the layerDefinition, for example; I want to update the scale ranges only, or the definitionExpression, rather than having to manipulate the layerDefinition and then use the entire layerDefinition to update.

"... or having the method recognize if 'layerDefinition' is passed into option dictionary and treat it differently."

It would be great if the options parameter recognizes the user is accessing and updating the layerDefinition, and only updates the components that the user has set.

All the best.
Glen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants