感谢一路走来默默支持和陪伴的你~~~
----------------------欢迎来访,拒绝转载----------------------
1. 调用ArcGIS API的Print实现地图的打印输出,部分代码如下:
//打印输出的参数数组,为打印输出的模板提供参数准备
var layouts = [{
name:"Letter ANSI A Landscape",
label:"Landscape(PDF)",
format:"pdf",
options:{
"legendLayers":[legendlayer0,legendlayer1,legendLayer3],
'scalebarUnit':"Miles",
'titleText': dom.byId('print_title').value,
"authorText":dom.byId('print_author').value,
"copyrightText":dom.byId('print_copyright').value
}
},{
name:"Letter ANSI A Portrait",
label:"Portrait(Image)",
format:"jpg",
options:{
"legendLayers":[legendlayer0,legendlayer1,legendLayer3],
"scalebarUnit":"Miles",
"titleText": dom.byId('print_title').value,
"authorText":dom.byId('print_author').value,
"copyrightText":dom.byId('print_copyright').value
}
}];
//定义打印输出的模板
var templates = array.map(layouts,function(lo){
var t = new PrintTemplate();
t.layout = lo.name;
t.label = lo.label;
t.format = lo.format;
t.layoutOptions = lo.options;
return t;
});
//打印输出功能
printer = new Print({
map: map,
templates:templates,
url: "http://192.168.18.102:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
}, dom.byId("printButton"));
printer.startup();
});
在浏览器端执行,输入图名、单位等信息并进行打印输出,选择打印的方式,如下:
以为你会愉快的运行,然而却遇到了一个酱紫的问题:输出的中文全部为乱码,怎么办呢?
-----------------------这是一条华丽丽的分割线---------------------
2.问题分析
仔细查阅,打印的API中也并为提供对PrintTemplate的字体的设置,然而PrintTask服务也是调用了ArcGIS Server中内置的出图模板,找到目录,打开模板进行查看:
打开在代码中所使用的相应的模板进行查看,惊奇大发现:所有输出为乱码的图名、单位名称等在模板中的默认字体均为Arial欧洲字体,怎能不可乱码~~~
-----------------------这是一条华丽丽的分割线---------------------
3. 问题解决:
很简单喽,修改每一处的字体为中文字体:以图名为例,右键单击图名选址properties,点击Change Symbol,修改字体类型。修改完毕后保存并关闭MXD文档。如下:
再次执行查看效果:
问题解决了~~~
----------------欢迎来访,拒绝转载----------------
版权声明:本文为博主原创文章,未经博主允许不得转载。
|