Sublayer legend Symbology question

1406
4
04-26-2011 11:53 AM
by Anonymous User
Not applicable
Original User: angelg

I have SL app with legends. When the app first load the legend with templates loads showing the three main layers (Legend1.png). When I click to expand one of these layers to show the sublayers, the sublayers and their symbology gets displayed (Legend2.png).  Is their a way to prevent the symbology displaying (Legend3.png) until the user actually expand the sublayer they want to see.

If you have many sublayers and many symbology within these sublayers it can frustrate the user since he/she need to close all of the sublayers, whose symbology they do not want to see.
0 Kudos
4 Replies
by Anonymous User
Not applicable
Original User: dbroux

The LegendItemViewModel class has a property 'IsExpanded' that can be set by code (default value is true).

The legendwittemplates sample is setting to false the first level of legend items but we could do it for the next level as well.

 
            if (e.LayerItem.LayerItems != null)
            {
                foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems)
                {
                    if (layerItemVM.IsExpanded)
                        layerItemVM.IsExpanded = false;
                   if (layerItemVM.LayerItems != null)
                      foreach(var item in layerItemVM.LayerItems)
                         item.IsExpanded = false;
                    if (layerItemVM.Label == "states")
                        removeLayerItemVM = layerItemVM;
                }
 
0 Kudos
AngelGonzalez
Occasional Contributor II
Worked!

Thanks
0 Kudos
by Anonymous User
Not applicable
Original User: gpapamih

How did you get the toggle switches for the layers inside the main one? I downloaded a configurable app and just has a selection box where I can only select one class at a time.
0 Kudos
AngelGonzalez
Occasional Contributor II
Basically I used  ESRI Toolkit Control sample "Legend with Templates"

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LegendWithTemplates

Copy and paste the code, update mapservice with your mapservice and update the LayerID with your layer ID name. Add the code Dominique suggested above if you want and run the app.


Attached is a shot of how my mxd/msd if configured.
0 Kudos