Retour à la documentation
/**
* @class spw.widgets.SpwPrintTask
*/
define(["dojo/_base/declare", "spw/api/SpwBaseWidget", "dojo/_base/lang",
"dojo/i18n!./nls/SpwCanvasPrinter",
"spw/api/MessageManager", "esri/config", "spw/api/Printer"],
function(declare, SpwBaseWidget, lang, labels,
MessageManager, esriConfig, Printer){
return declare("spw.widgets.SpwPrintTask", [SpwBaseWidget], /** @lends spw.widgets.SpwPrintTask.prototype */{
printServerUrl: "http://sampleserver6.arcgisonline.com:80/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export Web Map Task",
labels: labels,
generating: false,
widgetTitle: labels.printLabel,
iconClass: "spwMapPrinterIcon",
_widgetTitle: "",
_iconClass: "",
onActivate: function(){
if(this.generating){
MessageManager.getInstance().notifyInfo(this.labels["alreadyPrinting"]);
} else {
this.generating = true;
this._widgetTitle = this.get('widgetTitle');
this.set('widgetTitle', this.labels.generating);
this._iconClass = this.get('iconClass');
this.set('iconClass', "generatingIcon");
this.inherited(arguments);
new Printer().getImagePrintTask(this.printServerUrl, 750, 625, lang.hitch(this, this.printResult), lang.hitch(this, this.printError));
}
},
printResult: function(data){
this.generating = false;
this.set('widgetTitle', this._widgetTitle);
this.set('iconClass', this._iconClass);
window.open(data.url);
},
printError: function(error){
this.generating = false;
this.set('widgetTitle', this._widgetTitle);
this.set('iconClass', this._iconClass);
console.log(error);
}
});
});