Select to view content in your preferred language

how to generate 'web_map_as_json' string from a web map in python

841
3
04-02-2020 08:02 PM
artzaifman
New Contributor III

Looking for explanation of how to generate "web_map_as_json" string as the argument to mapping.export_map()

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

This link

arcgis.mapping module — arcgis 1.8.0 documentation 

refers yo to the documentation in arcgis help topics

Web map printing with arcpy.mp—ArcPy | Documentation 

which has some stuff to read, and maybe the section on

Understand web map JSON

would help

artzaifman
New Contributor III

This seemed to do the trick:

wm_as_json = json.loads(str(wm.definition))
wm_as_json['mapOptions'] = json.loads('''{ "extent" : { "xmin":-88.55, "ymin":17.55, "xmax":-72.75, "ymax":38.05, "spatialReference" : { "wkid" : 4326 } }}''')
wm_as_json['exportOptions'] = json.loads('''{ "dpi" : 300, "outputSize" : [1000,1000]}''')

mapping.export_map(webmap_as_json=wm_as_json)

0 Kudos
ANH
by
New Contributor III

I have recently had to solve this problem. @artzaifman's answer was a good help, but it wasn't clear on how to find the webmap item in a Portal environment. Here is an updated version:

# find webmap in portal
webmap_item_id = "YOUR_WEBMAP_ITEM_ID_HERE"
gis = GIS(url=YOUR_PORTAL_URL_HERE, token=YOUR_TOKEN_HERE)
webmap = gis.content.get(webmap_item_id)
webmap_as_json = webmap.get_data()

# convert webmap to aprx
webmap_as_json['mapOptions'] = {'extent':webmap_data['initialState']['viewpoint']['targetGeometry']}
webmap_as_json['exportOptions'] = json.loads('{ "dpi" : 300, "outputSize" : [1000,1000]}')
result = arcpy.mp.ConvertWebMapToArcGISProject(webmap_as_json)
aprx = result.ArcGISProject

0 Kudos