Print Task Legend

1692
2
07-03-2012 01:59 PM
VIKRANTKRISHNA
New Contributor III
I have a secured map service and I tried to print the map with legend . Everything works except legend is not showing up in the print layer. Below is the code as how I am setting up the print button. Its same as given in one of the sample.

var layouts = [
          {
            "name": "Letter ANSI A Landscape",
            "label": "Landscape (PDF)",
            "format": "pdf",
            "options": {
              "legendLayers": [0,1,2,3], // empty array means no legend
              "scaleBarUnit": "Miles",
              "titleText":$("#title").val()
            }
          }, {
            "name": "Letter ANSI A Portrait",
            "label": "Portrait (Image)",
            "format": "pdf",
            "options":  {
              "legendLayers": [0,1,2,3],
              "scaleBarUnit": "Miles",
              "titleText": $("#title").val()
            }
          }
        ];
       
        // create the print templates, could also use dojo.map
        var templates = [];
        dojo.forEach(layouts, function(lo) {
          var t = new esri.tasks.PrintTemplate();
          t.layout = lo.name;
          t.label = lo.label;
          t.format = lo.format;
          t.layoutOptions = lo.options
          templates.push(t);
        });
      
        app.printer = new esri.dijit.Print({
          map: app.map,
    "templates": templates,
          url: "http://107.21.20.43/webgis/rest/services/GPServices/SecurePrinting/GPServer/Export%20Web%20Map?token..." + response
        }, dojo.byId("print_Button"));
        app.printer.startup();
0 Kudos
2 Replies
JianHuang
Occasional Contributor III
legendLayers should be an array of esri.tasks.LegendLayer, which has the property of "layerId" and "subLayerIds". So the correct way to send legendLayers is:
        var legendLayer = new esri.tasks.LegendLayer();
legendLayer.layerId = "Boundaries";
legendLayer.subLayerIds = [0, 5];
And then, legendLayers: [legendLayer]
0 Kudos
VIKRANTKRISHNA
New Contributor III
That works ....Thanks
0 Kudos