How to Publish Pro Map as Web Map using python

561
1
09-02-2022 12:14 PM
BlueBunnies
New Contributor II

I am trying to publish a map from Pro as a Web Map to my portal.

The reason is that I need to create many web maps, but need to use a custom basemap that I have created. I cannot use any of the Esri basemaps at all. 

I have looked and have not been able to find any code that will allow me to publish a map document as a web map. 

I have looked into creating a web map using:  Web_Map = WebMap()

The issue though with that is that it will use a default Esri basemap. I cannot build it off a web map that already has the custom basemap I want.... they don't exist and will not exist. So I need to be able to set the basemap with an existing published layer... but nothing I have done is working.

Here is what I have tried:

#Publish layer as service
BM_layer_item = BM_item.publish()
BM_layer_item

#Create Web Map instance
Web_Map = WebMap()

#Add item to webmap as basemap

Web_Map.basemap=BM_layer_item

#Set web map properties

Set web_map_properties = {'title':'BaseMap1',
'snippet':'basemap test',
'tags':'test'}

#Save web map

web_map_item = Web_Map.save(item_properties=web_map_properties)

The end result is that I get a web map with an Esri basemap and not the custom basemap I was trying to set.

Can anyone help figure this out?

 

 

 

Tags (3)
0 Kudos
1 Reply
Clubdebambos
Occasional Contributor III

Hi @BlueBunnies,

Have you published your custom BaseMap to AGOL? See here for example.

If you create a WebMap manually in AGOL can you add your Custom BaseMap? 

If not, this is the first step, once its available in AGOL the automation of creating WebMaps using the BaseMap becomes easier. For me, I simply create a WebMap manually with just the Custom BaseMap, and use this as a template, add layers and tables and save as a new WebMap each time using the Python API. You can also add to a Custom BaseMap Gallery and create a new WebMap from scratch and add the Custom BaseMap. The former is just my preference.

The code below if the process when the Custom BaseMap is available in AGOL and a saved WebMap template.   

from arcgis import GIS
from arcgis.mapping import WebMap

## connect to AGOL
agol = GIS("home)

## get webmap item (template)
wm_item = agol.content.get("WM_ITEM_ID")

## create webmap object using webmap item
webmap = WebMap(wm_item)
###############################
## CODE TO ADD IN LAYERS/TABLES
###############################

## properties for new webmap 
properties = {
    "title" : "webmap_name",
    "snippet" : "summary",
    "tags" : "tag1,tag2,tag3"
}

## save new webmap
webmap.save(properties)

 

~ learn.finaldraftmapping.com
0 Kudos