Skip To Content

Create a graphics layer

In this topic

Graphics layers allow you to dynamically display graphics on a map. A graphics layer can, for example, be used to hold polygons or lines drawn by a user, or display features that satisfy the results of a task such as query or geoprocessing. The GraphicsLayer class allows you to create a layer that can contain one or more graphic features.

Add a graphic layer

The API exposes two public constructors, one for an empty GraphicsLayer and one that allows you to set the spatial reference and full extent of the layer. Be aware that the empty constructor assumes you have a base map layer defined for the MapView as the GraphicsLayer cannot be the bottom most layer. Once you have created a GraphicsLayer, add it to the map with the MapView.addLayer() method as shown below:

The API exposes two public constructors, one for an empty GraphicsLayer and one that allows you to set the spatial reference and full extent of the layer. Be aware that the empty constructor assumes you have a base layer defined for the MapView as the GraphicsLayer cannot be the bottom most layer. Once you have created a GraphicsLayer you add it to the map with the MapView.addLayer() method as shown below:

// Inflate Mapview from XML
MapView mMapView = (MapView)findViewById(R.id.map);
...
// Create GraphicsLayer
GraphicsLayer gLayer = new GraphicsLayer();
// Add basemap layer first
mMapView.addLayer(basemap);
// Add empty GraphicsLayer
mMapView.addLayer(gLayer);

A MapView can contain one or many GraphicLayers. Adding graphics to your graphics layer is described in Managing graphic features.