Select to view content in your preferred language

Another GroupLayer bug?

1749
2
12-14-2011 12:47 PM
JasonKnisley
Deactivated User
I've noticed two possible bugs with GroupLayer so far.  The first, which I already saw reported, is the fact that layers added to a group layer after the group layer is added to the map don't show up unless you call groupLayer.Initialize()... Interestingly, even while they aren't on the map they do show up in the Legend control.

A second possible bug, which I haven't seen reported yet, is that map.MoveLayer seems to have a strange effect on the GroupLayer.  As a test I have a map with a LayerCollection of size 8, where my GroupLayer is at the last index.  If call map.MoveLayer(map.Layers.IndexOf(groupLayer), 0) and then call map.Layers.IndexOf(groupLayer) immediately after the result now says that it is at index 0, but it doesn't actually get moved.  This is reflected both visually (I can still see it as the topmost layer of the map) and in the legend control, where it's position also does not move.  If I then check the index again (via a button click that I added for the sole purpose debugging this issue) I see that the index is back to 7.  It's as if it successfully moves to the new index (albeit only for a fraction of a second) and then immediately moves back to the old index.
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
I'm not able to reproduce the issue with the following sample. I use a button click event to toggle the position of GroupLayer and I do see Legend control and map reflect the change in layer order. Did I miss anything?

 <Grid x:Name="LayoutRoot" >

  <esri:Map x:Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000">
   <esri:ArcGISTiledMapServiceLayer ID="Street Map" 
                    Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
   <esri:ArcGISDynamicMapServiceLayer ID="United States" Opacity="0.6" 
                    Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"/>
   <esri:GroupLayer ID="MyGroupLayer">
   <esri:FeatureLayer ID="Points of Interest" 
                    Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/0" />
   </esri:GroupLayer>
  </esri:Map>
  <Button Content="Test" Click="Button_Click" VerticalAlignment="Top" HorizontalAlignment="Center"/>
  <Border Background="#77919191" BorderThickness="1" CornerRadius="5"
            HorizontalAlignment="Right"  VerticalAlignment="Top"
            Margin="20" Padding="5" BorderBrush="Black" >
   <esri:Legend Map="{Binding ElementName=MyMap}"                           
                         LayerItemsMode="Tree" 
                         ShowOnlyVisibleLayers="False">
    <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>
  </Border>

 </Grid>
 
</UserControl>


private void Button_Click(object sender, RoutedEventArgs e)
{
 var l = MyMap.Layers["MyGroupLayer"] as GroupLayer;
 var index = MyMap.Layers.IndexOf(l);
 MyMap.MoveLayer(index, index == 1 ? 2 : 1);    
}
0 Kudos
JasonKnisley
Deactivated User
Jennifer,

You are correct, there is no error.  I was testing MoveLayer() on a whim and got caught by a feature in my own code... the particular widget I was testing it on has a primary layer (which is now a GroupLayer with the release of 2.3), and when this widget is in focus it forces its primary layer to the top of the map if it isn't there already.  I experienced this particular problem because I was testing the MoveTo() function on that GroupLayer while this widget was in focus, and so it kept undoing my attempt to move it.  Sorry for the erroneous report.
0 Kudos