Looking for explanation of how to generate "web_map_as_json" string as the argument to mapping.export_map()
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
would help
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)
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