Map Screenshot with ArcGIS API for Python

244
1
02-26-2021 06:47 AM
YuliaMamonova
Occasional Contributor II

Hi all,

I am trying to create a script that would take a screenshot of the specific map area which would include the basemap and all the layers on the map.

The code below zooms in to the targeted area of the map and generates a screenshot. The problem is the screenshot only displays imagery layers, while vector layers are not showing up on the map. Any ideas why it's happening?

My code so far:

from arcgis.gis import GIS
from arcgis.mapping import export_map

gis = GIS('https://######.maps.arcgis.com/',
username='####',
password='####',
verify_cert=False)

webmap_item = gis.content.get('######')

webmap_json = webmap_item.get_data()

# Get coordinates of the targeted feature on the map
 
id_target = gis.content.get('######')
id_layer = id_target.layers[1]
id_features = id_featureset.features
test_feature = id_features[0]
coordinates = test_feature.geometry['rings'][0]
xmin, xmax = coordinates[1][0], coordinates[2][0]
ymin, ymax = coordinates[1][1], coordinates[2][1]

# Modify json with map options and export options
 
webmap_json['mapOptions'] = {
"extent" : {
"xmin": xmin,
"ymin": ymin,
"xmax": xmax,
"ymax": ymax,
"spatialReference": {
"wkid": 4326
}
},
"spatialReference" : {
"wkid" : 4326
}
}
webmap_json['exportOptions'] = { "dpi" : 96,
"outputSize" : [1000, 1000]
}

out = export_map(web_map_as_json=webmap_json, format='PNG8', layout_template='MAP_ONLY', gis=gis)

print(out)
0 Kudos
1 Reply
CalvinLietz
Esri Contributor

Hi Yulia,

What happens if you take the same web_map_as_JSON parameter and pass it into the default ArcGIS Online print service operation? 

https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%...

Do all the layers appear as expected?

-Calvin

0 Kudos