Export Web Map to image

937
2
Jump to solution
10-18-2018 07:13 AM
deleted-user-MOQmQl8Sb2hg
New Contributor II

I am trying to export a web map constructed in python (1.5.0) as an image, however, when sending the web map to the export_map call, the JSON appears to be missing the MapOptions section of the JSON that is needed. Any thoughts on what I am missing?

search_result = gis.content.search(query="title:" + carrier + "_In-Force", item_type="Feature Layer")
print(search_result[0])

search_result_HU = gis.content.search(query="title:Michael_10_12", item_type="Feature Layer")
print(search_result_HU[0])

wm = WebMap()
wm.add_layer(search_result_HU[0], options={'title': 'Hurricane', 'opacity': 0.5})
wm.add_layer(search_result[0], options={'title': 'Locations'})
print(wm.definition)

output = mapping.export_map(web_map_as_json=wm, format='PNG32')
print(type(output))

When calling the export_map, I am getting the following error:

Error executing tool. Export Web Map Task : 'mapOptions'

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
deleted-user-MOQmQl8Sb2hg
New Contributor II

Well I solved my own issue. 

I manually added the MapOptions and exportOptions to the webMap JSON.

webmapJSON = web_map_item.get_data()

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

From here, you can call the export_map function and the image will be rendered.

Also, beware that your layers must be marked public for this to work.

View solution in original post

2 Replies
deleted-user-MOQmQl8Sb2hg
New Contributor II

Well I solved my own issue. 

I manually added the MapOptions and exportOptions to the webMap JSON.

webmapJSON = web_map_item.get_data()

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

From here, you can call the export_map function and the image will be rendered.

Also, beware that your layers must be marked public for this to work.

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Thanks for sharing.

0 Kudos