Working with Symbols and Renderers

Symbols define all the non-geographic aspects of a Graphic's appearance. This includes a Graphic's color, border width, transparency, and more. The ArcGIS Runtime SDK for Android includes many symbol classes, each of which allows you to specify symbology in a unique way. Each symbol type is also specific to one geometry type (i.e. point, line, or polygon).

Symbol Types

The available Symbols and the geometries to which they apply are summarized in the table below:

Symbol

Geometry

Description

Symbol Class

Simple Marker Symbol

Point

Symbolizes points with simple shapes

SimpleMarkerSymbol

Picture Marker Symbol

Point

Symbolizes points with images

PictureMarkerSymbol

Simple Line Symbol

Polyline

Symbolizes lines with pre-defined styles

SimpleLineSymbol

Simple Fill Symbol

Polygon

Fills polygon with a variety of patterns

SimpleFillSymbol

Text Symbol

Poine, Polyline, or Polygon

Displays text labels for geometries

TextSymbol

All of the symbol classes above inherit from the Symbol interface.

Renderers

A renderer defines a set of symbols that will be used for graphics in a Graphics Layer. You can use renderers to symbolize features with different colors or sizes based on a the graphic's attribute values. To use a renderer, you create it, define the symbology you want, then set the renderer property of a Graphics Layer. Here is a class diagram of the types of renderers you can create:

Creating a Simple Renderer

A simple renderer uses the same symbol for every graphic. All you have to do is create the renderer with the desired symbol, then Graphics Layer’s renderer property.

// create a symbol for renderer
SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.BLUE, 5, STYLE.CROSS);
// instantiate a simple renderer with the symbol created above
SimpleRenderer simRenderer = new SimpleRenderer(sms);
// add the renderer to the graphics layer
gLayer.setRenderer(simRenderer);

Creating a Class Breaks Renderer

A class breaks renderer symbolizes each Graphic based on the value of some numeric attribute. Graphics with similar values for the attribute get the same Symbol. The “breaks” define the values at which the symbology changes.

The following code creates an ClassBreaksRenderer in order to symbolize cities according to size. There are three class breaks, the first is from MIN_POP to 50,000; the second is from 50,000 to 250,000; the last is from 250,000 to MAX_POP:

// instantiates a class break renderer
ClassBreaksRenderer cityPopRenderer = new ClassBreaksRenderer();
// set the attribute field used by renderer to match values 
cityPopRenderer.setField("POP1990");
// set the minimum population value = MIN_POP
cityPopRenderer.setMinValue(MIN_POP);
 
// create a class break representing the first
// low class break
ClassBreak lowClassBreak = new ClassBreak();
// set label as Low
lowClassBreak.setLabel("Low");
// set class break max value
lowClassBreak.setClassMaxValue(50000);
// set a pre-defined simple marker symbol
lowClassBreak.setSymbol(lowMarkerSymbol);
 
// create 2 more class breaks representing the
// mid and max class breaks
ClassBreak midClassBreak = new ClassBreak();
midClassBreak.setLabel("Middle");
midClassBreak.setClassMaxValue(250000);
midClassBreak.setSymbol(midMarkerSymbol);
ClassBreak highClassBreak = new ClassBreak();
highClassBreak.setLabel("High");
highClassBreak.setClassMaxValue(MAX_POP);
highClassBreak.setSymbol(maxMarkerSymbol);
 
// add class breaks to the class break renderer
cityPopRenderer.addClassBreak(lowClassBreak);
cityPopRenderer.addClassBreak(midClassBreak);
cityPopRenderer.addClassBreak(highClassBreak);
 
// add the class break renderer to the graphics layer
gLayer.setRenderer(cityPopRenderer);
1/24/2013