The table of contents, or Toc, control lists the layers on the map and shows
what the features represent. A toc is buddied with a map control.
As a result, checking a layer on in the toc control will draw it in the map
control. Each resource associated with a map control may 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 ADF
control that allows you to display data in a tree-type control with expandable
nodes. TreeViewPlus is also used in the TaskResults control. It is possible to
programmatically alter the nodes in the Toc by adding, moving or deleting
nodes. However, keep in mind that the typical use of the Toc and Web
ADF involves client callbacks rather than full page postbacks, so that
server-side methods to modify the Toc cannot ordinarily be done after startup
in the browser.
Using the Toc control
Add supporting controls to the page
In order to use the control, a number of supporting controls must be
available. Set up a Web application with, at minimum, a
MapResourceManager control and a Map
control using their discussion topics as a guide. Other controls may optionally
be added, such as a Toolbar control for
zoom/pan controls (users can also zoom/pan using mouse/keyboard combinations).
Add the Toc control to the page
Drag a Toc control onto the page. Your page should resemble the following (this
layout is using a table, so your arrangement may differ):
Set the properties for the Toc control
In design mode, click on the Toc control to select it. The Properties window
displays the properties for the control:
The only property that you must set for the Toc control is the Map
property. Click the drop-down list for its value and choose the Map control
The following table provides a list of properties of
interest. For complete reference information, see the Toc control in the
library reference section.
||The Map control ID to which the Toc will be buddied to.
||Color to display disabled nodes, such as nodes for layers that are not visible
at the current scale.
||Levels of the Toc's tree view to display on startup. For example, to display
all layer names and legend swatches on startup, set ExpandDepth to 2.
ExpandDepth is not automatically preserved if a full page postback occurs.
||Number of layers to display per page of the Toc. When the number of layers
exceeds PageSize, links are displayed at the top of the Toc to
display additional Toc pages.
||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.
||Displays checkboxes for each layer, enabling the user to turn layers on and
||Displays a checkbox at the level of the resource (map service), enabling users
to turn all layers in the service on or off. Useful when multiple services are
added to the map.
||Maximum number of swatches to display per layer before using paging within the
layer swatches. If the number of categories within the layer exceed this value,
only this number are displayed at a time, and links are displayed at the
top of the layer legend to display additional groups of swatches for the layer.
||The default is SwatchList, which includes legend swatches, which represent
layer symbology, in the Toc. The other option is LayerList, which displays
only layer names, without legend swatches.
Modifying Toc content at runtime
By default, if a Toc is buddied with a Map, map resources can be used
to populate nodes with content that includes layer
names, renderer classifications, and legend swatches. Nodes
within a Toc are populated during the initial call to PreRender, and
on any call to the Refresh or RenderLegendHtml
methods. The Toc maintains an OnNodesPopulated event which is
triggered after the nodes are populated. You can handle this event
and modify Toc content before it is rendered on the
client. This enables you to add, modify or remove content from the
Toc. Changes made in the handler must be applied each
time the nodes are populated because the structure of the Toc is
regenerated. As a result, you need to explicitly track and
manage changes you make to Toc content. The
following code provides a brief example of custom nodes being added to a
Toc using a NodesPopulated event handler.
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");
You can listen for other events on the Toc control (e.g. NodeChecked,
NodeClicked, etc.) to manage interaction with the custom content.
Setting Toc 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). You
should give resources names that describe their content or purpose, such as the
name of the map service.