Select to view content in your preferred language

GroupLayer in version 2.3

967
5
11-28-2011 10:58 AM
JasonCleaver
Frequent Contributor
Question,

I have a Silverlight App that uses a config.xml file that it reads to populate the map layers.  The layers are defined in ascending order in the xml file, but when I add the layers to the map control, I reverse the list because and then add each layer from the "bottom up".  I then, populate the Legend control with the layer IDs in ascending order so everything "looks" normal.  Through trial and error, and via forum postings, when adding layers via code, you have to add the bottom layer first.

Anyway, I am now trying to incorporate the new GroupLayer class and I am running into some issues.  The GroupLayers are appearing in the right order in the Legend, but the sub-layers are now in reverse order.  Thoughts?  Has anyone else tried this new functionality via code?

Jason
0 Kudos
5 Replies
DominiqueBroux
Esri Frequent Contributor
One option is you to write a value converter reversing the list of legend items, and then retempalte the legend control and use this converter.

Something like :
<sdk:HierarchicalDataTemplate ItemsSource="{Binding LayerItemsSource, Converter=MyReverseConverter}" >...
0 Kudos
RobChouinard
Frequent Contributor
One option is you to write a value converter reversing the list of legend items, and then retempalte the legend control and use this converter.

Something like :
<sdk:HierarchicalDataTemplate ItemsSource="{Binding LayerItemsSource, Converter=MyReverseConverter}" >...


Would this be placed in the Legend.MapLayerTemplate? Something like this:

<esri:Legend Map="{Binding ElementName=MyMap}" LayerItemsMode="Tree" LayerIDs="Bloomfield Hills" 
                         ShowOnlyVisibleLayers="False" Refreshed="Legend_Refreshed">
                <esri:Legend.MapLayerTemplate>
                    <sdk:HierarchicalDataTemplate ItemsSource="{Binding LayerItemsSource, Converter=MyReverseConverter}" >
                        <StackPanel Orientation="Horizontal">
                            <CheckBox Content="{Binding Label}"
                  IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                  IsEnabled="{Binding IsInScaleRange}" >
                            </CheckBox>
                        </StackPanel>
                    </sdk:HierarchicalDataTemplate>
                </esri:Legend.MapLayerTemplate>
            </esri:Legend>
0 Kudos
RobChouinard
Frequent Contributor
I accomplished this in the code behind using LINQ to reverse the order:

        private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
        {
            // Reverse the groups layer items
            if (e.LayerItem.Label == "Group ID")
            {
                e.LayerItem.LayerItems = new System.Collections.ObjectModel.ObservableCollection<LayerItemViewModel>(e.LayerItem.LayerItems.Reverse());
            }
        }
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Would this be placed in the Legend.MapLayerTemplate?

No, I was more thinking about the Template itself (that needs Blend to be easily accessed).

 
I accomplished this in the code behind using LINQ to reverse the order:

Great. It's a better idea.

Just a tip, to be generic you can replace your test 'if (e.LayerItem.Label == "Group ID")' by 'if (e.LayerItem.Layer is GroupLayer)'
0 Kudos
RobChouinard
Frequent Contributor

Just a tip, to be generic you can replace your test 'if (e.LayerItem.Label == "Group ID")' by 'if (e.LayerItem.Layer is GroupLayer)'


Even better. Thanks!
0 Kudos