ArcGIS API For Js 出图
按照上一篇写的,用Printing Tools导出或者打印地图源码奉上,里面需要注意跨域问题,要设置代理
//打印出图
function initPrintMap() {require(['dojo/_base/declare',
'dojo/_base/lang',
'dojo/on',
'esri/Evented',
'esri/tasks/PrintTemplate',
'esri/tasks/PrintTask',
'esri/tasks/PrintParameters',
'esri/request',
'esri/config',
'dojo/_base/array',
'dojo/dom',
'dojo/parser'], function (declare, lang, on,
Evented, PrintTemplate, PrintTask, PrintParameters, esriRequest, esriConfig, arrayUtils, dom, parser) {
$("#print_button").bind("click", function (e) {
var printMapTitle ='地图标题';
var printMapCompany ='出图单位';
var printMapPaper = 'A4 Landscape';';
var printFileFormat ='PNG32';
parser.parse();
printUrl = appConfig.Settings['ServiceUrl'];
esriConfig.defaults.io.proxyUrl = appConfig.Settings['publishUrl'];//代理设置
var printTask = new PrintTask(
printUrl
//{ async: true }
);//地图打印GP服务
var template = new PrintTemplate();
template.layout = printMapPaper;
template.format = printFileFormat;
template.exportOptions = {
width: 842,
height: 595,
dpi: 96
};
template.layoutOptions = {
"authorText": "发布单位:",
"copyrightText": "<copyright info here>",
//"legendLayers": ['', ''],
"titleText": printMapTitle,
"scalebarUnit": "KiloMeters",
"preserveScale": true,
"showAttribution": true,
"showLabels": true
};
var params = new PrintParameters();
params.map = map;
params.template = template;
printTask.execute(params, printResult, printError);
});
printResult = function (e) {//出图成功
window.open(e.url, "_blank");
};
printError = function (e) {//出图失败
alert("打印失败!");
console.log(e.error);
};
});
}