I need to generate some map images for use in a web application, using the Nat Geo base map, an ocean contour layer and some points plotted from a KML file. I have the map working OK using the 3.18 JS library, but I don't want a dynamic, tiled image returned, just a single PNG or JPG image that I can then save locally. Is this possible? New to ArcGIS and mapping in general! Thanks.
Solved! Go to Solution.
Andrew,
For that you would use the PrintTask and MAP_ONLY print template. Here is a snippet of code that I use for this purpose:
var oWid = this.map.width;
var oHgt = this.map.height;
var printTask = new PrintTask('YOURS /rest/services/ExportWebMap/GPServer/Export Web Map');
var template = new PrintTemplate();
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));
printResult: function(rsltURL){
var mapImg = domConstruct.toDom('<img src="'+rsltURL.url+'" border="0" style="width:740px;height:'+this.imgHeight+'px;"/>');
domConstruct.place(mapImg, dom.byId('mapImgDiv'), 'replace');
},
Andrew,
For that you would use the PrintTask and MAP_ONLY print template. Here is a snippet of code that I use for this purpose:
var oWid = this.map.width;
var oHgt = this.map.height;
var printTask = new PrintTask('YOURS /rest/services/ExportWebMap/GPServer/Export Web Map');
var template = new PrintTemplate();
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));
printResult: function(rsltURL){
var mapImg = domConstruct.toDom('<img src="'+rsltURL.url+'" border="0" style="width:740px;height:'+this.imgHeight+'px;"/>');
domConstruct.place(mapImg, dom.byId('mapImgDiv'), 'replace');
},
Hi - thanks for the reply. I should have said the we don't have an ArcGIS server instance which I think this solution relies on?
Thanks, Andy
Andrew,
So you use one of the sample or AGOL servers then.
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%...
Ok I'll investigate that - thanks a lot.