So I believe this is taking me closer to where I need. With the code below, though, I'm having issues debugging the following errors that occurs on map extent change :
-exception in animation handler for: onEnd
-TypeError: Cannot read property 'call' of undefined(...)
I connected the signal to update extents with map extent change within printInfoHandler, as I was having issues with parameters being defined within the latter. I don't know if this is the correct way to do so.
require([
"esri/layers/FeatureLayer",
"esri/dijit/Print",
"esri/tasks/PrintTemplate",
"esri/request",
"esri/config",
"dojo/_base/array",
"dojo/dom",
], function(
FeatureLayer,
Print, PrintTemplate,
esriRequest, esriConfig,
arrayUtils, dom
) {
//var printUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
var printUrl = "http://ourserver/arcgis/rest/services/Our_Tools/Our_Print_Tool/GPServer/Exporter%20une%20carte%20Web";
var center = "";
var latLong = "";
var printer;
var plate;
esriConfig.defaults.io.proxyUrl = "http://ourserver/Java/proxy.jsp";
// get print templates from the export web map task
var printInfo = esriRequest({
"url": printUrl,
"content": {
"f": "json"
}
});
printInfo.then(handlePrintInfo, handleError);
function handlePrintInfo(resp) {
var layoutTemplate, templateNames, mapOnlyIndex, templates;
var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2);
var long = window.myMap.extent.getCenter().getLongitude().toFixed(2);
latLong = "Latitude : " + lat + " - Longitude : " + long;
var X = window.myMap.extent.getCenter().x.toFixed(2);
var Y = window.myMap.extent.getCenter().y.toFixed(2);
center = "X : " + X + " - Y : " + Y;
console.log(latLong);
console.log(center);
layoutTemplate = arrayUtils.filter(resp.parameters, function(param, idx) {
return param.name === "Layout_Template";
});
if ( layoutTemplate.length === 0 ) {
console.log("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) {
plate = new PrintTemplate();
plate.layout = plate.label = ch;
plate.format = "PDF";
plate.layoutOptions = {
customTextElements : [
{
centerLatLong: latLong,
centerXY: center
}
]
};
return plate;
});
// create the print dijit
printer = new Print({
"map": window.myMap,
"templates": templates,
url: printUrl
}, dom.byId("print_button"));
printer.startup();
window.myMap.on('extent-change', showExtent());
}
function showExtent(extent) {
var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2);
var long = window.myMap.extent.getCenter().getLongitude().toFixed(2);
latLong = "Latitude : " + lat + " - Longitude : " + long;
var X = window.myMap.extent.getCenter().x.toFixed(2);
var Y = window.myMap.extent.getCenter().y.toFixed(2);
center = "X : " + X + " - Y : " + Y;
plate.layoutOptions.customTextElements.centerLatLong = latLong;
plate.layoutOptions.customTextElements.centerXY = center;
printer.templates = [plate];
console.log(latLong);
console.log(center);
}
function handleError(err) {
console.log("Something broke: ", err);
}
});