Enable popup in Web Map

207
4
09-14-2020 07:37 AM
Highlighted
by
Occasional Contributor II

Dear All,

Is it possible to Enable popup in Web Map using ArcGIS API for Python?

   

Thanks,

Krish

Tags (1)
Reply
0 Kudos
4 Replies
Highlighted
Esri Contributor

It's possible, but not directly through the Python API. You'd want to get the web map JSON, modify it to your liking, and use the item.update() function from the API to apply the changes. More on this below:

Configure Popup Attributes Programmatically with ArcGIS API for Python 

popupInfo | ArcGIS for Developers 

arcgis.mapping module — arcgis 1.8.2 documentation 

Highlighted
Esri Contributor

Hi Krish V

Here's the code to enable popups of layers in a webmap using ArcGIS API for Python:

from arcgis.mapping import WebMap
import json

item = gis.content.get("webmap id")
item_data = item.get_data()
layers = item_data['operationalLayers']

for layer in layers:
layer.update({'disablePopup':False})

item_properties = {"text": json.dumps(item_data)}
item.update(item_properties=item_properties)
web_map = WebMap(item)
web_map
Highlighted
by
Occasional Contributor II

Hi Mehdi Pira,

The code you provided is running successfully but It doesn't change anything in the webmap.

Thanks,

Krish

Reply
0 Kudos
Highlighted
Esri Contributor

Krish V‌,

I reckon there is a bug in ArcGIS API for Python at the moment for enabling popups when a layer first time is added to a webmap.

To do a workaround, I just found out that you need to first enable popups manually and save the web map. Then when you run the code with

layer.update({'disablePopup':True})

which makes all popups disabled. After that, set 'disablePopup' to  False and run the code again. This fixes the enabling and disabling popups via the code.