AnsweredAssumed Answered

How to create a WebMap layer from json

Question asked by minerjoe on Nov 30, 2018
Latest reply on Feb 8, 2019 by minerjoe



I had a tool before that let us do the popup configuration in an editor and then reload into the web map.  This was really easy because the WebMap was just a simple dictionary and I just had to replace the ['operationalLayers'] for a file.  This cannot be done in the newest API. 


What I am trying to do instead is remove the layers and then re-add them.  The issue is when trying to add the layer using WebMap.add_layer it does not allow it.  I have copied the exact layer object from a Map and then tried to add and it does not allow, so I know it is not an issue with the json.


How do I create a layer that can be added using WebMap.add_layer from the definition json?


Here is a code sample that shows the issue adding layers.  I use the identical definition to remove and works fine, try to add the same layer and it fails


web_map = arcgis.mapping.WebMap(web_map_item)

# create a copy of the layers
layers = []

# remove layers
for layer in layers:

#try to add layers back - see error below
for layer in layers:

TypeError                                 Traceback (most recent call last)
<ipython-input-55-3865d40b28c6> in <module>()
      9 for layer in layers:
---> 10     web_map.add_layer(layer)

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\arcgis\mapping\ in add_layer(self, layer, options)
    339         else:
    340             raise TypeError("Input layer should either be a Layer object or an Item object. To know the supported layer types, refer" +
--> 341                                 'to')
    342         # endregion

TypeError: Input layer should either be a Layer object or an Item object. To know the supported layer types, referto