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.
'WebMap' object has no attribute 'layers'
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.
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.
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.
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
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)