Select to view content in your preferred language

Interactive Legend check-box bindings

3164
3
Jump to solution
03-20-2014 08:32 AM
Labels (1)
eranz
by
Emerging Contributor
Hi,

I have an interactive legend with check-box for each layer (like in samples)

[HTML]<esri:Legend Map="{Binding ElementName=MyMap}" 
                         LayerIDs="USA"
                         LayerItemsMode="Tree"
                         ShowOnlyVisibleLayers="False"
                         Refreshed="Legend_Refreshed">
                <esri:Legend.MapLayerTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox Content="{Binding Label}"
                                    IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                                    IsEnabled="{Binding IsInScaleRange}" >
                            </CheckBox>
                            <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />
                        </StackPanel>
                    </DataTemplate>
                </esri:Legend.MapLayerTemplate>
                <esri:Legend.LayerTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding Label}"
                            IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                            IsEnabled="{Binding IsInScaleRange}" >
                        </CheckBox>
                    </DataTemplate>
                </esri:Legend.LayerTemplate>
            </esri:Legend>[/HTML]

I have an arcGISDynamicMapService which i took one of its childLayer and made it invisible. also added it as FeatureLayer to my
map. The legend is showing me both the hidden layer and the featureLayer - i want to change bindings of this specific layer only
in order to influence only the feature layer visibility and keep the original layer hidden. (But keep the regular bindings to the other
layers)
Note: i have removed the featureLayer from legend - i want the user see it in the original service hierarchy.

Any ideas?
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
Hi,

I have an arcGISDynamicMapService which i took one of its childLayer and made it invisible. also added it as FeatureLayer to my
map. The legend is showing me both the hidden layer and the featureLayer - i want to change bindings of this specific layer only
in order to influence only the feature layer visibility and keep the original layer hidden. (But keep the regular bindings to the other
layers)
Note: i have removed the featureLayer from legend - i want the user see it in the original service hierarchy.

Any ideas?


This sample may help.
The idea is on event Legend.Refreshed to remove the unexepected legend items and to reorganize them.

View solution in original post

0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
Hi,

I have an arcGISDynamicMapService which i took one of its childLayer and made it invisible. also added it as FeatureLayer to my
map. The legend is showing me both the hidden layer and the featureLayer - i want to change bindings of this specific layer only
in order to influence only the feature layer visibility and keep the original layer hidden. (But keep the regular bindings to the other
layers)
Note: i have removed the featureLayer from legend - i want the user see it in the original service hierarchy.

Any ideas?


This sample may help.
The idea is on event Legend.Refreshed to remove the unexepected legend items and to reorganize them.
0 Kudos
eranz
by
Emerging Contributor
Hi,

thanks for replying.
I have followed the sample you gave me, and it works fine.
But now i have lost functionality of the legend when check/uncheck the
group layer check box which the feature layer became its child after the replacement.

Should i handle it myself now? or there is something else i could do?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Hi,

thanks for replying.
I have followed the sample you gave me, and it works fine.
But now i have lost functionality of the legend when check/uncheck the
group layer check box which the feature layer became its child after the replacement.

Should i handle it myself now? or there is something else i could do?

Yes. That's the drawback, The feature layer is artificially placed in the dynamic layer legend hierarchy but is not following the same rules concerning the scale range and the visibility.
For the scale range, you can define the feature layer with the same scale range as the sublayer it replaces. That should solve the scale range issue.
For the visibility, you could by code link the feature layer visibility to the visibility of the dynamic layer and the visibility of the group layer.

For example after making _groupLayerItem a member variable, define a method UpdateFeatureLayerVisibility as
void UpdateFeatureLayerVisibility()
{
    if (_featureLayerItem != null && _groupLayerItem != null)
        _featureLayerItem.IsEnabled = _groupLayerItem.Layer.Visible && _groupLayerItem.IsEnabled;
}


and call this method when the layer or group layer visibility changes:

if (subLayerItem != _featureLayerItem) // else replacement already done
{
    dynamicLayerItem.Layer.PropertyChanged += (s, evt) =>
    {
        if (evt.PropertyName == "Visible")
            UpdateFeatureLayerVisibility();
    };
    ((ISublayerVisibilitySupport)dynamicLayerItem.Layer).VisibilityChanged += (s, evt) => UpdateFeatureLayerVisibility();
......


That being said, it will become more complex if you want to manage multi group layer levels and multiple feature layers so I may not recommend this approach, but if this can help for a selective and specific need....
0 Kudos