Update Basemap Layers using another Web Map

453
1
03-21-2023 07:38 AM
mpboyle
Occasional Contributor III

Is it possible to use the Python API to update the basemap layers of an existing web map to those of another web map?

For example, I have a template web map that has the base map configured as desired, and I'd like to use the Python API to iterate over several existing web maps and update the base map using the template web map.

Below is the code I've tried, but doesn't seem to do anything to the target web map:

import arcgis

# set web map ids
wmIDTarget = '...id1...'
wmIDTemplate = '...id2...'

# connect to portal
p = arcgis.GIS('https://www.arcgis.com/', 'user_name', 'user_password')

# create web map items
wmItemTarget = arcgis.mapping.WebMap(p.content.get(wmIDTarget))
wmItemTemplate = arcgis.mapping.WebMap(p.content.get(wmIDTemplate))

# get template base map layer information
templateBase = wmItemTemplate.basemap.get('baseMapLayers')

# update target web map base map layers
wmItemTarget.basemap.update({'baseMapLayers':templateBase})
wmItemTarget.basemap.update({'title':'Basemap Updated'})

 

1 Reply
Clubdebambos
Occasional Contributor III

Hi @mpboyle 

See code below, let me know if any issues.

from arcgis import GIS

## connect to the AGOL/Portal instance
p = arcgis.GIS('https://www.arcgis.com/', 'user_name', 'user_password')

## the id for the webmap to update
wmIDTarget = "...id1..."
## the id to for the webmap to get the basemap info from
wmIDTemplate = '...id2...'

## get as content items
wmTargetItem = p.content.get(wmIDTarget)
wmTemplateItem = p.content.get(wmIDTemplate)

## get basemap info from template
basemap_data = wmTemplateItem.get_data()["baseMap"]

## apply to target
target_data = wmTargetItem.get_data()
target_data["baseMap"] = basemap_data

## update target webamp
item_properties = {"text":target_data}
wmTargetItem.update(item_properties=item_properties)
~ Mapping my way to retirement
0 Kudos