HOW TO
By default, when a Table of Contents (TOC) or tree TOC is registered with a map, any layer added to the map is also added as a Legend or LegendNode to the TOC or tree TOC, respectively. A layer's legend to enable/disable visibility, select the layer, view the classification scheme, etc. can be manipulated by the user.It may be necessary to disable the ability to change visibility of the layer, or remove the layer from the TOC or tree TOC completely. In most cases, this involves more than a simple method call. In addition, a TOC and tree TOC require different techniques to accomplish this task.
Code:
MyTreeToc1.removeLegendNode(MyTreeToc1.findLegendNode(layer));
Code:
public class MyTreeToc extends com.esri.mo2.ui.toc.TreeToc{
public com.esri.mo2.ui.toc.LegendNode createLegendNode(com.esri.mo2.map.dpy.Layer layer){
if (layer.getName().equalsIgnoreCase("layername")) {
MyCustomFeatureLegendNode flayernode = new MyCustomFeatureLegendNode(this, (FeatureLayer) layer);
return flayernode;
} else {
return super.createLegendNode(layer);
}
}
}
public class MyCustomFeatureLegendNode extends FeatureLegendNode{
public MyCustomFeatureLegendNode(TreeToc toc, FeatureLayer flayer){
super(toc, flayer);
}
public void setChecked(boolean tf){
// Do nothing, checkbox cannot be changed
}
}
Code:
public class MyToc extends Toc {
public Legend createLegend(com.esri.mo2.map.dpy.Layer layer) {
if (layer.getName().equalsIgnoreCase("layername")) {
// To remove a layer from the TOC, but not the map:
return null;
// To see the layer in the map and TOC, but disable the ability to change layer visibility:
Legend legend = super.createLegend(layer);
JComponent jc = legend.getCheckBox();
java.awt.event.MouseListener[] mlist = jc.getMouseListeners();
jc.removeMouseListener(mlist[0]);
return legend;
} else {
return super.createLegend(layer);
}
}
}
Article ID:000008016
Get help from ArcGIS experts
Download the Esri Support App