Add_layer in python api for arcgis neither completes action nor returns an error

70 views Asked by At

I have a python script where I'm trying to add a feature layer to a webmap. The script completes without any errors but the feature layer doesn't get added.

Here's the code in question:

from arcgis.gis import GIS
from arcgis.mapping import WebMap

print("Logging in...")
gis = GIS("https://fotnf.maps.arcgis.com/", "XXXXXXX", "YYYYYYYY")
print(f"Connected to {gis.properties.portalHostname} as {gis.users.me.username}")

webmap_item = gis.content.get('e1405425e52d43689cfdaecd43e0239d')
feature_layer = gis.content.get('cc5eb6737f5441c48f2ea1c5ab42935e')
webmap = WebMap(webmap_item)

print("Adding layer")
webmap.add_layer(feature_layer)
print("Done")

Here's a screenshot of the Content pane in arcgis online. The code is attempting to add the Join_2_12_23 feature layer to the Test Mesa map. enter image description here

The version of the arcgis python package is 2.1.0.3

2

There are 2 answers

0
gis_iguess On

WebMap is usually used for rendering purposes in a Jupyter Notebook. Have you run this code in a Jupyter Notebook and tried rendering the WebMap object after adding the layer?

This can be done by running a cell with the object to render the map like this: enter image description here

2
maya On

In order for the map to get updated in your contents folder, it needs to be (re-)published. Otherwise, as the other response says, it will just update it so you can render it within Jupyter notebook.

This link has more info on how to do so.