AnsweredAssumed Answered

Legend with esri.tasks.PrintTask

Question asked by michael_porter on Sep 11, 2012
Latest reply on Sep 11, 2012 by JGravois-esristaff
I'm having problems getting the print Task to add a legend consistently.

The code I use is shown below

    function printMap (legendLayers) {
            var printTemplate = new esri.tasks.PrintTemplate();
            printTemplate.format = "JPG";
            printTemplate.layout = "Letter ANSI A Landscape";
            var legendLayer = new esri.tasks.LegendLayer();
// layer with "dynamicLayer" id points to
// and has layers 2,3,4,5 visible in the map
            legendLayer.layerId = "dynamicLayer";
            legendLayer.subLayerIds = [0,1,2,3,4,5];
            var layoutOptions = {TitleText: "Test Map",    scalebarUnit: 'Miles', legendLayers: [legendLayer]};
            printTemplate.layoutOptions = layoutOptions;
            printTemplate.preserveScale = true;
            var printParams = new esri.tasks.PrintParameters();
   = map;
            printParams.outSpatialReference = map.spatialReference;           
            printParams.template = printTemplate;
            var printURL = " Web Map Task";
            var printTask = new esri.tasks.PrintTask(printURL);
            printTask.execute(printParams, function(result) {
       + "?timestamp="+(new Date().getTime()));

Full example is in the attached file.  It is important that the solution supports group layers.

Any help is greatly appreciated.