bill_chuang

how to create a legend for GraphicLayer Dynamically with arcgis js api

Discussion created by bill_chuang on Aug 6, 2011
Latest reply on Aug 11, 2011 by hzhu
Hi,
i have a trouble for a few days,I generalize a isosurface by submit a job to a GP Service,when i get the isosurface from the server,I add them to a GraphicLayer,now I want to create a legend for the graphiclayer,but i have no idea,is there anyone help me?
now below is my code partly:
function addIsosurface(outputFeat)
{
var symbol = new esri.symbol.SimpleFillSymbol();
    symbol.setColor(new dojo.Color([150, 150, 150, 0.5]));

    var renderer = new esri.renderer.ClassBreaksRenderer(symbol, "GRIDCODE");
    renderer.addBreak(0, 26, new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([56, 168, 0, 1])));
    renderer.addBreak(26, 28, new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([139, 209, 0, 1])));
    renderer.addBreak(28, 30, new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255, 255, 0, 1])));
    renderer.addBreak(30, Infinity, new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255, 0, 0, 1])));
   
    var features = outputFeat.value.features;
    var isoLayer = new esri.layers.GraphicsLayer();
    dojo.forEach(features,function(feature)
    {
     isoLayer.add(feature);
    })
    isoLayer.setRenderer(renderer);
    map.addLayer(mapLayer);
    dojo.connect(map,'onLayersAddResult',function(results)
    {
     var layerInfo = dojo.map(results, function(layer,index){
         return {layer:layer.layer,title:'temperature'};
       });
       if(layerInfo.length > 0){
         var legendDijit = new esri.dijit.Legend({
            map:map,
            layerInfos:layerInfo
         },"legendDiv");
         legendDijit.startup();
       }
    });
    map.addLayers([isoLayer]);
}

Outcomes