elove

Dynamic Legend Not Working

Discussion created by elove on Dec 2, 2011
Latest reply on Dec 2, 2011 by DSwingley-esristaff
Hello,
I am very new to javascript and am having trouble with the dynamic legend in my web map. In the content pane on the right it says "No Legend". Any help would be greatly appreciated!!

map = new esri.Map("map",{ nav:true, extent:intExtent, lods: lods});
   var legendLayers = []; 
        //Add the topographic layer to the map. View the ArcGIS Online site for services http://arcgisonline/home/search.html?t=content&f=typekeywords:service     
        var basemapUrl = "http://slcarcgisdev1/SLCOGIS/rest/services/public/Base_Map/MapServer"; 
        var basemap = new esri.layers.ArcGISDynamicMapServiceLayer(basemapUrl); 
         map.addLayer(basemap); 
  
  var layer = "http://slcarcgisdev1/SLCOGIS/rest/services/public/Surveyor/MapServer"; 
        
  
  
  //dynamicMap = new esri.layers.ArcGISDynamicMapServiceLayer(layer);
   esri.config.defaults.geometryService = new esri.tasks.GeometryService
   ("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); 
   
   
   var pointsLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://slcarcgisdev1/SLCOGIS/rest/services/public/Surveyor/MapServer",{id:'Control Points'});
  map.addLayer(pointsLayer);
  
  dojo.connect(map,'onLayersAddResult',function(results){
         //add the legend
          var legend = new esri.dijit.Legend({
            map:map,
            layerInfos:[{layer:layer,title:"Legend"}],
            arrangement:esri.dijit.Legend.ALIGN_RIGHT
          },"legendDiv");
          legend.startup();
        });
  map.addLayers([pointsLayer]);
  
  //add check boxes  
        dojo.forEach(legendLayers,function(layer){          
         var layerName = layer.title; 
         var checkBox = new dijit.form.CheckBox({ 
            name: "checkBox" + layer.layer.id, 
            value: layer.layer.id, 
            checked: layer.layer.visible, 
            onChange: function(evt) { 
              var clayer = map.getLayer(this.value); 
              if (clayer.visible) { 
                clayer.hide(); 
              } else { 
                clayer.show(); 
              } 
              this.checked = clayer.visible; 
            } 
          }); 
 
          //add the check box and label to the toc 
          dojo.place(checkBox.domNode,dojo.byId("toggle"),"after"); 
          var checkLabel = dojo.create('label',{'for':checkBox.name, innerHTML:layerName},checkBox.domNode,"after"); 
           dojo.place("<br />",checkLabel,"after"); 
        }); 
      

Outcomes