Highlight Features Sample

Complexity: Beginner Data Requirement: ArcGIS Tutorial Data Setup

Purpose of the sample

The purpose of this sample is to show how to highlight features in map that are selected by user. The sample allows users to select a layer and identify features in that layer. The identified features are then highlighted on the map and a Callout, that holds information of all features selected, is displayed. A GraphicLayer object is used to highlight identified features.

Sample Design:

This sample has a MapView which has two layers: a 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 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 MapView and other Android UI elements (such as AlertDialog, Buttons) are instantiated as well.

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

How to use sample?

1. Launch the sample in emulator or device.

2. Click "Select Layer" button and select a layer from the drop-down list.

3. Identify a feature in selected layer by pressing finger on a feature for about 2-3 seconds (LongPress). If multiple features are identified, all will be highlighted. A Callout will hold details about all identified features.

4. Use the "Clear" button to clear all selections.

Steps: