Select to view content in your preferred language

Legend Only Loads on Zoom

919
2
07-19-2011 05:23 AM
DuncanRager
Deactivated User
Greetings,

I have the following code to start my legend:

function addLegend(){
  dojo.connect(map,'onLayerAdd', function(results){
   var legend = new esri.dijit.Legend({
    map:map,
    layerInfos:legendLayers
   },"legendDiv");
   legend.startup();
  });
 }


When I first load my web app, the legend reads, "No Legend", even though I've successfully added layers to my map. Oddly enough, when I mouse wheel to zoom in or out, the legend loads properly.

Similarly, when I use the checkboxes I have to turn other layers on an off, nothing changes in the legend... but when I zoom in or out the legend properly updates.

Could anybody explain this behavior?

Thanks,

DR
0 Kudos
2 Replies
StephenLead
Honored Contributor
Weird, I just noticed that I'm seeing the same behaviour on one of my maps. In my case I'm starting the legend in the onLayersAddResult (plural) event:

    dojo.connect(map, 'onLayersAddResult', function (results) {
        var legend = new esri.dijit.Legend({
            map: map,
            layerInfos: legendLayers
        }, "legendDiv");
        legend.startup();


Edit:

- Firebug shows that legend.layerInfos[0].layer.visible = true for each layer immediately after legend.startup is run.
- respectCurrentMapScale
is true, but there are no scale dependencies in the layers, and they display on the map.
- Omitting the layerInfos declaration doesn't change the behaviour

Edit2:

The sample at http://help.arcgis.com/en/webapi/javascript/arcgis/demos/widget/widget_legendvisible.html works. I based my map on this sample!

Interested to see what you find...

Steve
0 Kudos
LindseyKnapp
Deactivated User
I too have been having this problem. It is only occuring when it is loaded in the same building that the server is located in. Weird. I have no problems when testing from home and the tech from our other branch said there were no legend loading problems from his location. Try testing from home
and see what happens.
0 Kudos