Select to view content in your preferred language

update the html in 'custom attribute display' programatically using rest api python

1734
5
12-20-2017 11:44 PM
PareshPatel2
Occasional Contributor

I need to loop each web map in ArcGIS online/portal and update the html for layers with  'custom attribute display'.

I am unable to get layers from web map.


from IPython.display import display
import arcgis
from arcgis.gis import GIS
# connect to your GIS
gis = GIS("https://www.arcgis.com","arcgis_python","P@ssword123")
webmap_search = gis.content.search("Ebola maps", item_type="Web Map")
ebola_map_item = webmap_search[1]
ebola_map = WebMap(ebola_map_item)
for layer in ebola_map.layers: --- error: 
'WebMap' object has no attribute 'layers'

    print(layer.title)
Is there any possibilities of updating HTML programmatically for all the layers in webmaps in Group.
0 Kudos
5 Replies
by Anonymous User
Not applicable

The 'layers' property of 'WebMap' objects is something that is available in version 1.3 and above. Can you upgrade your conda package and try?

At version 1.3, when you add a layer to your web map by calling 'add_layer()' method, it automatically builds a default pop-up. You can customize it further by removing certain attributes that you do not want to display.

0 Kudos
PareshPatel2
Occasional Contributor

Thank you for response.

Is that possible for update default pop-up programmatically

Basically our idea is, we are retrieving list of service layers fields information and generating our own html table for configure pop - up when creating web map with the respective services.

0 Kudos
by Anonymous User
Not applicable

At the current version (1.3) the API the pop-up functionality is limited to giving you a basic pop-up that displays all the fields in a table.

But, if you know what needs to be put in the pup-up object, you can easily change the values and call the `update()` method. Since you are doing this on multiple web maps, I would recommend doing one using the web map UX (or ArcGIS Pro), read that maps definition (call the WebMap.definition or WebMap.layers property) to find the pop-up object and replicate that logic in all your maps.

PareshPatel2
Occasional Contributor

Thank you Mani,

I am able to get the current configure popupinfo using below code, but when I tried to update it back, it's not reflecting.

I don't know where i am missing. 

from arcgis.gis import GIS
from arcgis.gis import *
from arcgis.mapping import WebMap, WebScene

ago_gis = GIS(pPrtl_URL , pUserName , PPswrd) // Connecting Portal
search_Results = ago_gis.content.search('title:Test_html',item_type='Web Map', max_items=1000, outside_org=False) // Search Web Map
wm = search_Results[0]
web_map_obj = WebMap(wm)
lyrsdct = web_map_obj.layers[0]
lyrobj = lyrsdct['layers'][0]
popinfoObj = lyrobj['popupInfo']
popinfoObj['description'] // Able to display existing configured popinfoObj

// I am assing html table
popinfoObj['description'] = """ <table style="width:100%">
<tbody>
<tr>
<td>
<b>
<u>B</u>
</b>
</td>
</tr>
<tr style="background-color: #e9e9e9">
<td>SUBBASIN</td>
<td>{SUBBASIN }</td>
</tr>
<tr >
<td>CGIA_FMS</td>
<td>{CGIA_FMS }</td>
</tr>
<tr style="background-color: #e9e9e9">
<td>DWQ_INDEX_</td>
<td>{DWQ_INDEX_ }</td>
</tr>
<tr >
<td>DWQ_CLASS</td>
<td>{DWQ_CLASS }</td>
</tr>
</tbody>
</table> """
web_map_obj.update // updating map object
wm.update // updating web map

0 Kudos
TylerHays
New Contributor

Paresh Patel, you'll have to edit the web map object dictionary directly with the new HTML code, as opposed to editing the children dictionaries that are created as copies in your script.  In version 1.2.3, index into the appropriate list item/dictionary value and set the description key equal to your html code, then call the web_map_object.update() method, which will send the update to the server.  In version 1.3, obtain the definition dictionary of the web map object and edit accordingly, then pass the dictionary in to the web_map_object.update() method.  Refer to the scripts below:

With version 1.2.3 of the ArcGIS API for Python:

from arcgis.gis import GIS
from arcgis.mapping import WebMap
gis = GIS("<org_url>", "username", "password")


search = gis.content.search('title:Test_html')
wm = search[0]
wmo = WebMap(wm)

updated_html = "<updated html string>"
wmo['operationalLayers'][0]['layers'][0]['popupInfo']['description'] = updated_html
wmo.update()

With version 1.3 of the ArcGIS API for Python:

from arcgis.gis import GIS
from arcgis.mapping import WebMap
gis = GIS("<org_url>", "username", "password")

search = gis.content.search('title:Test_html')
wm = search[0]
wmo = WebMap(wm)

updated_html = "<updated html string>"

# get the definition dictionary of the web map object
def_dict = wmo.definition

# index into the appropriate layer and assign the update html as the popup 
def_dict['operationalLayers'][0]['layers'][0]['popupInfo']['description'] = updated_html

# pass the updated definition dictionary into the web map object update method, boolean is returned
wmo.update(def_dict)

0 Kudos