Why is my legend not showing up?

637
1
01-23-2012 10:51 AM
GarethMann
New Contributor III
I have added some code to my page to display a legend in a div element. I have placed the div element on the page but for some reason the legend is not showing up. There appears to be no error message in the Javascript tools (Google Chrome browser). The code for the legend is simply a copy-paste from the samples:

//add the legend
        dojo.connect(map,'onLayersAddResult',function(results){
         //add the legend 
          var legend = new esri.dijit.Legend({
            map:map,
            layerInfos:[{layer:dynamicLayer,title:"Legend"}],
            arrangement:esri.dijit.Legend.ALIGN_RIGHT
          },"legendDiv");
          legend.startup();
        });


Here is the page itself:
http://northmiamicra.org/PWorksLayoutdynamic.html
0 Kudos
1 Reply
KellyHutchins
Esri Frequent Contributor
In your application you are adding the legend when the map's onLayersAddResult event is fired. This event only happens if layers are added to the map using map.addLayers(). In your code you are using map.addLayer. If you modify the line that adds the layer to read as follows your legend will appear.

        map.addLayers([dynamicLayer]);
0 Kudos