Version: arcgis==2.0.1
Issue:
When you specify layout options using webMap.Print these options are ignored. This includes title, author, copywrite, scalebar and legend.
Code:
wm_item = gis.content.get('item')
wm = WebMap(wm_item)
ext = {'spatialReference': {'latestWkid': 3857, 'wkid': 102100},
"xmin": 14219202.665619811,
"ymin": -3017623.8659692756,
"xmax": 14225164.753826046,
"ymax": -3005929.0006416594}
layoutOptions = {
"titleText": "LADR",
"authorText": "Oz Minerals",
"copyrightText": "Copyright Oz Minerals",
"customTextElements": [{
"date": datetime.now().strftime("%m/%d/%Y")
}],
"scaleBarOptions": {},
"legendOptions": {
"operationalLayers": ids
}
}
printed_file_url = wm.print(file_format='JPG', layout_template="A4 Landscape",
extent=ext, layout_options=layoutOptions)
The problem in the esri code is this, it hangs the layout options off the map_otions whereas they should be on the print options
I think this is how it should be:
Here is a work around if anyone else runs into this
wm_item = gis.content.get('item')
wm = WebMap(wm_item)
e = polygon.extent
ext = {'spatialReference': {'latestWkid': 3857, 'wkid': 102100},
"xmin": 14219202.665619811,
"ymin": -3017623.8659692756,
"xmax": 14225164.753826046,
"ymax": -3005929.0006416594}
# legend
ids = []
for layer in wm.layers:
ids.append({"id": layer.id})
layoutOptions = {
"titleText": "my title",
"authorText": "my author",
"copyrightText": "Copyright",
"customTextElements": [{
"date": datetime.now().strftime("%m/%d/%Y")
}],
"scaleBarOptions": {},
"legendOptions": {
"operationalLayers": ids
}
}
# DW another esri bug? Doesn't add the token on print or
for layer in wm.layers:
layer.token = gis._con.token
map_options = {
"extent": ext
}
# compose combined JSON
print_options = {
"mapOptions": map_options,
"operationalLayers": wm._webmapdict["operationalLayers"],
"baseMap": wm._basemap,
"exportOptions": {"dpi": 96},
"layoutOptions": layoutOptions
}
# dw don't use wm.print the print from the web map as it has a bug which causes the
# legend not to display.
res2 = export_map(print_options, format="JPG", layout_template="A4 Landscape", gis=gis)
print(res2.url)
Hi,
Thank you for posting this. Your code helped me solve a CODE 400 error when I ran the print function under the arcgis.mapping module.
For those who find this comment, by adding the below code to my script the 400 error code no longer occurred.
for layer in wm.layers: layer.token = gis._con.token