Skip To Content ArcGIS for Developers Sign In Dashboard

Add graphics and text to graphics overlays

A graphic is a visible item on your map that can be seen as a point, line, polygon, or text. You can add graphics to your map view. These are contained in graphics overlays and are for showing temporary data that's not persisted once the application closes. For example, you may want to display a route between two locations or animate data items that change quickly.

This topic discusses adding graphics to your map in a way that generates a symbol instance for each graphic. If you're drawing a large number of graphics with the same symbology, then you should consider applying a renderer to the graphics overlay instead, which allows you to define the appearance of all the graphics in the overlay. Using renderers to add graphics is discussed in Symbols and renderers.

The image below shows an example of graphics drawn over a gray basemap. The graphics are showing:

  • Red markers showing location of buoys
  • Text symbols adding names to the islands of Craigleith and Bass Rock
  • A green cross hatched polygon showing a Gannet nesting ground on Bass Rock
  • A purple line showing the path of a boat trip.

Example of a map with multiple graphic overlays.

For more information on graphics and when to use them, see Features and graphics. For more information on graphics overlays, see Add graphics overlays to your app.

Add point graphics

The following steps show how to create the red buoy markers on the image above.

  1. The location of point graphics is represented by the Point geometry class. The following code shows how the buoy locations are defined:

    SpatialReference SPATIAL_REFERENCE = SpatialReferences.getWgs84();
    Point buoy1Loc = new Point(-2.72, 56.065, SPATIAL_REFERENCE);
    Point buoy2Loc = new Point(-2.69, 56.065, SPATIAL_REFERENCE);
    Point buoy3Loc = new Point(-2.66, 56.065, SPATIAL_REFERENCE);
    Point buoy4Loc = new Point(-2.63, 56.065, SPATIAL_REFERENCE);

    The points are defined in the WGS84 spatial reference, which is generally the spatial reference you would obtain from a GPS receiver, for example.


    If the spatial reference of the geometry of a graphic is null, then it is assumed the geometry is in the same spatial reference as the map view; if your graphics do not display as expected and have a null spatial reference, check that the coordinates of your geometry use the same spatial reference as the map view. If the spatial reference is set, and is different to that of the map view, geometries are automatically reprojected for display. For maximum efficiency, especially when dealing with large numbers of graphics or moving graphics, geometries of graphics should have the same spatial reference as the map view.

  2. Define what the points look like. Points can be drawn as simple marker symbols (circles, crosses, diamonds, etc.) or picture marker symbols represented by small bitmap images.

    The code below shows how to define a red circle.

    // create a red (0xFFFF0000) circle simple marker symbol
    SimpleMarkerSymbol redCircleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xFFFF0000, 10);

  3. Create graphics, which are defined by the point geometry and the symbol.

    // create graphics and add to graphics overlay
    Graphic buoyGraphic1 = new Graphic(buoy1Loc, redCircleSymbol);
    Graphic buoyGraphic2 = new Graphic(buoy2Loc, redCircleSymbol);
    Graphic buoyGraphic3 = new Graphic(buoy3Loc, redCircleSymbol);
    Graphic buoyGraphic4 = new Graphic(buoy4Loc, redCircleSymbol);

  4. Add the graphics to the graphics overlay, which will display them on the map view.

    graphicsOverlay.getGraphics().addAll(Arrays.asList(buoyGraphic1, buoyGraphic2, buoyGraphic3, buoyGraphic4));

Add line graphics

The following steps show how to create the purple, dashed line representing the boat trip in the image near the top of this topic.

  1. The geometry for the boat trip is represented by the Polyline class. This is built with a collection of points used to define the vertices of the line.

    // create a new point collection for polyline
    PointCollection points = new PointCollection(SPATIAL_REFERENCE);
    // create and add points to the point collection
    points.add(new Point(-2.715, 56.061));
    points.add(new Point(-2.6438, 56.079));
    points.add(new Point(-2.638, 56.079));
    points.add(new Point(-2.636, 56.078));
    points.add(new Point(-2.636, 56.077));
    points.add(new Point(-2.637, 56.076));
    points.add(new Point(-2.715, 56.061));
    // create the polyline from the point collection
    Polyline polyline = new Polyline(points);

    For more information on drawing lines using the geometry API, see Geometries.

  2. Define the symbol for the boat trip using the SimpleLineSymbol class.

    The code below defines this as a purple dashed line.

    //define a line symbol
    SimpleLineSymbol lineSymbol = 
        new SimpleLineSymbol(
            Color.argb(255, 255, 128, 0), 4, 1.0f);

  3. Create the graphic from the line geometry and line symbol.

    // create the graphic with polyline and symbol
    Graphic graphic = new Graphic(polyline, lineSymbol);

  4. Add the graphic to the graphics overlay.

    // add graphic to the graphics overlay

Add polygon graphics

