Select to view content in your preferred language

Legend Help Please

2180
3
Jump to solution
08-06-2012 01:08 PM
TanyaOwens
Frequent Contributor
Hello,

I am using this sample: http://resources.arcgis.com/en/help/...dWithTemplates with the Showcase Template. First, I am having trouble integrating the sample with the Showcase Template. The setup with esri:Legend.MapLayerTemplate and esri:Legend.LayerTemplate are the main problem - I get errors when I try to use them and I am not sure how to work around this. I would like to add the checkbox element to the showcase template legend.

Second, I have several layers grouped together from one dynamic map service layer and one feature layer (for using InfoWindow). I would like my legend to show the feature layer and the service layer together without the service layer ID showing in the legend. I am having trouble figuring out where/how to change this in the code.

So Right now I have:

Schools (Layer ID) - my feature layer for InfoWindow use
    School Layer 1
    School Layer 2
BaseMap layers (Layer ID) - my dynamic service layer
    Basemap layer 1
    Basemap layer 2

What I want is: (with check boxes to turn on and off the layers in the map)

School Layer 1
School Layer 2
Basemap Layer 1
Basemap Layer 2

Is this possible?

FYI - I am new to programming and I am using API 2.4 and silverlight 4.

Thanks!
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
[INDENT]You can reorganize legend layer items on event Legend.Refreshed.

I created a sample demonstrating how we can move the feature layer item from the root to the hierarchy of the dynamic layer items.

Hope this helps. [/INDENT]

View solution in original post

0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
[INDENT]You can reorganize legend layer items on event Legend.Refreshed.

I created a sample demonstrating how we can move the feature layer item from the root to the hierarchy of the dynamic layer items.

Hope this helps. [/INDENT]
0 Kudos
TanyaOwens
Frequent Contributor
This code helped me integrate this sample http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LegendWithTemplates with the Showcase template but I am still confused about how to use Legend_Refreshed to organize my layers. The sample you provided is replacing the duplicate dynamic layer with the feature layer. I don't have any duplicates and it would be simply adding the feature layer at the beginning of the dynamic layer service sublayers. I am also having trouble figuring out how to tell it to show all sublayer but not the heading of the dynamic service layer. Sorry if this obvious but being new to this, I just don't see it.
0 Kudos
TanyaOwens
Frequent Contributor
Aha!! I changed LayerItemsMode to Flat and the following code and it seems to work:

App.xaml:
        <Style TargetType="esri:Legend">
            <Setter Property="LayerItemsMode" Value="Flat" />
            <Setter Property="LayerTemplate">
                <Setter.Value>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <CheckBox Content="{Binding Label}"
                          IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                          IsEnabled="{Binding IsInScaleRange}" >
                                    </CheckBox>
   
                                </StackPanel>
                            </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="MapLayerTemplate">
                <Setter.Value>

                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox Content="{Binding Label}"
                          IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                          IsEnabled="{Binding IsInScaleRange}" >
                            </CheckBox>

                        </StackPanel>
                    </DataTemplate>
                </Setter.Value>

            </Setter>
        </Style>


MainPage.xaml:
          <userControls:DraggableWindow IsOpen="True" x:Name="MapLegendWindow" Margin="0,280,20,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="212" Height="231" Padding="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Title="Map Legend" Background="{StaticResource BaseColor}">
                <i:Interaction.Triggers>
                    <i:EventTrigger>
                        <actions:ToggleWindowVisibilityAction /> <!-- Hide at startup -->
                    </i:EventTrigger>
                </i:Interaction.Triggers>

                <esri:Legend x:Name="Legend" Map="{Binding ElementName=MyMap}"
                             LayerIDs="Schools, Base Layers"
                             LayerItemsMode="Flat"
                             ShowOnlyVisibleLayers="False"
                             Refreshed="Legend_Refreshed"/>
              




            </userControls:DraggableWindow>
        </Grid>



MainPage.xaml.cs:
        private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
        {
            LayerItemViewModel removeLayerItemVM = null;

            if (e.LayerItem.LayerItems != null)
            {
                foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems)
                {
                    if (layerItemVM.IsExpanded)
                        layerItemVM.IsExpanded = false;


                }

                if (removeLayerItemVM != null)
                    e.LayerItem.LayerItems.Remove(removeLayerItemVM);
            }
            else
            {
                e.LayerItem.IsExpanded = false;
            }
        }
0 Kudos