I am trying to edit the popup fields for a featureset layer (of points) I have added to a WebMap class item. I have been trying to follow the sample notebook from DevSummit2022 on editing popups, but I am stuck at
In [23]: national_forest = webmap.get_layer(title="national_forest") national_forest.popupInfo
When I do the same operation on my webmap layer, for 'national_forest' I get an object of type 'arcgis._impl.common._mixins.PropertyMap' and an error that says:
'PropertyMap' instance has no attribute 'popupInfo'
Solved! Go to Solution.
I have had a look at the WebMap and will point out a few things.
1. In the code below you are accessing a Group Layer with
income = webmap.get_layer(title="Median Household Income")
You really want to access an individual layer within this group, such as below.
income = webmap.get_layer(title="State (Median income)")
2. However, if we look at the webmap, the popup for this layer is disabled. When I turned it on the PopUp doesnt display fields it displays a graph (well, 2 graphs that you can use as a carousel). Are you looking to remove the graphs?
You can still access the popupInfo for that layer using the following...
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import json
gis = GIS()
webmap_item = gis.content.get("efa66839c8804250917dc75b07839fdf")
webmap = WebMap(webmap_item)
income = webmap.get_layer(title="State (Median income)")
print(json.dumps(income["popupInfo"], indent=4))
3. never use list as a variable, it is a keyword in Python.
list = ["Percent_with_foodstamps", "Percent_unemployed"]
4. I have a bug request in against the configure_pop_ups() method (link here),that affects its use when the popupElements is set and has its own fieldInfos, this is just something to be aware of when attempting to manipulate popups. It will work but it will make the fields visible or not in the attribute table.
I hope that gets you a step closer to what you want to achieve.
Can you post your current code please? I know you have posted a link but it's always better to post you own endeavours when asking a question.
The first two below are easy enough to implement, the third is probably possible by adding an Arcade expression, which you can also do using the API (I use it to add links to Google Street View for example.)
Hi @Clubdebambos ! Thanks so much for helping me understand how to create a more helpful post (I'm new to this).
The eg below is just a webmap I made from publicly available layers in LivingAtlas:
from arcgis.gis import GIS
from arcgis.mapping import WebMap
gis = GIS()
webmap_item = gis.content.get("efa66839c8804250917dc75b07839fdf")
# convert webmap item into WebMap
webmap = WebMap(webmap_item)
# try to access popupInfo
income = webmap.get_layer(title="Median Household Income")
income.popupInfo
Produces error:
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9236\3513109354.py in <cell line: 0>()
2
3 income = webmap.get_layer(title="Median Household Income")
----> 4 income.popupInfo
~\AppData\Local\miniconda3\envs\test-env\Lib\site-packages\arcgis\_impl\common\_mixins.py in __getattr__(self, key)
78 """
79 if key not in self or not self._valid_name(key):
---> 80 raise AttributeError(
81 "'{cls}' instance has no attribute '{name}'".format(
82 cls=self.__class__.__name__, name=key
AttributeError: 'PropertyMap' instance has no attribute 'popupInfo'
However, popupInfo does come up when I search the keys for the operational layer.
webmap.definition['operationalLayers'][0].keys()
output:
dict_keys(['id', 'opacity', 'disablePopup', 'title', 'url', 'visibility', 'itemId', 'layerType', 'layerDefinition', 'popupInfo'])
I thought I would try a workaround since I could find it in the layer's dictionary, which almost worked, but I still got stuck because of the PropertyMap issue.
inc_popup = income_dict['popupInfo'] # works
fieldinfos = inc_popup['fieldInfos'] # brings up list
fields = []
for field in fieldinfos:
fields.append(field["fieldName"]) # creates list of all the field names
#lets say want to keep 'percent_with_foodstamps' and 'percent_unemployed'
list = ["Percent_with_foodstamps", "Percent_unemployed"]
for field in list:
fields.remove(field) # successfully removes these two fields from the list
# set our fields to false visibility
webmap .configure_pop_ups(layer_title=income.title,
field_names=fields,
visibility=False)
Returns this error message:
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9236\3973670836.py in <cell line: 0>()
1 # set our fields to false visibility (aka not visible)
----> 2 webmap.configure_pop_ups(layer_title=income.title,
3 field_names=fields,
4 visibility=False)
~\AppData\Local\miniconda3\envs\test-env\Lib\site-packages\arcgis\mapping\_types.py in configure_pop_ups(self, layer_title, field_names, visibility)
2228 for field_name in field_names:
2229 idx = 0
-> 2230 for field in layer.popupInfo.fieldInfos:
2231 if field["fieldName"] == field_name:
2232 layer.popupInfo.fieldInfos[idx].visible = visibility
~\AppData\Local\miniconda3\envs\test-env\Lib\site-packages\arcgis\_impl\common\_mixins.py in __getattr__(self, key)
78 """
79 if key not in self or not self._valid_name(key):
---> 80 raise AttributeError(
81 "'{cls}' instance has no attribute '{name}'".format(
82 cls=self.__class__.__name__, name=key
AttributeError: 'PropertyMap' instance has no attribute 'popupInfo'
Another curious situation is that that is the only layer of the 3 with 'popupInfo' in the dictionary key, even though I added them all the same way through Living Atlas and they are all PropertyMap types.
If I could get this code to work, I could understand how I could customize which fields are viewable - but a) I can't and b) I still am clueless as to how to add additional text in the popup.
Hope this was more helpful, again please let me know if not. Thanks so much for your help!
I have had a look at the WebMap and will point out a few things.
1. In the code below you are accessing a Group Layer with
income = webmap.get_layer(title="Median Household Income")
You really want to access an individual layer within this group, such as below.
income = webmap.get_layer(title="State (Median income)")
2. However, if we look at the webmap, the popup for this layer is disabled. When I turned it on the PopUp doesnt display fields it displays a graph (well, 2 graphs that you can use as a carousel). Are you looking to remove the graphs?
You can still access the popupInfo for that layer using the following...
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import json
gis = GIS()
webmap_item = gis.content.get("efa66839c8804250917dc75b07839fdf")
webmap = WebMap(webmap_item)
income = webmap.get_layer(title="State (Median income)")
print(json.dumps(income["popupInfo"], indent=4))
3. never use list as a variable, it is a keyword in Python.
list = ["Percent_with_foodstamps", "Percent_unemployed"]
4. I have a bug request in against the configure_pop_ups() method (link here),that affects its use when the popupElements is set and has its own fieldInfos, this is just something to be aware of when attempting to manipulate popups. It will work but it will make the fields visible or not in the attribute table.
I hope that gets you a step closer to what you want to achieve.
Hi again.
Thank you so much!
I was trying to customize the pop-ups for one of those layers as an example because I thought the process would be the same. I'm really trying to customize pop-ups for a point layer, but I don't think I can share it publicly.
Pointing out that those feature layers are group layers was INCREDIBLY helpful! I am used to ArcPro, and it took me a bit to adjust to each 'layer' having many sublayers at different scales in arcgis online. I totally forgot when I moved to the api. Thank you! Same with the list variable tip.
Following your instructions finally let me access the popups dict in the points layer though - so I am very grateful. I realized that I could just take the json from popups that were already formatted with arcade the way I wanted, now I am just struggling to successfully apply that to the other layer.
Thanks for your help!