Draw Graphic Elements
The purpose of this sample is to show how to draw graphic elements on screen and add these to a Graphic Layer as Graphic objects. The 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 inncludes comments to explain API being used.
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 user draws on screen. When the sample application starts, a MapView, TiledMapServiceLayer and GraphicsLayer are instantiated, a TouchListener is added to MapView and other Android UI elements (such as AlertDialog, Buttons) are instantiated as well.
When user selects a geometry type from the AlertDialog, the AlertDialog's onClick() handler method assigns appropriate symbology to the GraphicLayer's Renderer. The MapView's TouchListener class has handlers to listen to SingleTap, OnDranPointerMove and OnDragPointerUp events. These collect geometry based on 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 device is flipped or user switches to another application.
How to use sample?
1. Launch the sample in emulator or device.
2. Click "Select Geometry Type" button and select "Polygon" from the drop-down list.
3. Drag your mouse (emulator) or finger (device) across the screen to draw a polygon. To finish drawing, release the mouse button or finger from screen.
4. Select "Polyline" from drop down list and repeat 3. above to draw a polyline.
5. Select "Point". Click or tap on the map anywhere to draw a point.