ArcGIS API for Python version 2.2.0.1
I have used the move_from_basemap() to move basemap to a layer.
from arcgis.gis import GIS
from arcgis.mapping import WebMap
## Access AGOL
agol = GIS("home")
## get webmap item
wm_item = agol.content.get("WM_ITEM_ID")
## create WebMap object
webmap = WebMap(wm_item)
## get basemap definition
basemap_lyr = webmap.definition["baseMap"]["baseMapLayers"][0]
## call move_from_basemap
webmap.move_from_basemap(basemap_lyr)
## update basemap
webmap.update()
This works perfectly! Now going in the other direction with move_to_basemap()
from arcgis.gis import GIS
from arcgis.mapping import WebMap
## Access AGOL
agol = GIS("home")
## get webmap item
wm_item = agol.content.get("WM_ITEM_ID")
## create WebMap object
webmap = WebMap(wm_item)
## get layer definition
basemap_lyr = [lyr for lyr in webmap.layers if lyr.title == "Dark Gray Base"][0]
## move to basemap
webmap.move_to_basemap(basemap_lyr)
## update webmap
webmap.update()
I am returned this error..
arcgis.gis.Error: This layer type cannot be added as a basemap. See method description to know what layer types can be moved to basemap.
The layer is a VectorTileLayer and as per documentation should work!! I mean, its a layer that I switched from the basemap in the first place.
{
"id": "dark-gray-base-layer",
"opacity": 1,
"title": "Dark Gray Base",
"visibility": true,
"layerType": "VectorTileLayer",
"styleUrl": "https://www.arcgis.com/sharing/rest/content/items/5e9b3685f4c24d8781073dd928ebda50/resources/styles/root.json"
}