WebMap object move_to_basemap() method will not move the layer to the basemap

451
5
12-20-2023 08:38 AM
Labels (3)
Clubdebambos
Occasional Contributor III

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

 

 

~ learn.finaldraftmapping.com
0 Kudos
5 Replies
EarlMedina
Esri Regular Contributor

I think this one can be logged as a bug. The reference list is:

 

 

        layer_types = [
            "ArcGISTiledMapServiceLayer",
            "ArcGISImageServiceLayer",
            "ArcGISImageServiceVectorLayer",
            "ArcGISMapServiceLayer",
            "ArcGISTiledImageServiceLayer",
            "ArcGISVectorTileLayer",
        ]

 

 

 

But the layerType attribute is set to "VectorTileLayer." From a quick glance at the source, it looks like "ArcGISVectorTileLayer" is only defined in arcgis/mapping/_types.py so I think the types are either incorrect or the logic needs to be updated to properly map to the types.

0 Kudos
Clubdebambos
Occasional Contributor III

Thanks @EarlMedina 

Have you got a link to the process for reporting as a bug?

~ learn.finaldraftmapping.com
0 Kudos
Clubdebambos
Occasional Contributor III

Here's a workaround for now...

 

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)
~ learn.finaldraftmapping.com
0 Kudos
NicholasGiner1
Esri Contributor

 Hello, thanks for sharing your question.  You can report bugs and make enhancement requests to the Python API public GitHub repo here: https://github.com/Esri/arcgis-python-api/issues

thanks,

Nick Giner - Product Manager

Clubdebambos
Occasional Contributor III

Reported as bug here: https://github.com/Esri/arcgis-python-api/issues/1739 

~ learn.finaldraftmapping.com
0 Kudos