备注:防止中文乱码,中文字体选用“微软雅黑”。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function Print(printTitle) {
    //var printTitle = $("#ipttitle").val();
    var legend = $("#Checkbox1").prop("checked");
    var printTask = new esri.tasks.PrintTask(printUrl);
    //打印模板
    var template = new esri.tasks.PrintTemplate();
    template.format = "JPG";
    template.label = "Portrait (Image)";
    //template.layout = "Letter ANSI A Landscape";    
    template.layout = "printtemplate";//这是本人自定义的地图模板,不是arcgis系统自带的
    //获取所有图层的Id
    var arrlegend = [];
    for (var j = 0; j < map.layerIds.length; j++) {
        var layerid = "layer" + j;
        arrlegend.push({ "layerId": layerid });//根据图层id,打印对应的图例
    }
    var options = {
        scaleBarUnit: "Miles",
        legendLayers: arrlegend,
        titleText: printTitle
    };
    if (!legend) {
        options.legendLayers = [];//图例数组为空时,不打印图例
    }
    template.layoutOptions = options;
    //打印参数
    var params = new esri.tasks.PrintParameters();
    params.map = map;
    params.template = template;
    printTask.execute(params, printResult,printError);
}
function printError(error) {
    var error = error;
    $("#btnPrint").removeAttr("disabled");
}
function printResult(result) {
    $("#btnPrint").removeAttr("disabled");
    var url = result.url;
    var str = "<br/>" "<a href='" + url + "' target='_blank'>打印输出</a>";
    $("#PrintResult").html(str);
}