sniklasch

Print Widget legend problem

Discussion created by sniklasch on Jun 28, 2013
Latest reply on Feb 5, 2015 by fcbassongis
I have a problem with the legend in in the print widget:

I have a map with a DynamicMapServiceLayer, which has several different Layers(mapServer is a variable for the url of the service):
operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapServer, { "id": "collection" });


I can change the Rendering with for example this function (operationalLayer is the DynamicMapServiceLayer):
function addEqualBreaks(number, colorStart, colorEnd) {
    equalBreaksOptions[0] = number; //number of breaks
    equalBreaksOptions[1] = colorStart;
    equalBreaksOptions[2] = colorEnd;
    activeClassification = 2; // 2 = automatic

    //maximum of 12 classes:
 if (number > 11){
  number = 11;
  document.getElementById("equalBreaksText").value = 12;
 }
    //get the min/max-Values of the active Layer from an Array:
    var breakStep = (maxValues[activeLayer] - minValues[activeLayer]) / (number + 1); //size of one class
    var colorArray = generateColor(colorStart, colorEnd, number); //generates an array of an color gradient

    symbol = new esri.symbol.SimpleFillSymbol();
    symbol.setColor(new dojo.Color([150, 150, 150, 0.75]));
    var renderer = new esri.renderer.ClassBreaksRenderer(symbol, attributeFields[activeLayer] + currentYear);
    
    for (var i = 0; i <= number; i++) {
        var min = minValues[activeLayer] + i * breakStep;
        var max = minValues[activeLayer] + (i + 1) * breakStep;
        renderer.addBreak({
            minValue: min,
            maxValue: max,
            symbol: new esri.symbol.SimpleFillSymbol().setColor(dojo.colorFromHex('#' + colorArray[i])),
            label: min + " - " + max
        });
    }

    //delete the entrys of the manual classification:
 var breaksList = document.getElementById("Breaks");
 breaksList.innerHTML = '';
 breakCount = 0;
    
    //following from the ArcGIS Server JS-API:
    var optionsArray = [];
    var drawingOptions = new esri.layers.LayerDrawingOptions();
    drawingOptions.renderer = renderer;
    optionsArray[activeLayer] = drawingOptions;
    operationalLayer.setLayerDrawingOptions(optionsArray);

    legend.refresh();
}

When I do this, the Legend of the Webmap shows the right colors for the Breaks, but if I use the Print widget, the legend of the printed map shows the default breaks and colors of the MapService(but the map is printed right).
You can see my implemetation of the print-widget here:
function exportMap(){
    exportTitle = document.getElementById("mapExportTitle").value; //a text-field to enter a title
    exportAuthor = document.getElementById("mapExportAuthor").value; //a text-field to enter an author
    var legendLayer = new esri.tasks.LegendLayer();
    legendLayer.layerId = "collection"; // "collection" is the id of the operationalLayer
    
    //printer
    if(printer != undefined){
     printer.destroy();
    }
    printer = new esri.dijit.Print({
          map: map,
          templates: [{
                label: "PNG Hochformat",
                format: "PNG32",
                layout: "A4 Portrait",
                layoutOptions: {
                  titleText: exportTitle,
                  authorText: exportAuthor,
                  scalebarUnit: 'Kilometer',
                  legendLayers: [legendLayer]
                }
              },{
                label: "PNG Querformat",
                format: "PNG32",
                layout: "A4 Landscape",
                layoutOptions: {
                  titleText: exportTitle,
                  authorText: exportAuthor,
                  scalebarUnit: 'Kilometer',
                  legendLayers: [legendLayer]
                }
              }],
         url: "http://.../arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task/"
         }, dojo.byId("printButton"));
    document.getElementById("exportWarning").innerHTML = "Achtung: Das exportieren der Karte kann einige Sekunden in Anspruch nehmen.";
    printer.startup();
    
    dojo.connect(printer,'onPrintStart',function(){
     console.log('The print operation has started');
     document.getElementById("loadingImage").style.visibility = "visible";
    });
    
    dojo.connect(printer,'onPrintComplete',function(value){
     console.log('The url to the print image is : ' + value.url);
     document.getElementById("loadingImage").style.visibility = "hidden";
    });
}


What can I do that the print-legend gets right?

you can see the whole project online at webgis-westfalen.de

Outcomes