How to configure Map Image Layer Pop-up Attributes by Python?

2114
3
Jump to solution
02-11-2021 02:51 PM
ChenLi
by
Emerging Contributor

I need help to check/uncheck programmatically the setting "Use 1000 Separator" of Pop-up's "Configure Attributes" for a layer inside of Map Image Layer (Source: Map Service). 

Saw a sample to change the Pop-up settings for item of WebMap (https://community.esri.com/t5/arcgis-api-for-python-questions/enable-popup-in-web-map/td-p/814850), but not for item of Map Image Layer.

The Pop-up settings can be changed and saved back to the Image Map Layer by "Save Layer" using Map Viewer.

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi! 

This can be achieved using the ArcGIS API for Python.

If you access your AGOL Account/Enterprise Portal from ArcGIS Online Assistant https://ago-assistant.esri.com/ you can view the structure of the popup info for your Map and Feature Service items. 

If you look at the "Data" section for a map or feature service (with popups enabled) in AGO Assistant, you can see the structure of popup information as JSON.  In particular, what you're after is the "digitSeparator" parameter (true/false). 

 

Here's an example JSON for the data section of a map or feature service item:

{
    "layers": [
        {
            "id": 0,
            "popupInfo": {
                "title": "Contours",
                "fieldInfos": [],
                "description": null,
                "showAttachments": true,
                "mediaInfos": []
            }
        },
        {
            "id": 1,
            "popupInfo": {
                "title": "Contours 0.25 m: {ELEVATION}",
                "fieldInfos": [
                    {
                        "fieldName": "OBJECTID",
                        "label": "Object ID",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox"
                    },
                    {
                        "fieldName": "ELEVATION",
                        "label": "Elevation (m) AHD",
                        "tooltip": "",
                        "visible": true,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": true
                        }
                    },
                    {
                        "fieldName": "CLASSIFICATION",
                        "label": "Classification",
                        "tooltip": "",
                        "visible": true,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": false
                        }
                    },
                    {
                        "fieldName": "SHAPE",
                        "label": "Shape",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox"
                    }
                ],
                "description": null,
                "showAttachments": true,
                "mediaInfos": []
            },
            "layerDefinition": {
                "defaultVisibility": true
            }
        },
        {
            "id": 2,
            "popupInfo": {
                "title": "Contours 5m: {ELEVATION}",
                "fieldInfos": [
                    {
                        "fieldName": "OBJECTID",
                        "label": "Object ID",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox"
                    },
                    {
                        "fieldName": "ELEVATION",
                        "label": "Elevation (m) AHD",
                        "tooltip": "",
                        "visible": true,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": true
                        }
                    },
                    {
                        "fieldName": "CLASSIFICATION",
                        "label": "Classification",
                        "tooltip": "",
                        "visible": true,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": true
                        }
                    },
                    {
                        "fieldName": "SHAPE",
                        "label": "Shape",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox"
                    },
                    {
                        "fieldName": "SHAPE_STLength__",
                        "label": "SHAPE.STLength()",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": true
                        }
                    }
                ],
                "description": null,
                "showAttachments": true,
                "mediaInfos": []
            }
        },
    ]
}



To access this via the api: First you can access the item through gis.content.get with the item ID.
Once you've got the item, use the get_data method https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html?highlight=get_data#arcgis.gis... to download the JSON data above. 

Once you've got a copy of this data, you can iterate through the layers to programmatically change the value for "digitSeparator". 

Lastly, you can update the item through the item.update method.  This will push the changes back up into the map/feature service item. 

While I don't have a snippet available off the top of my head, I've used this process numerous times to update/migrate popup data. 

View solution in original post

3 Replies
by Anonymous User
Not applicable

Hi! 

This can be achieved using the ArcGIS API for Python.

If you access your AGOL Account/Enterprise Portal from ArcGIS Online Assistant https://ago-assistant.esri.com/ you can view the structure of the popup info for your Map and Feature Service items. 

