Select to view content in your preferred language

How to do disappear or appear the graphics (symbol) of Map from legend?

1328
11
12-18-2012 06:51 AM
FabienNAPPA
Regular Contributor
Hi all,

How to do disappear or appear the graphics (symbol) of Map from legend?

Here's what I've done:

I added in the LegendItemTemplate the CheckBox.
        <Setter Property="LegendItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="5,-1,0,-1">
                        
                        <Grid VerticalAlignment="Center">
                            <CheckBox x:Name="ChckBoxLayer" IsChecked="{Binding IsEnabled, Mode=TwoWay}" />
                            <CheckBox IsChecked="{Binding IsEnabled}" IsEnabled="{Binding IsVisible}" IsHitTestVisible="False" />
                        </Grid>
                        
                        <Image Source="{Binding ImageSource}" HorizontalAlignment="Left" VerticalAlignment="Center"
          Stretch="None" MaxHeight="55" MaxWidth="55" MinWidth="20" Margin="0,-1" />
                        
                        <TextBlock Text="{Binding Label}" Margin="8,0,0,0" VerticalAlignment="Center" />
                    </StackPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>


After I added the event in LegendItemViewModel.

private bool _isEnabled = true;
        /// <summary>
        /// Whether the layer is currently enabled i.e. is checked on.
        /// </summary>
        /// <value><c>true</c> if the layer is currently enabled; otherwise, <c>false</c>.</value>
        public bool IsEnabled
        {
            get
            {
                return _isEnabled;
            }
            set
            {
                if (value != _isEnabled)
                {
                    _isEnabled = value;

  // here the action...

       OnPropertyChanged("IsEnabled");
                }
            }
        }


public event PropertyChangedEventHandler PropertyChanged;

  internal void OnPropertyChanged(string propertyName)
  {
   PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
   if (propertyChanged != null)
    propertyChanged(this, new PropertyChangedEventArgs(propertyName));
  }



Thank you in advance,
Fabiano
0 Kudos
11 Replies
FabienNAPPA
Regular Contributor
Hi all,

I have not yet the solution. Do you have any idea?

Thank's
0 Kudos
DominiqueBroux
Esri Frequent Contributor
There is no out of the box solution for showing or hiding all graphics corresponding to a unique value or a class break of the renderer (I am guessing it's what you would need).

You could do it by yourself by code but it's likely not that easy.

I see 3 possible approachs:
    - change to null the symbol of the class break or the unique value, so the graphics will not be displayed (but the legend will reflect this null value).
    - change to null the symbol of all graphics whose attribute is in the class break range (and set FeatureLayer.RendererTakesPrecedence to false)
    - change the where clause of the FeatureLayer in order to exclude the graphics that are in the range

Unfortunately I have no sample to share with these approachs.

Dominique
0 Kudos
FabienNAPPA
Regular Contributor
Thank's for your help Dominique.

In the class LegendItemViewModel I can get ImageSource = legendItemInfo.ImageSource;

I would like to compare the ImageSource those use in the graphic of my Layer.

How to do that?

foreach (var graphic in myLayer.Graphics)
                     {
                         if (ImageSource ==??)
{
/ / Here the action of the graphic to disappear
}
                     }


Thank you for your help.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I would like to compare the ImageSource those use in the graphic of my Layer.


That won't work. The legend ImageSource is a static snapshot of the symbol and there is no way to retrieve the symbol or the graphics from that image source.

The easiest way to get the association between a legend item and a symbol is during the event Legend.Refreshed.

The legend items returned by the feature layer are in the same order as the UniqueValueInfos in the UniqueValueRenderer, so at this stage you could store the symbol or the UniqueValueInfo in the Tag of the LegendItemViewModel.


Then you can reuse this tag when the user clicks the checkbox in the legend.
0 Kudos
FabienNAPPA
Regular Contributor
great idea, thank you Dominique.

Best regards
0 Kudos
FabienNAPPA
Regular Contributor
How to retrieve the Symbol from the Legend_Refreshed?

Thank's
0 Kudos
FabienNAPPA
Regular Contributor
Hi all,

I still can't to retrieve the symbol from refresh!

Someone an idea?

Thank you in advance
Fabiano
0 Kudos
FabienNAPPA
Regular Contributor
I have not found the solution !

Do you have an idea of �??�??how to retrieve the symbol from legend_refresh?

In advance thank you,
Fabiano
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I have not found the solution !

Do you have an idea of �??�??how to retrieve the symbol from legend_refresh?


The symbols come from the renderer. For example, if your renderer is an UniqueValueRenderer, you can get the Infos collection. Each uniquevalueinfo has a symbol property which is likely what you are looking for.

Additionaly an UniqueValueRenderer may have a DefaultSymbol which, if not null,  will be first in the LegendItems collection.
0 Kudos