Developing with selection

The ArcGIS Mobile SDK contains a number of developer components called MapActions, which reduce the amount of code you need to write by encapsulating common tools and commands you will need. The Selection MapAction is a component that you can use to select features on a map using either a mouse or stylus. Using 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, etc) and the layers to select. In addition, there are properties and events that you can use to access selection for a layer without having to write much code. For more information about queries see Querying spatial and attribute information.

Features of the SelectionMapAction

The selection MapAction includes the following features:

Selection MapAction workflow

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

Steps:
  1. To begin working with the selectionMapAction you need to add the Map control to your application from the ArcGIS Mobile Controls tab within the Visual Studio toolbox.
  2. To associate the selection MapAction with the map you can use the Visual Studio designer or write code. Within the designer you can open the MapAction Collection Editor and add the selectionMapAction. If you wish to do this entirely in code you can create a new selectionMapAction and then add it to the MapActionCollection on the map control.
  3. Specify the SelectionType to be envelope (default), point or polygon.
  4. Change the GeometricRelationship to the one that suits your tool best.
  5. If you need to find features only on a particular layer you need to create a list of selectable feature layers and associated this to the selection MapAction.
  6. Write code against the StatusChanged event to perform some function against the selection result.

Setting the selection environment

The selection type will typically be set to envelope, although it an also be 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.CurrentMapAction = selectionMapAction1;

The other important selection setting will typically be the layers to select from. By specifying the selection layers one can develop a more focused selection tool, improve performance, and limit the results.

// Sets the selected feature layers array to the Selection MapAction 
selectionMapAction1.SelectionLayers = map1.MapLayers["Buildings"].Layer as FeatureLayer; 
// Sets map action to be selection map action 
map1.CurrentMapAction = selectionMapAction1;

Using the selection results

The selectionMapAction will wait for a user to make their selection on the map display and then populate a list of FeatureDataTables with the results. This list has one FeatureDataTable for each MapLayers with selected features.

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.FeatureLayer.Name); 
} 
//the tab opens on the first layer and use that to populate the grid
dataGridSelect.Parent = tabControlGrid.TabPages[0];
dataGridSelect.DataSource = selectionMapAction1.SelectedFeatures[0]; 
}


9/20/2011