Select features sample

Complexity: Intermediate Data Requirement: ArcGIS.com

The purpose of this sample is to show how to select features in a feature layer using an envelope created by dragging a box on the map. The envelope is used in a spatial query with an additional WHERE clause so that only certain features are selected (in this case, Gas Fields only).

Sample design

In the Activities onCreate() method, the feature layer is set up with its options (mode) and selection symbol. The MyTouchListener class (which extends MapOnTouchListener) listens for touch events. In this case, via the onDragPointerMove() method, in which an envelope graphic is added to the map as the user's finger moves across the screen. In the onDragPointerUp() method, the envelope geometry is retrieved and used to set up a Query object with a String based WHERE clause. The other necessary parameters required for the query are added, including the spatial reference and spatial relationship. The query is used in the selectFeatures() method on the feature layer, which returns the results and automatically renders the selected features using its selection renderer.

Using the sample

Steps:
  1. Upload the sample on your device.
  2. Long press on the map and drag a rectangle around the polygons you want to select.
  3. If the polygons satisfy the WHERE clause and spatial intersection, the polygon will be selected and highlighted in pink.
5/31/2012