Getting the following error when running my app:
Error: Tried to register widget with id==legendDiv but that id is already registered
Not sure how to get rid of it. My javascript for the legend is:
//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);
}
and my HTML is:
<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>
Can anybody suggest a workaround or a fix to the error. I've done some searching and it looks like I might need to do a destroy? Not sure how to do that.