GenerateRendererTask results and the Legend digit

Discussion created by myESRIUName on Sep 21, 2012
Latest reply on Oct 10, 2012 by myESRIUName
Hello all,

Within my application, the legend digit does not appear to accommodate a renderer definition applied to a layer dynamically during a refresh. I'm hoping someone can provide some pointers as to what I might be missing because I've been trying to get this all working for days and am stuck with what to try next.

I have an ArcGISDynamicMapServiceLayer that has no visible layers at startup but contains 7 different ones in total. The end user is able to indicate which layer in the service they wish to work with, pick an attribute from that layer, specify how they would like the layer displayed (e.g., with a ClassBreaksDefinition), the number of classes and the colours to ramp between in displaying the data. All this is very similar to the "Change the Attribute Field Used to Render Data" sample found at:

The sample has one layer within the mapping service and when it calls the show() on the layer, the legend gets updated.

In my application, I set the layer drawing options for the layer in question, set that layer visible and the legend gets updated...incorrectly. In my case, it adds the layer to the legend but uses the default unclassified renderer definition in the mapping service itself. That is, all the polygons in the layers are just solid blue areas in the mapping service (because they are all turned off anyway) so, although the map appears with the requested classification scheme, the legend appears with a solid blue square. I have included a picture to show the result. The map's classification is all in yellows and greens, but the Legend is showing them as solid pale blue.


My code to apply the GenerateRendererTask's results is as follows:
        cbExecuteGenerateRendererTask: function(renderer){
            var optionsArray = [];
            var drawingOptions = new esri.layers.LayerDrawingOptions();
            drawingOptions.renderer = renderer;
            optionsArray[selectedlayerId] = drawingOptions;

I thought perhaps there was a timing issue in that the legend digit was updating itself before the renderer had finished getting applied, but I introduced an "onUpdateEnd" event handler where I do a legend.refresh(), but it doesn't make any difference. The legend stays a solid blue area when the legend.refresh() is called even after the map has completed updating its display.

In case I'm just doing that part wrong, here is my code for that too:
                ,function() {
                    if (app.legend != null){

Could someone who is more familiar with the actual code in the Legend digit provide some indication what I might be missing that is causing it to ignore the renderer definition being used? I've downloaded it and had a look but nothing jumps out at me, not being familiar with it at all.