populating sublayers on a listbox along with the symbols

1644
23
02-09-2011 05:02 AM
SangamLama
New Contributor
Hi all,
I'm following this tutorial to display and populate sublayers out of a dynamic map layer.
http://resources.esri.com/help/9.3/arcgisserver/apis/silverlight/samples/start.htm#SubLayerList

I figured it'd be cool to display the symbols representing those sublayers on the listbox, including the color fills symbols, line symbols etc. I was wondering how I could populate them?

The only time I've ever accessed low level details tied to every sublayer was when I carried out an IdentifyTask on certain coordinates (on the map). Then I used IdentifyResult to access the feature attributes. Would you say carrying out similar IdentifyTask is the only way? But again, the listbox is generated on application load, so I dont know how that's going to be possible..

Thanks for the ideas 🙂
0 Kudos
23 Replies
SangamLama
New Contributor
FINALLY, the problem's fixed. I tried both the approach, SOAP API and an upgrade to SP1. Both worked. But we decided to stick to the latter.

Many thanks to you for sticking with this thread and answering all my questions. You guys do a wonderful job at assisting people in this forum. Keep it up 🙂

Correct.
The legend fallback mechanism that is used by the legend control for services prior to 10SP1 is a service hosted by arcgis.com, so your service has to be accessible from arcgis.com ==> need to be public.


The legend is still available by the SOAP API. If you are interested, there is a sample of a legend service using the SOAP API here : http://www.arcgis.com/home/item.html?id=c896e06026444819afcf47d11a1be730
0 Kudos
BlueRace
New Contributor II
Hi
I�??m hoping this thread is still open.
I am looking to do something similar to what has been discussed here but my twist is instead of having the layers hard coded in the XAML I�??m looking to (1) have users enter the URL like here #AddLayerDynamically   then  (2)the Sublayers (including any hierarchy) would be listed with checkboxs like here #SubLayerList.

This probably means most of the code will be done in codebehind c# then bound to respective elements in the XAML

I�??m very new to Silverlight. I�??ve been trying to do this for ages but no joy. Any help would be very much appreciated.







Sorry I forgot to mention that if you have a hierarchy of group layers, you have also to adapt the C# code to take into account this hierarchy.

Here is the code which should work whatever the number of group levels:
void Legend_Refreshed(object sender, ESRI.ArcGIS.Client.Toolkit.Legend.RefreshedEventArgs e)
{
    SetLayerItemImageSource(e.LayerItem);
} 

private void SetLayerItemImageSource(LayerItemViewModel layerItem)
{
    if (layerItem.LegendItems != null && layerItem.LegendItems.Any()) // if there is a legend item
        layerItem.ImageSource = layerItem.LegendItems.First().ImageSource; // set the image of the sublayer with the image of the first legenditem
 
    // Call recursively SetLayerItemImageSource
    if (layerItem.LayerItems != null)
    {
        foreach(var sublayerItem in layerItem.LayerItems)
            SetLayerItemImageSource(sublayerItem);
    }
}
Note that instead of using your own listbox and a binding to a legend control, you can also retemplate the legend control to use a listbox.

For example with this template:
<esri:Legend Map="{Binding ElementName=MyMap}" LayerItemsMode="Flat" ShowOnlyVisibleLayers="False" LayerIDs="California" Refreshed="Legend_Refreshed">
<esri:Legend.Template>
 <ControlTemplate TargetType="esri:Legend">
  <ListBox ItemsSource="{TemplateBinding LayerItemsSource}" >
   <ListBox.ItemTemplate>
    <DataTemplate>
     <StackPanel Orientation="Horizontal">
      <CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}" IsEnabled="{Binding IsInScaleRange}" VerticalAlignment="Center"/>
      <TextBlock Text="{Binding Label}" VerticalAlignment="Center"/>
      <Image Source="{Binding ImageSource}" Margin="3,0"/>
     </StackPanel>
    </DataTemplate>
   </ListBox.ItemTemplate>
  </ListBox>
 </ControlTemplate>
</esri:Legend.Template>
<esri:Legend>
you get this result:
0 Kudos
BlueRace
New Contributor II
Hi
I�??m hoping this thread is still open.
I am looking to do something similar to what has been discussed here but my twist is instead of having the layers hard coded in the XAML I�??m looking to (1) have users enter the URL like here #AddLayerDynamically   then  (2)the Sublayers (including any hierarchy) would be listed with checkboxs like here #SubLayerList.

This probably means most of the code will be done in codebehind c# then bound to respective elements in the XAML

I�??m very new to Silverlight. I�??ve been trying to do this for ages but no joy. Any help would be very much appreciated.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Hi
I�??m hoping this thread is still open.
I am looking to do something similar to what has been discussed here but my twist is instead of having the layers hard coded in the XAML I�??m looking to (1) have users enter the URL like here #AddLayerDynamically then (2)the Sublayers (including any hierarchy) would be listed with checkboxs like here #SubLayerList.

This probably means most of the code will be done in codebehind c# then bound to respective elements in the XAML

I�??m very new to Silverlight. I�??ve been trying to do this for ages but no joy. Any help would be very much appreciated.


(1) Adding dynamically the layers doesn't mean any additional c# code for XAML binding. All should be OK with the existing code.

(2) To see the hierarchy of sublayers you need to set the Legend LayerItemsMode to tree. There is a sample here : http://broux.dominique.free.fr/Silverlight/InteractiveSDK/Default.htm#LegendTOC
0 Kudos