add layer to web map with standalone table don't work

427
3
Jump to solution
01-26-2024 07:19 AM
Labels (3)
RenatoTeixeira1
New Contributor III

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})

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Clubdebambos
Occasional Contributor III

Hi @RenatoTeixeira1 

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()
~ learn.finaldraftmapping.com

View solution in original post

3 Replies
EarlMedina
Esri Regular Contributor

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.

 

0 Kudos
Clubdebambos
Occasional Contributor III

Hi @RenatoTeixeira1 

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()
~ learn.finaldraftmapping.com
RenatoTeixeira1
New Contributor III

Works perfectly, thank you @Clubdebambos  and @EarlMedina