ArcGIS API For Javascript GP工具 Printing Tools匯出地圖或者列印地圖(二):GP 服務Printing Tools
阿新 • • 發佈:2018-11-27
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);
};
});
}