Draw graphic elements sample

Complexity: Beginner Data Requirement: ArcGIS Tutorial Data for Desktop

The purpose of this sample is to show how to draw graphic elements on the screen and add these to a graphic layer as graphic objects. This sample allows users to draw different shapes (polygon, polyline, point) on the screen. These shapes are then added to a graphic layer and displayed on a map. The sample code includes comments to explain the application programming interface (API) being used.

Sample design

This sample has a MapView, which has two layers (that is, a TiledMapServiceLayer and GraphicsLayer). The TiledMapServiceLayer points to a map service on one of Esri's servers, while the GraphicsLayer holds graphic elements that a user draws on the screen. When the sample application starts, a MapView, TiledMapServiceLayer, and GraphicsLayer are instantiated. A TouchListener is added to a MapView and other Android user interface (UI) elements (AlertDialog, Buttons) are also instantiated.

When a user selects a geometry type from the AlertDialog, the AlertDialog's onClick() handler method assigns the appropriate symbology to the GraphicLayer's renderer. The MapView's TouchListener class has handlers to listen to SingleTap, OnDragPointerMove, and OnDragPointerUp events. These collect geometry based on the user's actions on the screen and assign this geometry to a graphic object, which is then added to the GraphicsLayer. This application also retains its state when the device is flipped or the user switches to another application.

Using the sample

Steps:
  1. Start the sample on your device.
  2. Click the Select Geometry Type button and select Polygon from the drop-down list.
  3. Drag your finger across the screen to draw a polygon. To finish drawing, release the mouse button or finger from the screen.
  4. Select Polyline from the drop-down list and repeat Step 3 to draw a polyline.
  5. Select Point. Click or tap anywhere on the map to draw a point.
5/31/2012