We would like to write a javascript code to save a map (with layers) as an image file. We do not have desktop, but have an AGOL account. The help community points at utility.arcgis.com (printing - Setting up ArcGIS Print service for ArcGIS Online account? - Geographic Information Syste...). Can anyone give us more pointers on how to exactly use the utility.arcgis.com's print service? Thank you
Shawn,
Here is some code snippet I use for that:
//Requires needed
'esri/tasks/PrintTemplate',
'esri/tasks/PrintParameters',
'esri/tasks/PrintTask',
'dojo/_base/lang'
PrintTemplate, PrintParameters, PrintTask, lang
var printTask = new PrintTask('http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export Web Map Task');
var template = new PrintTemplate();
//code to calculate and maintain images aspect ratio
var oWid = this.map.width;
var oHgt = this.map.height;
this.imgHeight = (740/oWid) * oHgt;
template.exportOptions = {
width: 1542,
height: (1542/oWid) * oHgt,
dpi: 200
};
template.format = "jpg";
template.layout = "MAP_ONLY";
template.preserveScale = false;
template.showAttribution = false;
var params = new PrintParameters();
params.map = this.map;
params.template = template;
printTask.execute(params, lang.hitch(this, this.printResult));
function printResult(rsltURL){
console.info(rsltURL);
}
Thanks but I do not have the server installed. I have to try replacing " 'http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export Web Map Task'" with the utility.arcgis.com link.
Shawn,
Sampleserver6 is a publicly accessible server. You do not need your own.
You can create an image client-side using HTML canvas. See this project: GitHub - WSDOT-GIS/arcgis-map-thumbnail-builder: Exports an image of an ArcGIS API for JavaScript ma...