Hello guys,
Using ArcGIS API for python, I'm trying to add layer that contain standalone table to a list of webmap in my organization programmatically but don't work.
When I execute the method to add a mapservice layer to webmap, just add normal feature class layer, not standalone table.
There are any way to avoid that behavior or some workaround ?
maintenance_webmap = "webmap id"
mapa_consultas = gis.content.get(maintenance_webmap)
web_map_obj = WebMap(mapa_consultas)
maintenance_layer = gis.content.get(maintenance_layer_id)
web_map_obj.add_layer(maintenance_layer, options={'title':maintenance_layer_title})
Solved! Go to Solution.
from arcgis.gis import GIS
from arcgis.mapping import WebMap
from arcgis.features import Table
## Access AGOL
agol = GIS("home")
## Access the WebMap Item
wm_item = agol.content.get("WEBMAP_ITEM_ID")
## Create a WebMap object from WebMp Item
webmap = WebMap(wm_item)
## Access the Feature Service
table_item = agol.content.get("FS_ITEM_ID")
## Create a Table object from the Feature Service / Table Service Item
## make sure the grab the correct table using the ID, 0 is used in the example below
tbl = Table.fromitem(table_item, 0)
## Add the Table to the WebMap
webmap.add_table(tbl)
## Update and save the WebMap
webmap.update()
Can you try WebMap.add_table()? It works basically the same way, but it's intended for tables.
You'll need to change your code a bit and use the id for the table instead.
from arcgis.gis import GIS
from arcgis.mapping import WebMap
from arcgis.features import Table
## Access AGOL
agol = GIS("home")
## Access the WebMap Item
wm_item = agol.content.get("WEBMAP_ITEM_ID")
## Create a WebMap object from WebMp Item
webmap = WebMap(wm_item)
## Access the Feature Service
table_item = agol.content.get("FS_ITEM_ID")
## Create a Table object from the Feature Service / Table Service Item
## make sure the grab the correct table using the ID, 0 is used in the example below
tbl = Table.fromitem(table_item, 0)
## Add the Table to the WebMap
webmap.add_table(tbl)
## Update and save the WebMap
webmap.update()
Works perfectly, thank you @Clubdebambos and @EarlMedina