Select to view content in your preferred language

Error: Tried to register widget with id==legendDiv but that id is already registered

4363
8
Jump to solution
12-03-2012 05:35 AM
CraigMcDade
Deactivated User
I'm getting:

Error: Tried to register widget with id==legendDiv but that id is already registered

when loading my map. I've searched around and it seems to be an issue with a few other widgets as well. Can anybody recommend a good work around?
0 Kudos
1 Solution

Accepted Solutions
JeffPace
MVP Alum
you are calling addLayers twice.  Remember this is all asynchronous. 

You call add layers, then define a legend in the callback.  Likely after the legend is defined, the event actually occurs, triggering it.

You then call addLayers again, which triggers the callback again, which tries to create a second legend.

View solution in original post

0 Kudos
8 Replies
derekswingley1
Deactivated User
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?
0 Kudos
CraigMcDade
Deactivated User
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?


No. My only instances for legend is once in the JS:

//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 once in the HTML:
<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>
0 Kudos
JeffPace
MVP Alum
although i might be reading it wrong, it looks like you are CREATING a legend on each layer add.  So it would work the first time, but on the second layer it is trying to create a second legend.
0 Kudos
derekswingley1
Deactivated User
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.
0 Kudos
CraigMcDade
Deactivated User
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.


This link should work in IE9. As always, I appreciate your help.
0 Kudos
JeffPace
MVP Alum
you are calling addLayers twice.  Remember this is all asynchronous. 

You call add layers, then define a legend in the callback.  Likely after the legend is defined, the event actually occurs, triggering it.

You then call addLayers again, which triggers the callback again, which tries to create a second legend.
0 Kudos
CraigMcDade
Deactivated User
Thanks Jeff. Totally overlooked that. This answer actually solves my basemap gallery issue as well.

I appreciate the help.
0 Kudos
JeffPace
MVP Alum
glad to help!
0 Kudos