Select to view content in your preferred language

Legend - Hiding layers in the treeview

4539
10
12-09-2010 06:36 AM
AndrewWhite
Emerging Contributor
I would like to hide specific layers in the Legend but still have them show up on the map.  I'm not talking about MapService layers which are easy to hide by not including them in the Legend.LayerIds property. 

Specifically, we've got annotation sublayers that we need on the Map but are just noise on the Legend.

Within the LayerTemplate I've got a StackPanel that I'm Collapsing if it's an annotation sublayer.  However, that just leaves an empty node in the Legend TreeView.  I'm guessing I need to Collapse the TreeViewItem itself, but I can't figure out how to access it.
0 Kudos
10 Replies
DominiqueBroux
Esri Frequent Contributor
You have to hook up an handler to the legend Refreshed event and in this handler you can add/remove/change any items in the legend tree (from a layerItem, you can get the LayerItems children and so on if it's a group layer)
0 Kudos
AndrewWhite
Emerging Contributor
You have to hook up an handler to the legend Refreshed event and in this handler you can add/remove/change any items in the legend tree (from a layerItem, you can get the LayerItems children and so on if it's a group layer)


Wow, that seems really hacky to me.  Seems like I should have the ability to use a DataConverter to evaluate the LayerItemViewModel and set the visibility of the treeview nodes.  Just my 2c.
0 Kudos
LakshmananVenkatesan
Frequent Contributor
Hello:

I want to hide some layers in legend control in my dynamic map service layer. Application has one dynamic map service layer and feature layer. Dynamic service layer has 10 layers. I want to hide some specific layers in legend control which is from dynmaic map service . How do I go about.?


I use latest SL 2.1 version and legend control. Pl help
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You can remove legend items in legendrefreshed event handler.

There is a sample in the InteractiveSDK.

The code looks like:
 
if (removeLayerItemVM != null)
  e.LayerItem.LayerItems.Remove(removeLayerItemVM);
0 Kudos
LakshmananVenkatesan
Frequent Contributor
Hi

When I use e.LayerItem.LayerItems.Remove(removeLayerItemVM), am changing collection at runtime and getting an error. am doing in Legend_Refreshed event as given in sample Legend with Templates.

Please help me
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I can't guess where the issue is with so few infos.
What is your event handler code?  Which error are you getting?
0 Kudos
LakshmananVenkatesan
Frequent Contributor
Hi

I have sucessfully removed layers. Now, I have to change the group name to Alais name. In Legend am setting LayerID to my dynamic service layer. I want to change to alias name. How do I do that?.


<esri:ArcGISDynamicMapServiceLayer ID="mapLayer" InitializationFailed="FeatureLayer_InitializationFailed"
Url="http://xxxxx/ArcGIS/rest/services/Test/MapServer"

<legend:Legend Map="{Binding ElementName=mapControl}"   
                         LayerIDs= "mapLayer"
                         LayerItemsMode="Tree"
                         ShowOnlyVisibleLayers="False"
                                    x:Name="legendTOC"
                         Refreshed="Legend_Refreshed">

In my legend, group node label appear as "mapLayer" which I need to change. Howto go about?


Is that possible to remove the group layer node and only display the layers without group name?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
On event 'Refreshed', you can also change or reorganize any legend item (as you did for removing).

A LegendItemViewModel has 3 main properties that you can change:
     - Label (that you can change to your alias)
     - ImageSource
     - Description (used in tooltip)

Concerning the removal of the group layer node, the legend control has 2 built-ins mode : "Tree" and "Flat".
With the flat mode (LayerItemsMode="Flat"), the group layers are not shown, so it might be what you need.

For other specific cases, you need either to template the control or to change the layer tree by code in event 'Refreshed'.
0 Kudos
LakshmananVenkatesan
Frequent Contributor
OK. My map control has two layers 1)Dyanmic service layer and other is Featurelayer

In legend, I want to change the Feature Layer name to Alais name. How do I go about ?. In refereshed event, am seeing all dynamic service layers in e.LayerItem.LayerItems not the feature layer?. When do a quick watch am not seeing any information related to featurelayer.

Regards
SR
0 Kudos