Toc control


In this topic


About the Toc control

The Toc (table of contents) control lists the layers on the map and shows what the features represent. A Toc control is buddied with a Map control. As a result, selecting a layer on the Toc control draws it in the Map control. Each resource associated with a Map control can contain one or more layers. The Toc control represents each resource as a group layer, which is a layer that contains layers.
The Toc control inherits from the TreeViewPlus control, which is a Web Application Developer Framework (ADF) control that allows you to display data in a tree-type control with expandable nodes.
The TreeViewPlus control is also used in the TaskResults control. It is possible to programmatically alter the nodes in the Toc control by adding, moving, or deleting nodes. However, the typical use of the Toc control and Web ADF involves client callbacks, rather than full page postbacks; therefore, server-side methods to modify the Toc control cannot be done after startup in the Web browser.

Using the control

  1. Open Visual Studio to add supporting controls to the page. Set up a Web application with, at minimum, a  MapResourceManager control and a Map control. Other controls can optionally be added, such as a Toolbar control for zoom and pan functionality (you can also zoom and pan by using mouse and keyboard combinations) 
  2. Drag the Toc control to add it on the page. See the following screen shot that shows the page in Visual Studio in a table layout:


  3. In design mode, click the Toc control to set the properties. The Properties window appears showing the control's properties. The only property that must be set for the Toc control is the Map property. Click the drop-down arrow for the property's value, then choose the previously added Map control. See the following screen shot:

Modifying content at runtime

By default, if a Toc control is buddied with a Map control, map resources can be used to populate nodes with content that includes layer names, renderer classifications, and legend swatches. 
Nodes in a Toc control are populated during the initial call to PreRender and on any call to the Refresh or RenderLegendHtml methods. The Toc control maintains an OnNodesPopulated event that is triggered after the nodes are populated. Handle the OnNodesPopulated event and modify Toc control content before it is rendered on the client to add, modify, or remove content from the Toc control. Changes made in the handler must be applied each time the nodes are populated, because the structure of the Toc control is regenerated. As a result, explicitly track and manage changes you make to Toc control content.  
The following partial code example shows custom nodes being added to a Toc control using a NodesPopulated event handler:
[C#]
void Toc1_NodesPopulated(object sender, EventArgs e)
{
    TreeViewPlusNode ParentNode = new TreeViewPlusNode("commserver", 
        "Community Incidents");
    TreeViewPlusNode ChildNode1 = new TreeViewPlusNode("incidents", "Crime");
    TreeViewPlusNode ChildNode2 = new TreeViewPlusNode("b&e", 
        "Breaking and Entering");
    TreeViewPlusNode ChildNode3 = new TreeViewPlusNode("trespass", "Trespassing");
    ChildNode1.Nodes.Add(ChildNode2);
    ChildNode1.Nodes.Add(ChildNode3);
    ParentNode.Nodes.Add(ChildNode1);
    Toc1.Nodes.Insert(0, ParentNode);
}
The following screen shot shows a runtime view of the Toc control content generated by the preceding code example:
Toc control properties
You can listen for other events on the Toc control (for example, NodeChecked, NodeClicked, and so on) to manage interaction with the custom content. 

Setting tree headings

When you add resources (map services) to the MapResourceManager control, you can assign a value to the Name property for each resource. The Name value is used in the Toc control as the heading label for the resource (service). Name resources to describe their content or purpose, for example, the name of the map service.

Members

The following table shows a list of properties related to the Toc control. For more reference information, see the Toc control in the library reference section.
Property name
Type
Description
BuddyControl
string
Map control ID to which the Toc will be buddied.
DisabledColor
color
Color to display disabled nodes, such as nodes for layers that are not visible at the current scale.
ExpandDepth
int
Levels of the Toc's tree view to display at startup. For example, to display all layer names and legend swatches at startup, set ExpandDepth to 2. ExpandDepth is not automatically preserved if a full page postback occurs.
PageSize
int
Number of layers to display per page in the TOC. When the number of layers exceeds PageSize, links show at the top of the TOC to display additional TOC pages.
RenderOnDemand
bool
Defers rendering of legend swatches until the layer is expanded to display the swatches. Useful when the TOC contains numerous or complex layers, or when users rarely expand the TOC to view legend swatches.
ShowLayerCheckBoxes
bool
Shows check boxes for each layer, enabling layers to be turned on and off.
ShowResourceCheckBoxes
bool
Shows check boxes at the resource level (map service), enabling users to turn all layers in the service on or off. Useful when multiple services are added to the map.
SwatchPageSize
int
Maximum number of swatches to display per layer before paging in the layer swatches. If the number of categories in the layer exceed this value, only this number displays at a time and links display at the top of the layer legend showing additional groups of swatches for the layer.
TocType
TocType
SwatchList is the default, which includes legend swatches representing layer symbology in the TOC. LayerList is the other option, which only shows layer names without legend swatches.


See Also:

Web ADF controls
Customizing the Web Mapping application




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
  • ESRI.ArcGIS.ADF.Web.UI.WebControls.dll