Select to view content in your preferred language

Opacity on thematics tool

413
1
03-19-2012 11:13 AM
jonataspovoas
Regular Contributor
Hi,

I'm Creating a "thematics map tool", and i'm having trouble to set a property to change the opacity on the Layer I present with them.
<ListBox x:Name="nomeTematico" Grid.Row="1" Margin="0,0,0,217" Background="#FFFEFEFE" 
             BorderBrush="{x:Null}" Foreground="#FF245489">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <CheckBox Margin="2"
                          IsChecked="{Binding DefaultVisibility}"
                          Tag="{Binding ID}"
                          ClickMode="Press" 
                          Checked="AtivaVisualizacaoDeTematico"
                          Unchecked="DesativaVisualizacaoDeTematico"/>
                <Slider Maximum="1" Value="{Binding Opacity??, Mode=TwoWay}" Width="40" Margin="0,0,8,0" />
                <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
<ListBox x:Name="legendaTematico" BorderBrush="{x:Null}" Margin="20,43,0,5" Grid.Row="1"/>

This is the code to my thematics window, and the following code shows the moment I select a theme:
private void AtivaVisualizacaoDeTematico(object sender, RoutedEventArgs e)
{
    if (sender is CheckBox)
    {
        this.tematicoExibido = sender as CheckBox;
    }
    if (this.tematicoExibido != null)
    {
        string serviceName = this.comboTematico.SelectedItem as string;
        int indiceDaCamada = (int)tematicoExibido.Tag;

        ArcGISDynamicMapServiceLayer camadaDeTematicos = mapaEmExecucao.Layers["Mapa Tematicos"] as ArcGISDynamicMapServiceLayer;
        
        List<int> subCamadasVisiveis;
        if (camadaDeTematicos.VisibleLayers != null)
        {
            subCamadasVisiveis = camadaDeTematicos.VisibleLayers.ToList();
        }
        else
        {
            subCamadasVisiveis = new List<int>();
        }

        if (!subCamadasVisiveis.Contains(indiceDaCamada))
        {
            subCamadasVisiveis.Add(indiceDaCamada);
        }
       
        camadaDeTematicos.VisibleLayers = subCamadasVisiveis.ToArray();
    }
}

private void DesativaVisualizacaoDeTematico(object sender, RoutedEventArgs e)
{
    if (sender is CheckBox)
    {
        this.tematicoExibido = sender as CheckBox;
    }
    if (this.tematicoExibido != null)
    {
        string serviceName = this.comboTematico.SelectedItem as string;
        int indiceDaCamada = (int)tematicoExibido.Tag;

        ArcGISDynamicMapServiceLayer camadaDeTematicos = mapaEmExecucao.Layers["Mapa Tematicos"] as ArcGISDynamicMapServiceLayer;

        List<int> subCamadasVisiveis;
        if (camadaDeTematicos.VisibleLayers != null)
        {
            subCamadasVisiveis = camadaDeTematicos.VisibleLayers.ToList();
        }
        else
        {
            subCamadasVisiveis = new List<int>();
        }

        if (subCamadasVisiveis.Contains(indiceDaCamada))
        {
            subCamadasVisiveis.Remove(indiceDaCamada);
        }

        camadaDeTematicos.VisibleLayers = subCamadasVisiveis.ToArray();
    }
}
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
I guess the ItemSources of your ListBox is set to the Layers property of an ArcGISDynamicMapServiceLayer.
It means that the DataContext of each listbox item is a LayerInfo object. This object has no opacity property since LayerInfo gives the metadata info coming from the server while opacity is set at client side.

So it's not that easy to bind the Opacity in this context.

I strongly recommend you to use the legend control which is done for this use case (live sample)
0 Kudos