Copy layers between webmaps not working.

06-17-2022 06:26 AM
New Contributor III

Why is this not working for copy layers from one webmap to another?



map1 = gis.content.get(<itemID_1>)
map2 = gis.content.get(<itemID_2>)

webmap1 = WebMap(map1)
webmap2 = WebMap(map2)

layer = webmap2.definition.operationalLayers[0]





I get no error messages, but there is no alteration on webmap1 as well.

It add the layer to the webmap1 when i check for it before webmap1.update(), but this update has no effect.


1 Reply
Occasional Contributor III

Hi @HenriqueJoner 

There might be a couple of ways to do this but the below has worked successfully.

from arcgis import GIS

agol = GIS("home")

map1 = agol.content.get("***wm1_id***")
map2 = agol.content.get("***wm2_id***")

map1_data = map1.get_data()
map2_data = map2.get_data()

## the layer index to copy
## index 0 is the bottom layer and those above
## increment by 1 for each layer
lyr2copy = map2_data['operationalLayers'][0]

## add the JSON or the layer to the JSON of the other 
## WebMap operationalLayers
map1_data['operationalLayers'] = map1_data['operationalLayers'] + [lyr2copy]

## Update the data for the map that the layer was coppied to
item_properties = {"text":map1_data}





~ Mapping my way to retirement
0 Kudos