2 Replies Latest reply on Dec 4, 2014 8:43 AM by Erica Pfister-Altschul

    Excluding layers from, and switching order of, a legend

    Erica Pfister-Altschul

      We need to show our users symbology in addition to simply listing layers, so I added in a legend using Legend Class and ArcGIS API for Silverlight - Interactive Samples: Legend with Template. It works, but it's bringing up some further questions:

       

      (1) How can I exclude layers from this list?

      exclude.png

      These last three layers aren't anything I added (and, incidentally, don't show up in the Table of Contents), so they're presumably related to the ArcFM viewer. InsetMapMarker, for example, I assume is the red rectangle in the inset map. In order to ensure everything works smoothly AND to avoid questions from confused end users ("I didn't make a buffer, what's this BufferLayer?") I don't want them to show in the legend. How can I exclude those layers?

       

      (2) How can I switch the order of the layers?

       

      The legend list our layers in the same order we added them in the XAML: lowest layer first.


      This does not, however, match the order that our users expect to see -- we are transitioning a bunch of users from ArcGIS Desktop, where the lowest layer is listed last, to this ArcFM Silverlight viewer. Again, we are hoping to avoid questions from confused end users.

       

      How do I flip the order of the layers in the legend, so it will show:

      1. Annotation Layer
      2. Electric Data
      3. Aerial Imagery
      4. Street Map Layer

       

      This is the current XAML for the legend:

                  <esri:Legend Name="Legend" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,25,0,0" Width="350"

                              Map="{Binding ElementName=MapControl}"

                              LayerItemsMode="Tree" Refreshed="Legend_Refreshed"

                              ShowOnlyVisibleLayers="False">

                      <esri:Legend.MapLayerTemplate>

                          <DataTemplate>

                              <StackPanel Orientation="Horizontal">

                                          <CheckBox Content="{Binding Label}"

                                                    IsChecked="{Binding IsEnabled, Mode=TwoWay}"

                                                    IsEnabled="{Binding IsInScaleRange}" >

                                          </CheckBox>

                                  </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>


      and for the C# behind:

              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 (layerItemVM.Label == "InsetMapMarker")

                              removeLayerItemVM = layerItemVM;

                          if (layerItemVM.Label == "TextTemporary")

                              removeLayerItemVM = layerItemVM;

                          if (layerItemVM.Label == "BufferLayer")

                              layerItemVM.Label = "CHANGE ME";

                      }

                      if (removeLayerItemVM != null)

                          e.LayerItem.LayerItems.Remove(removeLayerItemVM);

                  }

                  else

                  {

                      e.LayerItem.IsExpanded = false;

                  }

              }