Select to view content in your preferred language

List of basemap names to pass to addBasemap() method in Python (Arcpy)

1189
5
Jump to solution
02-28-2023 05:07 PM
Mahdi_Ch
New Contributor III

Hello all, 

I wanted to use Python to change basemap for my maps.

The documentation for addBasemap(basemap_name) method does not provide info about how to get the list of the available default basemap names. It mentions "basemap gallery" and when you search that, initially there are not much useful info but from there you go down the rabbit hole of finding some stuff on ArcGIS Maps SDK for JavaScript / API Reference and obviously the values there, are different from actual names (some of them work though).

Working with Python for a while and after seeing that API for JS, it naturally gives you the impression that there should be no spaces when passing those names. And interestingly enough, it took me a while to realize that's not the case here and you can use the names that you see in the Basemap control on the Map ribbon. Something like this:
m.addBasemap('Light Gray Canvas')

I hope if someone has the same issue, they land here and see this (instead of searching within arcpy packages and json files for a clue!)

 I was also wondering if mentioning a bit more about the basemap names in the Documentation could help other people finding it easier. Or maybe there could be a method similar to the ones for maps and layouts but for basemap (listBasemaps() ? ) to return the values to the user.

My platform: Windows 11 (22H2) and  ArcGISPro 3.1

 

0 Kudos
2 Solutions

Accepted Solutions
JeffBarrette
Esri Regular Contributor

Thanks for your feedback.  We can certainly provide a couple of examples in the doc to make it more clear that we take the literal strings that are used in the basemap gallery. We can also consider improving the design to present an enum but we need to make sure it picks up any custom basemaps and also works with different locals.

Jeff - Layout and arcpy.mp teams

View solution in original post

JeffBarrette
Esri Regular Contributor

We plan to add the following to Pro 3.2:

p = arcpy.mp.ArcGISProject(path)
m = p.createMap('New Map', 'MAP') #New at 3.1
m.addBasemap(p.listBasemaps('*imagery*)[0]) #New for 3.2

 

View solution in original post

5 Replies
JeffBarrette
Esri Regular Contributor

Thanks for your feedback.  We can certainly provide a couple of examples in the doc to make it more clear that we take the literal strings that are used in the basemap gallery. We can also consider improving the design to present an enum but we need to make sure it picks up any custom basemaps and also works with different locals.

Jeff - Layout and arcpy.mp teams

JeffBarrette
Esri Regular Contributor

We plan to add the following to Pro 3.2:

p = arcpy.mp.ArcGISProject(path)
m = p.createMap('New Map', 'MAP') #New at 3.1
m.addBasemap(p.listBasemaps('*imagery*)[0]) #New for 3.2

 

Mahdi_Ch
New Contributor III

Thank you Jeff! That will be awesome!

0 Kudos
JohnFixCai
New Contributor II

What about in ArcGIS Pro 2.9? I can't move to 3x since I'm supporting an ArcGIS Maps SDK project that geocoding fails when create a geocoder in 3.x.

 

I tried the above and I get:

AttributeError: 'ArcGISProject' object has no attribute 'listBasemaps'

Has this been added to 3.2? And how do I add a basemap in 2.9? Thanks!

0 Kudos
JeffBarrette
Esri Regular Contributor

@JohnFixCai prior to Pro 3.2, you had to pass in the full, explicit basemap name string the way it appears in the gallery.  It is sometimes confusing because what you see in the gallery is different than what you see in the TOC. For example In the Gallery you see 'Colored Pencil Map' but when it is added, you see 'Colored Pencil' in the TOC.  The listBasemaps function allows you to use a wildcard (e.g.,  'Color*') instead of the full string.

So in your case, you could use Map.addBasemap('Colored Pencil Map')

 

Jeff - Layout arcpy.mp team

0 Kudos