GraphicsLayer Legend Alias Names

2283
3
05-16-2011 09:53 AM
adamestrada
New Contributor
All,

My app has several Graphics layers that are generated dynamically based on specific query results and whatnot. 

My esri:Map container looks like this:

                <esri:Map x:Name="Map" Loaded="Map_Loaded" Extent="-15000000,2000000,-7000000,8000000" ExtentChanged="Map_ExtentChanged" MouseMove="Map_MouseMove"
                          Grid.Row="1" Grid.Column="0">

                    <esri:ArcGISTiledMapServiceLayer ID="AGOLayer" Visible="True"  
                        Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />

                    <esri:WmsLayer ID="Nexrad" Opacity="0.5" SkipGetCapabilities="True" Initialized="WmsLayer_Initialized"  Visible="True" />

                    <esri:GraphicsLayer ID="ContextGraphicsLayer" x:Name="TestLayer"></esri:GraphicsLayer>

                    <esri:GraphicsLayer ID="GeocodeResultsGraphicsLayer">
                        <esri:GraphicsLayer.MapTip>
                            <Grid>
                                <Border BorderBrush="Black" CornerRadius="10"  BorderThickness="1" Background="#FFFFE300" />
                                <StackPanel Orientation="Vertical" Margin="5">
                                    <TextBlock Text="{Binding [DisplayName]}" HorizontalAlignment="Left" />
                                </StackPanel>
                            </Grid>
                        </esri:GraphicsLayer.MapTip>
                    </esri:GraphicsLayer>
                    <esri:GraphicsLayer ID="SelectionGraphicsLayer" 
                                        MouseEnter="GraphicsLayer_MouseEnter" 
                                        MouseLeave="GraphicsLayer_MouseLeave" />

                </esri:Map>


In my Legend the names of the GraphicsLayers are based on the ID and not not really all that appealing. eg. SelectionGraphicsLayer, GeocodeResultsGraphicsLayer and ContextGraphicsLayer. My question is can I change or alias these names when they are displayed in the Legend?

Thanks,
Adam
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
In my Legend the names of the GraphicsLayers are based on the ID and not not really all that appealing. eg. SelectionGraphicsLayer, GeocodeResultsGraphicsLayer and ContextGraphicsLayer. My question is can I change or alias these names when they are displayed in the Legend?


You can hook up an handler to the Legend.Refreshed event and change the Labels in this handler.
Something like:

 
private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
{
    switch(e.LayerItem.Layer.ID)
    {
        case "ContextGraphicsLayer":
            e.LayerItem.Label = "Contextual result";
            break;
        case "GeocodeResultsGraphicsLayer":
            e.LayerItem.Label = "Geocode result";
            break;
    }
}


You can also remove the legend item if you'd rather not to see it in the legend.
0 Kudos
adamestrada
New Contributor
Thanks Dominique,

That worked to change the display name but to make the layer completely invisible I get the following error.

Property or indexer 'ESRI.ArcGIS.Client.Toolkit.Primitives.LayerItemViewModel.IsVisible' cannot be assigned to -- it is read only


                case "GeocodeResultsGraphicsLayer":
                    e.LayerItem.IsVisible = false;
                    //e.LayerItem.Label = "Geocode result";
                    break;


Why would the visibility be read only?

Adam
0 Kudos
DominiqueBroux
Esri Frequent Contributor
IsVisible is a read-only property because it returns the current visibility of the layer or sublayer by taking care of the current scale and of the visibility of the parent hierarchy (for a sublayer).

The writeable property is called 'IsEnabled', so e.LayerItem.IsEnabled = false; should work.
You can also set directly the 'Visible' property of the layer : e.LayerItem.Layer.Visible = false;
0 Kudos