Select to view content in your preferred language

ClearSelection ICommand fails on Polygons in Silverlight API v2.1

927
7
10-13-2010 01:28 PM
jarrodskulavik
Deactivated User
Hi All,

The awesome Editor Commands all work well in the 2.1 version, with the exception of ClearSelection.  It works fine on point and polyline features, but is does not clear the selection against any polygon layers that I pass.
0 Kudos
7 Replies
AliMirzabeigi
Emerging Contributor
I am not able to reproduce your problem and tried it in both code-behind and XAML.
Could you please provide more information if you are still encountering the issue?
0 Kudos
jarrodskulavik
Deactivated User
The problem seems to occur when creating FeatureLayers from both version 10 and 9.3.1 ArcGIS Server MapServices within the same Editor binding/Map.  The clear select works for all layers in 10 or all layers in 9.3.1, but when you mix FeatureLayers, it does not.

Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
I also am not able to reproduce the issue with the following code:

<Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <esri:Editor x:Key="MyEditor" Map="{Binding ElementName=MyMap}"/>
        </Grid.Resources>
        <esri:Map x:Name="MyMap" Extent="-85.9444646373356,37.9972855862017,-85.4429082072966,38.3780113173182">
            <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" 
    Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
            <esri:FeatureLayer ID="Layer10" Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/2"/>
            <esri:FeatureLayer ID="Layer931" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer/0"/>
        </esri:Map>
        <StackPanel VerticalAlignment="Top" HorizontalAlignment="Center" DataContext="{StaticResource MyEditor}">
            <Button x:Name="SelectBtn" Content="Select" Command="{Binding Select}"/>
            <Button x:Name="ClearBtn" Content="Clear" Command="{Binding ClearSelection}"/>
        </StackPanel>
    </Grid>


Do you set ID on both layers? If not, maybe this is the reason the FeatureLayer is ignored. Please let me know what I did different to help me reproduce what you are experiencing with ClearSelection.

Thanks!
0 Kudos
jarrodskulavik
Deactivated User
Hello,

Yes, I have IDs set on every single layer in my map.

Here's the code for my binding to the command:
(Grid.FindName("ClearSelectButton") as Button).SetBinding(Button.CommandProperty, new Binding("ClearSelection"));

And here are the layers that you're using.  The Fire/Sheep layer with ID 2 will not clear its selection, it remains cyan and selected when the above command is executed.  However, the above command clears all polyline and point selections from both 9.3.1 and 10 FeatureLayers.

            Map.Layers.Add(new ESRI.ArcGIS.Client.FeatureLayer
            {
                ID = "Layer10",
                Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/2",
            });
            Map.Layers.Add(new ESRI.ArcGIS.Client.FeatureLayer
            {
                ID = "Layer931",
                Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/M..."
            });
0 Kudos
JenniferNery
Esri Regular Contributor
Can you also share your code on how you define the  Editor?  Also, do you set the DataContext of your ClearSelection button? 

In the XAML code I have, the StackPanel that includes my button has its DataContext set to the Editor.  Do you do something similar in your code-behind binding?
0 Kudos
jarrodskulavik
Deactivated User
Hi Jennifer,

Yes, of course.  I've placed my ClearSelection button in a border and set its DataContext.  The relative snippets are:

//Editor
_MapEditor = new Editor { Map = MyMap, SelectionMode = DrawMode.Rectangle, ContinuousMode = true };

(Grid.FindName("SpatialQueryBorder") as Border).DataContext = _MapEditor;
0 Kudos
JenniferNery
Esri Regular Contributor
Please try the following sample. I tried to use your same approach of defining the Editor and Binding in code-behind and also add the layers at run-time. 

For simplicity, I only have ClearSelection, graphics in my sample are selected as soon as the feature layer update is complete.  I added MouseLeftButtonDown so you can check which graphic belongs to which layer and whether it is infact, selected.  I also added ZoomTo the layer's extent so you can verify visually whether their graphics are being selected/deselected.

I could not replicate the issue.
XAML-code
 <Grid x:Name="LayoutRoot" Background="White">
  <esri:Map x:Name="MyMap" Extent="-85.6657120405393,38.3219737638205,-85.5755236547754,38.3873509095678"/>
  <Border x:Name="MyBorder" VerticalAlignment="Top" HorizontalAlignment="Center">
   <StackPanel Orientation="Horizontal">
    <Button x:Name="ClearBtn" Content="Clear" />
    <Button x:Name="ZoomTo931" Content="Zoom to Layer931"  Click="ZoomTo931_Click"/>
    <Button x:Name="ZoomTo10"  Content="Zoom to Layer10" Click="ZoomTo10_Click"/>
   </StackPanel>
  </Border>
 </Grid>


Code-behind:
public MainPage()
  {
   InitializeComponent();
   Editor editor = new Editor() { Map = this.MyMap, ContinuousMode = true };
   Border border = this.LayoutRoot.FindName("MyBorder") as Border;
   if (border != null)
    border.DataContext = editor;
   Button button = this.LayoutRoot.FindName("ClearBtn") as Button;
   if (button != null)
    button.SetBinding(Button.CommandProperty, new System.Windows.Data.Binding("ClearSelection"));
   FeatureLayer layer = new FeatureLayer()
   {
    ID = "Layer10",
    Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/2"
   };
   layer.UpdateCompleted += layer_UpdateCompleted;
   layer.MouseLeftButtonDown += layer_MouseLeftButtonDown;
   this.MyMap.Layers.Add(layer);
   layer = new FeatureLayer()
   {
    ID = "Layer931",
    Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer/0"
   }; 
   layer.UpdateCompleted += layer_UpdateCompleted;
   layer.MouseLeftButtonDown += layer_MouseLeftButtonDown;
   this.MyMap.Layers.Add(layer);
  }
  
  void layer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
  {
   FeatureLayer layer = sender as FeatureLayer;
   MessageBox.Show(string.Format("Layer ID: {0}, Graphic Selected: {1}", layer.ID, e.Graphic.Selected));
   e.Handled = true;
  }

  void layer_UpdateCompleted(object sender, EventArgs e)
  {
   FeatureLayer layer = sender as FeatureLayer;
   foreach (Graphic g in layer.Graphics)
    g.Selected = true;
  }

  private void ZoomTo931_Click(object sender, RoutedEventArgs e)
  {
   this.MyMap.ZoomTo(new Envelope(-85.6657120405393, 38.3219737638205, -85.5755236547754, 38.3873509095678));
  }

  private void ZoomTo10_Click(object sender, RoutedEventArgs e)
  {
   this.MyMap.ZoomTo(new Envelope(-118.407424798307, 33.9943429215228, -117.3355913417, 34.7713100610928));
  }
0 Kudos