Solved! Go to Solution.
This happens when you try to create multiple widgets with the same id. Are you trying to create a new legend without first destroying a previous one you created?
//Add the Legend
legendLayers.push({
layer: layer,
title: ''
});
dojo.connect(map, 'onLayersAddResult', function (results) {
var legend = new esri.dijit.Legend({
map: map,
layerInfos: legendLayers
}, "legendDiv");
legend.startup();
});
map.addLayers([layer]);
if (layer.loaded) {
buildLayerList(layer);
} else {
dojo.connect(layer, "onLoad", buildLayerList);
}<div dojoType="dijit.TitlePane" title="Legend" closable="false" open="false" style="float:right;"> <div dojoType="dijit.layout.ContentPane" style="width:180px; overflow:auto;"> <span id="legendDiv"></span> </div> </div>
How many times is onLayersAddResult firing?
Can you post a full repro case? We'll be able to get to the bottom of this faster if you post code that reproduces the error.