Select to view content in your preferred language

Adding Symbols for graphics layer in Legend Tool

2079
1
04-18-2012 04:50 AM
SaurabhDasgupta
Deactivated User
Hi,
   I need a help on this. I ahve a silverlight application which displays the Basemap layer. Here I am displaying the legend information only for the graphics layer. This addition of the graphics layer is done dynamically. Now the legend information shows the name of the layer associated with it. On this I want to add the symbology for each legend information every time I add the different layer information for the map. My xaml code looks like this.

<Border Background="#77919191" BorderThickness="1" CornerRadius="5"
            HorizontalAlignment="Left" VerticalAlignment="Top"  Margin="0,70,15,5" Height="Auto" Padding="0" BorderBrush="Black" >
            <esriToolkit:Legend Map="{Binding ElementName=edmsMap}" x:Name="edmsProgramTypeLegend" Loaded="edmsProgramTypeLegend_Loaded"
                         LayerIDs=""
                         LayerItemsMode="Flat"
                         ShowOnlyVisibleLayers="False"
                         Refreshed="edmsProgramTypeLegend_Refreshed"
                                                         >
                <esriToolkit:Legend.MapLayerTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox x:Name="legendSelectionCheckBox"  Content="{Binding Label}"
                  IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                  IsEnabled="{Binding IsInScaleRange}"
                                    Checked="legendSelectionCheckBox_Checked" 
                                    Unchecked="legendSelectionCheckBox_Unchecked">
                            </CheckBox>
                            <Button x:Name="deleteLayerButton" Width="25" Height="23" Tag="{Binding Label}"  Click="DeleteLayer_Click">
                                <Image Source="Images/deleteLayer.png" />
                            </Button>
                            <Button x:Name="showResultButton" Width="25" Height="23" Tag="{Binding Label}"  Click="showResultButton_Click">
                                <Image Source="Images/report.png" />
                            </Button>
                            <Button x:Name="selectGraphicResults" Width="25" Height="23" Tag="{Binding Label}"  Click="selectGraphicResults_Click">
                                <Image Source="Images/selectiontool.png" />
                            </Button>                           
                        </StackPanel>
                    </DataTemplate>                   
                </esriToolkit:Legend.MapLayerTemplate>
                <esriToolkit:Legend.LayerTemplate>
                    <DataTemplate>
                        <CheckBox x:Name="legendSelectionCheckBox" Content="{Binding Label}"
                   IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                IsEnabled="{Binding IsInScaleRange}"
                            Checked="legendSelectionCheckBox_Checked" 
                            Unchecked="legendSelectionCheckBox_Unchecked">
                        </CheckBox>
                       
                    </DataTemplate>
                </esriToolkit:Legend.LayerTemplate>
            </esriToolkit:Legend>
        </Border>




My C# code looks like this

private void edmsProgramTypeLegend_Loaded(object sender, RoutedEventArgs e)
{
     
}

private void edmsProgramTypeLegend_Refreshed(object sender, Legend.RefreshedEventArgs e)
       {
           //LayerItemViewModel removeLayerItemViewModel = null;

           if (!(layerNames == null || layerNames.Length == 0))
           {
               edmsProgramTypeLegend.LayerIDs = layerNames;
               edmsProgramTypeLegend.Visibility = System.Windows.Visibility.Visible;
           }
           else
           {
               edmsProgramTypeLegend.Visibility = System.Windows.Visibility.Collapsed;
           }
}

Attached is screen shot for the map legend information.
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
If your graphics layer uses a renderer for displaying the graphics, the legend swatches should automatically be drawn in the legend control.

If your graphics layer doesn't use a renderer, i.e. you assigned a symbol by graphic, no swatches are generated by default.
However you can create your own swatches (ie. LegendItemViewModel object) and add them to the layer lgend item on event 'Refreshed'.
0 Kudos