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:
- Performs a spatial query using mouse events.
- Lets you perform different types of selections (point, envelope, or polygon).
- Supports different geometric relationships between the input geometry (mouse or stylus input) and the geometry of the features (intersect, contain, and so on).
- Selects from all layers or a specified set of layers.
- Provides a selection feedback that represents the mouse input (rubber banding).
- Lets you choose whether or not to display selected features. Developers might want to create a custom layer to draw these geometries. For more information see Developing custom layers.
- Provides a selection symbol that is used to draw selected features on the map.
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.
- To begin working with the SelectionMapAction, add the Map control to your application from the ArcGIS Mobile Controls tab within the Visual Studio toolbox.
- Declare a new instance of the SelectionMapAction.
- Specify the SelectionType as envelope (default), point, or polygon.
- Change the GeometricRelationship to the one that meets your requirements.
- Give the SelectionFeatureSources property one or more FeatureSources to use in the selection.
- 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.
- 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];
}