The following is the JavaScript function:function Print() {
var app = {};
require([
"esri/map", "esri/layers/FeatureLayer", "esri/layers/ArcGISDynamicMapServiceLayer",
"esri/dijit/Print", "esri/tasks/PrintTemplate",
"esri/request", "esri/config",
"dojo/_base/array", "dojo/dom", /*"dojo/parser",*/
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function(
Map, FeatureLayer, ArcGISDynamicMapServiceLayer,
Print, PrintTemplate,
esriRequest, esriConfig,
arrayUtils, dom/*, parser*/
) {
//parser.parse();
app.printUrl = "http://www.mapping2.cityoflondon.gov.uk/arcgis/rest/services/Printing/ExportWebMap/GPServer/Export%20Web%20Map";
esriConfig.defaults.io.proxyUrl = "http://vmgisapp02/proxy/proxy.ashx";
app.map = map;
/*
app.map = new esri.Map("map");
var permitUrl = "http://vmgisapp03/arcgis/rest/services/Test4YellowLines/MapServer/0";
var poolFeatureLayer = new FeatureLayer(permitUrl, {
"mode": FeatureLayer.MODE_SNAPSHOT
});
app.map.addLayer(poolFeatureLayer);
*/
// get print templates from the export web map task
var printInfo = esriRequest({
"url": app.printUrl,
"content": { "f": "json" }
});
printInfo.then(handlePrintInfo, handleError);
function handlePrintInfo(resp) {
var layoutTemplate, templateNames, mapOnlyIndex, templates;
layoutTemplate = arrayUtils.filter(resp.parameters, function(param, idx) {
return param.name === "Layout_Template";
});
if ( layoutTemplate.length == 0 ) {
//alert("print service parameters name for templates must be \"Layout_Template\"");
return;
}
templateNames = layoutTemplate[0].choiceList;
// remove the MAP_ONLY template then add it to the end of the list of templates
mapOnlyIndex = arrayUtils.indexOf(templateNames, "MAP_ONLY");
if ( mapOnlyIndex > -1 ) {
var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];
templateNames.push(mapOnly);
}
// create a print template for each choice
templates = arrayUtils.map(templateNames, function(ch) {
var plate = new PrintTemplate();
plate.layout = plate.label = ch;
plate.format = "PDF";
plate.layoutOptions = {
"authorText": "Made by: Esri's JS API Team",
"copyrightText": "<copyright info here>",
"legendLayers": [],
"titleText": "Pool Permits",
"scalebarUnit": "Miles"
};
return plate;
});
app.printer = new Print({
"map": app.map,
"templates": templates,
url: app.printUrl
}, dom.byId("print_button"));
app.printer.startup();
}
function handleError(err) {
alert("Something broke: ", err);
}
});
}
When this function is outputted on a html map page, I get Cross Origin errors, these don't stop the code from working??( Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://vmgisapp03/arcgis/rest/services/Printing/ExportWebMap/GPServer/Export%20Web%20Map/execute. This can be fixed by moving the resource to the same domain or enabling CORS. )The following error is more worrying: POST http://www.mapping2.cityoflondon.gov.uk/arcgis/r...ExportWebMap/GPServer/Export%20Web%20Map/execute Aborted 60s init.js (line 157)RequestTimeoutError: Timeout exceeded ...g"],function(b){return function(m,e,p,n){p=p||Error;var k=function(b){if(p===Err...I have tested the line.... "app.map = map;"When I comment out "app.map = map;" and uncomment the code block below it, everything works fine.The line "app.map=map;" is taking the existing map object from another JS file elsewhere.It would be great to hear your thoughts.Thanks,Saqib.