If you look at the "Data" section for a map or feature service (with popups enabled) in AGO Assistant, you can see the structure of popup information as JSON.  In particular, what you're after is the "digitSeparator" parameter (true/false). 

 

Here's an example JSON for the data section of a map or feature service item:

{
    "layers": [
        {
            "id": 0,
            "popupInfo": {
                "title": "Contours",
                "fieldInfos": [],
                "description": null,
                "showAttachments": true,
                "mediaInfos": []
            }
        },
        {
            "id": 1,
            "popupInfo": {
                "title": "Contours 0.25 m: {ELEVATION}",
                "fieldInfos": [
                    {
                        "fieldName": "OBJECTID",
                        "label": "Object ID",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox"
                    },
                    {
                        "fieldName": "ELEVATION",
                        "label": "Elevation (m) AHD",
                        "tooltip": "",
                        "visible": true,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": true
                        }
                    },
                    {
                        "fieldName": "CLASSIFICATION",
                        "label": "Classification",
                        "tooltip": "",
                        "visible": true,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": false
                        }
                    },
                    {
                        "fieldName": "SHAPE",
                        "label": "Shape",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox"
                    }
                ],
                "description": null,
                "showAttachments": true,
                "mediaInfos": []
            },
            "layerDefinition": {
                "defaultVisibility": true
            }
        },
        {
            "id": 2,
            "popupInfo": {
                "title": "Contours 5m: {ELEVATION}",
                "fieldInfos": [
                    {
                        "fieldName": "OBJECTID",
                        "label": "Object ID",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox"
                    },
                    {
                        "fieldName": "ELEVATION",
                        "label": "Elevation (m) AHD",
                        "tooltip": "",
                        "visible": true,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": true
                        }
                    },
                    {
                        "fieldName": "CLASSIFICATION",
                        "label": "Classification",
                        "tooltip": "",
                        "visible": true,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": true
                        }
                    },
                    {
                        "fieldName": "SHAPE",
                        "label": "Shape",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox"
                    },
                    {
                        "fieldName": "SHAPE_STLength__",
                        "label": "SHAPE.STLength()",
                        "tooltip": "",
                        "visible": false,
                        "stringFieldOption": "textbox",
                        "format": {
                            "places": 2,
                            "digitSeparator": true
                        }
                    }
                ],
                "description": null,
                "showAttachments": true,
                "mediaInfos": []
            }
        },
    ]
}



To access this via the api: First you can access the item through gis.content.get with the item ID.
Once you've got the item, use the get_data method https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html?highlight=get_data#arcgis.gis... to download the JSON data above. 

Once you've got a copy of this data, you can iterate through the layers to programmatically change the value for "digitSeparator". 

Lastly, you can update the item through the item.update method.  This will push the changes back up into the map/feature service item. 

While I don't have a snippet available off the top of my head, I've used this process numerous times to update/migrate popup data. 

ChenLi
by
Emerging Contributor

Thanks to AlexBowler, the Python code works as

#Note: add the Layer in Map Viewer and Save Layer first, otherwise .get_data returns empty {}
gis = arcgis.gis.GIS("https://arcgis.com", verify_cert=False)
item = gis.content.get("4c44fb8e5a1f43acacxxxxxxx") # The layer <item-id>
item_data = item.get_data(try_json=True)
item_data['layers'][0]['popupInfo']['fieldInfos'][1]['format']['digitSeparator'] = False
item_properties = {"text": json.dumps(item_data)}
item.update(item_properties=item_properties)

0 Kudos
AlderMaps
Frequent Contributor
#Note: add the Layer in Map Viewer and Save Layer first, otherwise .get_data returns empty {}

Was really hoping this was going to do the trick for me. Already have a script that works fine on a feature layer collection; have been asked to make this work for map img service, for which .get_data() returned empty.

Tried the advice above...and get back a dict only 3 keys, visibleLayers, visibility and opacity. 😞

I mean at least it's not empty...but was really hoping for the layers in there. Any insight into what my issue might be would be appreciated. For now, back to the drawing board...

0 Kudos