Select to view content in your preferred language

I want to reorganize the legend structure showing the map layers

624
3
06-10-2012 06:34 PM
EdwardSon
Emerging Contributor
Right now I have the legend conrol bound to the map layers from a map service which show the feature layers in a flat structure.
I want to reorganize this either in xaml or code-behind to reflect a hierarchy.
Is this possible?

I am actually using the map layers returned from a configuration file using the silverlight builder.  So they are defined in the map.xml file.
I can actually group the various layers on the server side so that they are returned as hierarchy and bind that to the legend control.
But the issue is the builder does not allow one to configure the sublayers this way.  Only the top level layer.  I need to be able to add clustering feature to the sublayers.
I realize one can add clustering to map layers programmatically, but it seems that the sublayers don't exist as layers in MapApplication.Current.Map.Layers object.  They exist only as LayerInfos.

So decided to just switch back to the flat structure of layers on the server side, but then reorganize them on the UI side.
I can build my own toc, with a tree structure and bind the map layers any way I like and handle for events, but this is lots of work, including the showing of symbology.
Is there any easier way of using preexisting controls, such as the legend control?
0 Kudos
3 Replies
JoeHershman
MVP Alum
I think I am not fully understanding what your goal is.  The Legend Control has a LayerItemMode property which can be set to Flat of Tree and will show the Legend accordingly.  By setting  each of the templates individually in xaml you can get it to behave and look differently at each level of the tree.  This will reflect the map, though, so if you want to have the Legend in the application show different from how the source map is designed this would not work.  I think to do that you might be forced into making changes to the Legend Control and having your own custom control (what I do but for other reasons).

Hope that helps
-Joe
Thanks,
-Joe
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The best way to organize your layers is to use group layers (sample ) which organize hierarchically the layers and allow to change visiblity and/or opacity by group layer.
The legend control will automaticlaly take care of that layer hierarchy (in tree mode)

If your any reason, the group layer doesn't fit your requirement you might as well modify the hierarchy of legend items by wiring up an handler to legend event LegendRefreshed (but doing that you won't be able to manage the visibility and/or the opacity by node of the legend).
0 Kudos
EdwardSon
Emerging Contributor
Ok, I will try to explain my situation more clearly.  I was in a hurry yesterday... 🙂
I am working with the Sivlerlight Builder to generate my map contents and as a framework, and modifying builit in controls as needed.
One of them is the Map Contents (or toc) control.

When I define the map service to have group layers and the feature layers organized accordingly underneath them, and I browse to this service to build my map using the builder, then I get a map structure which when I bind to the legend control I get the hierarchy I want.  But I lose the clustering for the point feature layers.  This is because the builder doesn't seem to let me configure the feature layers that are organized under group layers to have clustering.  I only have access to these feature layers from the builder to enable clusterring for them if I do not put them under the group layers.

So I seem to have two options: one is to return a flat structure from the map service and try to reorganize them on the client side (the legend control) to have hierarchy, or return the hiearchy with groups from the map service and enable clustering on the client side for the feature layers of interest.  But I noticed that, in the latter case, the MapApplication.Current.Map.Layers structure has the topographic layer and the ArcGISDynamicMapServiceLayer and all of the map/feature layers beneath it as "LayerInfo" object and not "Layer".  So I don't have access to the Clusterer object.  (Btw, is there a third option where I can reorganize the MapApplication.Current.Map.Layers data object itself in the code before binding the Map to the legend control, i.e. add in group layers at this point?)

I hope my request made sense.  Btw, I am sort of new to this Silverlight API so I am trying rapidly learning things as going.

Thanks.
0 Kudos