0

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"
}

1 Answer 1

0

Apparently this is a bug...here is a workaround for now incase anyone is looking to perform similar.

from arcgis.gis import GIS
from arcgis.mapping import WebMap

## Access AGOL
agol = GIS("home")

## WebMap Item ID
wm_item_id = "WM_ITEM_ID"

## get the webmap item as an item object
wm_item = agol.content.get(wm_item_id)

## create a WebMap object from webmap item
webmap = WebMap(wm_item)

## Get the layer of interest
basemap_lyr = [lyr for lyr in webmap.layers if lyr.title == "Dark Gray Base"][0]

## Convert lyr definition to a dictionary
basemap_lyr_dict = dict(basemap_lyr)

## Remove the basemap layer from the Map
webmap.remove_layer(basemap_lyr)

## This needs to be called to make the remove layer stick
status = webmap.update()
print(status)

## Re-get the updated webmap item
wm_item = agol.content.get(wm_item_id)

## Get the webmap item data
item_data = wm_item.get_data()

## Update the Basemap list with the dictionary
item_data["baseMap"]["baseMapLayers"].append(basemap_lyr_dict)

## Define the webmap item properties
wm_item_properties = {"text":item_data}

## Update the webmap item properties
wm_item.update(item_properties=wm_item_properties)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.