Javascript API table of contents?

5273
9
Jump to solution
02-18-2015 12:48 PM
DanielSchatt
New Contributor III

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

0 Kudos
1 Solution

Accepted Solutions
9 Replies
TimWitt2
MVP Alum
ChrisSergent
Regular Contributor III

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

by Anonymous User
Not applicable

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.

ChrisSergent
Regular Contributor III

I hope so. I added that idea to ArcGIS ideas here: https://c.na9.visual.force.com/apex/ideaView?id=087E00000005IN2IAM

0 Kudos
by Anonymous User
Not applicable

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?

0 Kudos
ChrisSergent
Regular Contributor III

I created a poll to @Kevin here: I think we should wear shirts that display that when we go to conferences.

0 Kudos
by Anonymous User
Not applicable

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.

0 Kudos
KenBuja
MVP Esteemed Contributor

The Javascript team has had a long antipathy towards TOCs, unfortunately.

0 Kudos
DanielSchatt
New Contributor III

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. 

0 Kudos