Configure Popup Attributes Programmatically with ArcGIS API for Python

5887
13
Jump to solution
03-19-2018 04:58 PM
NathanielEvatt
New Contributor III

I am hoping to run a script that can hide certain fields from an ArcGIS Online web map.  In ArcGIS Online, I would accomplish this by opening a webmap, clicking the three dots of the layer I was interested in, selecting "configure pop-up" then selecting "Configure Attribute".  Finally from there I can edit the display options in the GUI shown below.  

Is this something that is currently configurable from the ArcGIS API for Python?

1 Solution

Accepted Solutions
AaronPulver
Esri Regular Contributor

This is possible but there's no "popup" API for it. You can get the webmap json, then edit the popup properties in the json, then update the webmap.

See the webmap spec here: popupInfo | ArcGIS for Developers  .

Code would be something like this (this hides every field in the popup):

import arcgis
import json

gis = arcgis.gis.GIS("https://arcgis.com", "username", "password")

item = gis.content.get("<item-id>")
item_data = item.get_data()
field_infos = item_data['operationalLayers'][0]['popupInfo']['fieldInfos']
for field in field_infos:
    field["visible"] = False

item_properties = {"text": json.dumps(item_data)}
item.update(item_properties=item_properties)

View solution in original post

13 Replies
NeilAyres
MVP Frequent Contributor

I don't see anything in here to toggle visibility.

arcgis.mapping module — arcgis 1.4.0 documentation 

0 Kudos
AaronPulver
Esri Regular Contributor

This is possible but there's no "popup" API for it. You can get the webmap json, then edit the popup properties in the json, then update the webmap.

See the webmap spec here: popupInfo | ArcGIS for Developers  .

Code would be something like this (this hides every field in the popup):

import arcgis
import json

gis = arcgis.gis.GIS("https://arcgis.com", "username", "password")

item = gis.content.get("<item-id>")
item_data = item.get_data()
field_infos = item_data['operationalLayers'][0]['popupInfo']['fieldInfos']
for field in field_infos:
    field["visible"] = False

item_properties = {"text": json.dumps(item_data)}
item.update(item_properties=item_properties)

View solution in original post

by Anonymous User
Not applicable

Maybe I should start a different conversation, but our problem is that popups go away when overwriting a service from ArcGIS Pro, and we would like to automate the process of turning them back on (grr....).

This shows how to control which fields are displayed when the popups are turned on. Is it possible to enable popups programmatically?

Thank you,

Randy McGregor

LukasWürsch
New Contributor III

Thanks a lot for your code, this is very helpful. I could make this work for normal Hosted Feature Layers. My problem is that I couldn't make it work for a Hosted Feature Layer View, because 

item_data = item.get_data()

returns None, so I am not able to access 'fieldInfos'

Is this a general issue with Hosted Feature Layer Views or is there another way how I can configure the popup of these layers?

If necessary, I can provide an example layer to reproduce the issue. I would highly appreciate an answer.

Regards,

Lukas Würsch

0 Kudos
SeanSweeney
New Contributor III

Thanks Aaron.  I'm using this on Feature Layers, and it works great as long as the Visualization for the layer has been edited already through the UI.  For brand new just-published Feature Layers item.get_data() returns None.  Is there a way through the Python API to "touch" the Visualization and create the backing JSON before running item.get_data()?  I have over 150 layers to deal with so I don't want to have to update them all manually first.

0 Kudos
AtmaMani
Esri Contributor

You can accomplish this by editing the visibility property of each field. You can do something like this

web_map_obj = WebMap(wm_item)
layer_1 = web_map_obj.layers[0]

#turn off visibility of field 1 of layer 1
layer_1.popupInfo.fieldInfos[0].visible = False

# update the web map
web_map_obj.update()
by Anonymous User
Not applicable

This is great. Thank you. Where is this documented? This is the first I've seen of this particular functionality.

Thanks,

Randy

0 Kudos
by Anonymous User
Not applicable

When the I have an operational layer that is a map service layer, the "layers" property for that consistently misses many layers. I have one service that has 24 layers, and only 3 are returned. I thought maybe only the visible layers were being returned, or just the group layers, but neither is the case. Just 3 random layers are returned, all the rest totally ignored.

 

MapImageLayer will list all layers, but that is just the contents of the portal item associated with the map service, rather than the configured layer within the web map, which is what I wan't to get at.

Is there something I'm missing (probably)?

Thank you,

Randy

0 Kudos
NathanielEvatt
New Contributor III

Cool, thanks very much guys

0 Kudos