Duplicate layers in TOC widget

1622
13
Jump to solution
03-21-2014 09:12 AM
CM2
by
New Contributor II
Hey folks,

I'm having an issue where layers I'm using in Nliu's TOC are showing up double in the TOC.

Check out my code on JSFiddle here: http://jsfiddle.net/749QG/1/

Weird! I'm not sure why it's doing that - does so no matter what service I use.

Thanks for any suggestions,

Craig
0 Kudos
13 Replies
KenBuja
MVP Esteemed Contributor
That Fiddle show a new error. However, if you switch back to 3.8, that error goes away.
0 Kudos
MayJeff
Occasional Contributor
I realized that too.  Only with version 3.9 got errors.  Not sure why.  Thank you.
0 Kudos
KenBuja
MVP Esteemed Contributor
You may want to start a separate thread to get the attention of the API developers.
0 Kudos
NianweiLiu
Occasional Contributor II
That Fiddle show a new error. However, if you switch back to 3.8, that error goes away.

The problem for the code is around the event used to trigger the creation of the digit. The code used 'layer-add-result', which is an event that fired multiple times, thus the developer was actually trying to create many instances of TOC and would running into problems. Even developer code just called 'addLayer' once, the basemap add by API itself would trigger that event internally too.
Having something like "if (toc==null ) toc=new ..." might help, although it is really about make sure knowing when the code will be called.
Why 3.8 worked could be just how DOJO internally check div changed, may not even an ESRI thing.
0 Kudos