Legend widget not loading all layers on inital load

1589
5
Jump to solution
03-07-2017 06:02 AM
JayHill
Occasional Contributor II

When using the legend widget (esri JAPI 3.20), not all the layers show up when my map loads. I have to zoom a level first then they all show up. Any fixes?

0 Kudos
1 Solution

Accepted Solutions
JayHill
Occasional Contributor II

got it to work by adding refresh.

var legend = new Legend({
map: map,
layerInfos: layers

}, "legendDiv");
map.on ("layer-add-result", function(){
legend.refresh();
legend.startup();

})

View solution in original post

0 Kudos
5 Replies
thejuskambi
Occasional Contributor III

Can you share your code, how you have initialize the Legend widget.

0 Kudos
JayHill
Occasional Contributor II

var legend = new Legend({
            map: map,
            layerInfos: layers,
            
        }, "legendDiv");
    
        legend.startup();

I think problem lies in my array of featurelayers being used for layerlist. I tried the legend.refresh() code but it didn't help

0 Kudos
KenBuja
MVP Esteemed Contributor

Wait until the map loads all your layers before adding the legend

map.on("layers-add-result", function () {
  var legend = new Legend({
    map: map,
    layerInfos: layers
  }, "legendDiv");
  legend.startup()
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍
JayHill
Occasional Contributor II

Ken

I don't get a legend showing in the div now.

0 Kudos
JayHill
Occasional Contributor II

got it to work by adding refresh.

var legend = new Legend({
map: map,
layerInfos: layers

}, "legendDiv");
map.on ("layer-add-result", function(){
legend.refresh();
legend.startup();

})

0 Kudos