hi all, newbie here trying to familiarize myself with the Javascript API. I have a dynamic map service with 20 layers or so and I'd like the user to be able to toggle each layer on or off and also show the symbology for each layer, just like the TOC that one would see in Desktop. The Silverlight API had a sample for this ("Legend with Templates") and I assume Flex did as well. But I can't find any such sample on the Javascript API page. Do I really need to try to code this myself or get it from a third party? Hard to believe -- It seems like this is very basic functionality for a GIS tool... or did I miss something? Thanks!
Dan
Solved! Go to Solution.
This should be what you are looking for. http://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109
This should be what you are looking for. http://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109
I had some trouble with the one that Tim Witt referenced, but a lot of other people seem to be doing okay with the widget. If you have trouble with it you can also try out Rene Rubalcava who wrote a post on how to make a TOC - How to make a ToC
There is another interesting TOC 'cbtree' here:
http://thejekels.com/cbtree/demos/ArcGIS.php
ArcGIS Layers · pjekel/cbtree Wiki · GitHub
Dojo Dijit Tree with Checkboxes
I am wondering when or if ESRI plans to officially incorporate a TOC in the API.
I hope so. I added that idea to ArcGIS ideas here: https://c.na9.visual.force.com/apex/ideaView?id=087E00000005IN2IAM
Ah yes. They have resisted for six or seven years for philosophical reasons. There are threads requesting one in the API on forums.esri.com even. Perhaps we should start a poll. Would everyone like to see an official TOC? Like if they officially adopted AGS TOC for example?
I should also point out this TOC can do some things AGS can not. However, I have not used it, I have only used AGS TOC. Which works great. FYI, you can create multiple TOCs, and for example put one in each pane of an Accordion, or one per jQuery dialog window, for example.
The Javascript team has had a long antipathy towards TOCs, unfortunately.
Thanks for the suggestions, working on them and I expect it will take some time. I have to say that I'm totally mystified by this perspective some seem to have that TOCs with toggled layers are outdated or not good practice. If I have multiple (i.e. perhaps 20 or more) overlapping layers that I want to make available on one map, how else am I supposed to do that? I don't even understand why there's any antipathy at all. I think they're very intuitive and easy for the lay user.