Get opacity of layers in Legend control

2897
5
04-29-2013 10:56 PM
MiriEshel
New Contributor III
Hi everybody,

I'm using a legend that looks like this:
                           
<esri:Legend x:Name="Legend"
                                         LayerIDs="USAID_Layers"
                                         LayerItemsMode="Tree"
                                         Map="{Binding ElementName=Map}"
                                         Refreshed="Legend_Refreshed"
                                         ShowOnlyVisibleLayers="True">
                                <esri:Legend.LegendItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="0,-3" Orientation="Horizontal">
                                            <Image MinWidth="20"
                                                   Margin="0,-1"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Source="{Binding ImageSource}"
                                                   Stretch="None" />
                                            <TextBlock MinWidth="80"
                                                       Margin="5,0"
                                                       VerticalAlignment="Center"
                                                       Text="{Binding Label}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </esri:Legend.LegendItemTemplate>
                            </esri:Legend>


One of the layer has opacity (defined in the mxd).
This layer looks good on the map (the brown and yellow polygons) but it is solid (has no opacity) in the legend.
See attached files.

Is there any binding that I can do in order to get the opacity of the layer from the mxd?

Thanks a lot.
Miri
0 Kudos
5 Replies
by Anonymous User
Not applicable
Original User: dbroux

You can redefine the LegendItemTemplate of the legend and bind the swatch opacity to the layer opacity.Something like:
<esri:Legend.LegendItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <Image MinWidth="20" HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                      Opacity="{Binding Path=DataContext.Layer.Opacity,
                                        RelativeSource={RelativeSource AncestorType=esriToolkitPrimitives:TreeViewItemExtended,
                                                                    AncestorLevel=2}}" 
                     Source="{Binding ImageSource}"
                    Stretch="None" />
            <TextBlock Margin="5,0,0,0" VerticalAlignment="Center" Text="{Binding Label}" />
        </StackPanel>
    </DataTemplate>
</esri:Legend.LegendItemTemplate>
0 Kudos
MiriEshel
New Contributor III
Hi Dominique,

Thank you for your help.

I've tried what you have suggested but unfortunately it does not help. What you've suggested is related to ArcGISDynamicMapServiceLayer as a whole, so if I do:
             <esri:ArcGISDynamicMapServiceLayer ID="USAID_Layers"
                                                       Initialized="ArcGISDynamicMapServiceLayer_Initialized"
                                                       Opacity="0.3" DisableClientCaching="True"                                                      
                                                        />
I will see the legend of all layers ,in the legend of the ArcGISDynamicMapServiceLayer, transparent.
The thing is that I'm interested in individual layers within the ArcGISDynamicMapServiceLayer (few polygon layers) that will be transparent (with opacity). I thought that if I will define these layers transparent in the MXD and publish it, it will look the same in the legend of the application but it doesn't.
As a result, Esri opened a NIM for that :Bug ID: # NIM091488
Synopsis Transparency of Legends/TOC not honored in Map Service

The  ArcGISDynamicMapServiceLayer exposes very few details for each individual layer in the service - minScale, maxScale, name, subLayersID, defaultVisibility (you can see in the attached file) so I cannot grab the opacity.


Thanks a lot,
Miri
0 Kudos
by Anonymous User
Not applicable
Original User: aafgilbert01

Hello,

I would like to know if the issue of enabling opacity in the color box in the esri:legend has been resolved in the last release. If it has been solved, I would like to have also a sample code of the XAML to write the opacity binding with the layer.


Regards
0 Kudos
FrancoisGilbert
New Contributor
Is there any news regarding Bug ID: # NIM091488

Has this been adressed in the latest ArcGis Runtime platform.

Regards
0 Kudos
by Anonymous User
Not applicable
Original User: miri

Hi Francois,

As far as I know, it is solved in 10.2.
With which ArcGIS Server version are you working?

Miri
0 Kudos