Duplicate layers in TOC widget

526
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
Reply
0 Kudos
13 Replies
KenBuja
MVP Honored Contributor
That Fiddle show a new error. However, if you switch back to 3.8, that error goes away.
Reply
0 Kudos
MayJeff
Occasional Contributor
I realized that too.  Only with version 3.9 got errors.  Not sure why.  Thank you.
Reply
0 Kudos
KenBuja
MVP Honored Contributor
You may want to start a separate thread to get the attention of the API developers.
Reply
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.
Reply
0 Kudos