I would like to use ArcGIS Python API (v. 1.4.1) to copy the operational layers from one map to another in the same 10.6 Portal (for a development map / production map environment where I make changes to the development maps' symbology, layers, popups, etc., and then just copy the entire operational layers object to the production map), but I can't get it to work (even though it worked on a previous version of the API / previous version of Portal).
Here is my old code, which worked in a previous version.
In this version, the code successfully runs, but the destination map isn't changed.
from arcgis.gis import GIS
from arcgis.gis import Item
import arcgis.mapping
portal = GIS("https://portalurl/webcontext", "username","password", verify_cert=False)
srcMap = Item(portal, "5959197ba01748ccb51cf097597b4cf4")
destMap= Item(portal,"e326e343d5aa45668a448e54acc4d06d")
opsLayers = srcMap.get_data()['operationalLayers']
mapDestObj = arcgis.mapping.WebMap(destMap)
mapDestObj['operationalLayers'] = opsLayers
mapDestObj.update()
I've also followed instructions located at Using and updating GIS content | ArcGIS for Developers , but that doesn't seem to work either.
mapDestObj has a layers attribute, but mapDestObj.layers = opsLayers throws an AttributeError (can't set attribute)
I've also tried the following: which successfully updates the mapDestObj.layers attribute, but doesn't save the map when I run the update command.
for index, layer in enumerate(mapDestObj.layers):
mapDestObj.layers[index] = opsLayers[index]
webMapObj.update({})
Does anyone have a working prototype for this workflow?
Solved! Go to Solution.
Jay Gregory, in your first snippet, you may have to change the last but one line to the following
# your current line
# mapDestObj['operationalLayers'] = opsLayers
mapDestObj.definition['operationalLayers'] = opsLayers
mapDestObj.update()
and that should work. Can you give this a try and let me know?
Jay Gregory, in your first snippet, you may have to change the last but one line to the following
# your current line
# mapDestObj['operationalLayers'] = opsLayers
mapDestObj.definition['operationalLayers'] = opsLayers
mapDestObj.update()
and that should work. Can you give this a try and let me know?
Thanks - that worked! It seems like the definition attribute isn't listed in the documentation.
Also, I was able to get the operation to work by doing the following:
srcData = srcMap.get_data() destData = destMap.get_data() destData['operationalLayers'] = srcData['operationalLayers'] destMap.update(data=str(destData))
You are welcome. For future reference, the correct way to do your workaround is to pass a dictionary with key= "text" and value = your web map dict. So the last line should look like this
import json
destMap.update(data={'text':json.dumps(destData)})