Developing with selection

The ArcGIS Runtime SDK for Windows Mobile contains a number of developer components called MapActions. MapActions reduce the amount of code needed to write by providing the necessary common tools and commands. The Selection MapAction is used to select features on a map using a mouse or stylus. With this MapAction, you can set properties including the type of spatial selection (point, line, polygon), the geometric relationship associated with the selection (intersect, touch, overlap, and so on), and the layers from which to select features. In addition, there are properties and events you can use to access selection for a layer while writing minimum code. For more information about queries, see Developing spatial and attribute queries.

Features of the SelectionMapAction

The SelectionMapAction includes the following features:

Selection MapAction workflow

The following steps outline the basic workflow when using the SelectionMapAction. Specific usage and examples with code are detailed in following sections.

Steps:
  1. To begin working with the SelectionMapAction, add the Map control to your application from the ArcGIS Mobile Controls tab within the Visual Studio toolbox.
  2. Declare a new instance of the SelectionMapAction.
  3. Specify the SelectionType as envelope (default), point, or polygon.
  4. Change the GeometricRelationship to the one that meets your requirements.
  5. Give the SelectionFeatureSources property one or more FeatureSources to use in the selection.
  6. When you connect the declared SelectionMapAction to the Map.MapAction property, it becomes active and is used when the mouse is on the map display.
  7. Write code against the StatusChanged event to perform a function with the selection result.

Setting the selection environment

The default selection type is envelope but it can also be set to point or polygon.

// Sets the selection type to be an envelope, 
// which will be the dragged rectangle on the map 
selectionMapAction1.SelectionType = SelectionType.Envelope; 
map1.MapAction = selectionMapAction1;

The most important selection setting is FeatureSources to select from. By specifying specific layers, you can develop a more focused selection tool, improve performance, and limit results; although, sometimes you will want to select from all layers.

// Sets the selected feature layers array to the Selection MapAction 
  for (int i = 0; i < mobileCache1.FeatureSources.Count; ++i)
  {
    SelectionMapAction1.SelectionFeatureSources.Add(mobileCache1.FeatureSources[i]);
  }
// Sets map action to be selection map action 
map1.MapAction = selectionMapAction1;

Using the selection results

The SelectionMapAction waits for a user to make their selection on the map display, then populate a list of FeatureDataTables with the results. This list has one FeatureDataTable containing selected features for each FeatureSource.

private void selectionMapAction1_StatusChanged(object sender, MapActionStatusChangedEventArgs e) 
{ 
//Checked if selection is completed and something is selected 
if (e.StatusId != MapAction.Completed ) 
  return; 

if (selectionMapAction1.SelectedFeatures.Count == 0) 
  return; 

foreach (FeatureDataTable fdtable in selectionMapAction1.SelectedFeatures) 
{ 
  //Use the featurelayer name for the tab name
  tabControlGrid.TabPages.Add(fdtable.FeatureSource.Name); 
} 

//The tab opens on the first layer and uses that to populate the grid
dataGridSelect.Parent = tabControlGrid.TabPages[0];
dataGridSelect.DataSource = selectionMapAction1.SelectedFeatures[0]; 
}
1/7/2015