The following steps show how to create the polygon representing the nesting ground area in the image near the top of this topic.

  1. The geometry for the nesting ground is defined using the Polygon class. The vertices of the polygon are created from a collection of points. For more information on building polygons, see Geometries.

    // create a new point collection for polygon
    PointCollection points = new PointCollection(SPATIAL_REFERENCE);
    // create and add points to the point collection
    points.add(new Point(-2.6425, 56.0784));
    points.add(new Point(-2.6430, 56.0763));
    points.add(new Point(-2.6410, 56.0759));
    points.add(new Point(-2.6380, 56.0765));
    points.add(new Point(-2.6380, 56.0784));
    points.add(new Point(-2.6410, 56.0786));
    // create the polyline from the point collection
    Polygon polygon = new Polygon(points);

  2. Define a symbol for the polygon. The symbol in the screen shot above is made up of a line symbol for the outline and a fill symbol for the polygon fill.

    //define the fill symbol and outline
    SimpleLineSymbol outlineSymbol = 
        new SimpleLineSymbol(
            Color.argb(255, 0, 0, 128), 1, 1.0f);
    SimpleFillSymbol fillSymbol = 
        new SimpleFillSymbol(
            Color.argb(255, 0, 80, 0, 255), 
            outlineSymbol, 1.0f);

  3. Create the graphic from the polygon geometry and fill symbol.

    // create the graphic with polyline and symbol
    Graphic graphic = new Graphic(polygon, fillSymbol);

  4. Add the polygon graphic to the graphics overlay.

    // add graphic to the graphics overlay

Add text

The following steps show how to add the "Craigleith" and "Bass Rock" text to the graphics overlay.

  1. The geometry for text symbols is a point. The point represents the anchor point for the text. The following code defines the anchor points for the two text symbols in the image at the top of this topic.

    // create two points
    Point bassPoint = new Point(-2.64, 56.079, SPATIAL_REFERENCE);
    Point craigleithPoint = new Point(-2.72, 56.076, SPATIAL_REFERENCE);

  2. Create the symbols for the text items.

    //create text symbols
    TextSymbol bassRockSymbol = 
        new TextSymbol(
            10, "Bass Rock", Color.argb(255, 0, 0, 230), 
            HorizontalAlignment.LEFT, VerticalAlignment.BOTTOM);
    TextSymbol craigleithSymbol = 
        new TextSymbol(
            10, "Craigleith", Color.argb(255, 0, 0, 230), 
            HorizontalAlignment.RIGHT, VerticalAlignment.TOP);

  3. Create the graphics from the point and text symbol.

    // create two graphics from the points and symbols
    Graphic bassRockGraphic = new Graphic(bassPoint, bassRockTextSymbol);
    Graphic craigleithGraphic = new Graphic(craigleithPoint, craigleithTextSymbol);

  4. Add the text graphics to the graphics overlays.

    // add graphics to the graphics overlay

Identify graphics

In your app, you can add code to allow users to click on a graphic and get more information about it. For example, you may tap or click on a seabird in your graphics overlay to display the name of the bird's species in a dialog box.

The identifyGraphicsOverlay method on the map view allows you identify graphics at a point on the map for a given graphics overlay. If you have more than one graphics overlay and want to perform an identify operation on all graphics overlays, use the identifyGraphicsOverlays method. The example below shows how you can perform an identify on a single graphics overlay in response to a tap on the map view.

//set a custom touch listener on the MapView
mapView.setOnTouchListener(new MapTouchListener(this, mapView));

//define custom touch listener class, overriding the onSingleTapConfirmed method
class MapTouchListener extends DefaultMapViewOnTouchListener {
  public MapTouchListener(Context context, MapView mapView) {
    super(context, mapView);

  public boolean onSingleTapConfirmed(MotionEvent e) {
    //get the tapped location in screen coordinates. screenPoint = new e.getX(), (int) e.getY());
    //use the screen location to perform the identify
    final ListenableFuture<List<Graphic>> identifyGraphics = mapView.identifyGraphicsOverlay(graphicsOverlay, 
        screenPoint, 10, 2);
    //wait for the results to be returned.
    identifyGraphics.addDoneListener(new Runnable() {
      public void run() { 
    return true;

You can iterate through each result returned from an identify. For example, you can display a list of the attribute values from each result.

Select graphics

Selecting a graphic is a way of bringing it to the attention of a user by drawing a halo around it. Change the selection state of a graphic by using the setSelected method on the Graphic class.

Example of a graphic with a selection halo.

Update graphics

It's possible to update the geometry or attributes of a graphic by using the graphics collection of the graphics overlay. The code below sets a new geometry on a graphic (grItem).

// create a point from location clicked
mapView.setOnMouseClicked(e -> {
  if (e.getButton() == MouseButton.PRIMARY) {
    Point2D mapViewPoint = new Point2D(e.getX(), e.getY());
    // add new location to selected graphic
    Point mapPoint = mapView.screenToLocation(mapViewPoint);

Remove graphics

To remove graphics you work with the graphics collection and call the remove method.