Highlight features sample

Complexity: Beginner Data Requirement: ArcGIS Tutorial Data for Desktop

The purpose of this sample is to show how to highlight selected features on a map. This sample allows you to select a layer and identify features in that layer. The identified features are then highlighted on the map and a callout that contains information of the selected features is displayed. A GraphicLayer object is used to highlight the identified features.

Sample design

This sample has a MapView that has two layers: TiledMapServiceLayer and GraphicLayer. The TiledMapServiceLayer points to a map service on one of Esri's servers, while the GraphicsLayer holds graphic elements that highlight features selected as a result of an Identify operation. When the sample application starts, a MapView, TiledMapServiceLayer, and GraphicsLayer are instantiated, some listener methods (SingleTap and LongPress) are added to the MapView, and other Android user interface (UI) elements (such as AlertDialog and Buttons) are instantiated as well.

When you select a layer from the AlertDialog, then press the screen for 2 to 3 seconds (LongPress), an Identify task is executed using the selected layer and the press location. When IdentifyTask executes, features that are returned from the server as results are highlighted as graphic elements on the GraphicsLayer. A callout is also instantiated and displayed that includes details of the highlighted features. The MapView's onLongPress() handler executes the IdentifyTask, creates a Graphic object with appropriate symbology based on the layer's geometry type, and adds Graphic objects to the GraphicsLayer. This application also retains its state when the device is flipped or when you switch to another application.

Using the sample

Steps:
  1. Launch the sample on a supported device.
  2. Press the Select Layer button and select a layer from the drop-down list.
  3. Identify a feature in the selected layer by pressing a feature for 2 to 3 seconds (LongPress).

    If multiple features are identified, all will be highlighted. A callout containing details about the identified features is displayed.

  4. Press the Clear button to clear all selections.
5/31/2012