Adding line graphics

Lines are added to a graphics layer in four stages:

  1. Creating a line symbol which represents the presentation of the line (line style, color, and size).
  2. Creating a line geometry using the Polyline class. There are methods which enable a line to be built up from a series of points as shown in the code below.
  3. Creating a graphic using the defined line style and line geometry.
  4. Adding the graphic to the graphics layer.

The following code snippet shows how to add a line graphic which represents the path of a boat:

//create a line symbol (green, 3 thick and a dash style)
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(Color.green, 3, SimpleLineSymbol.Style.DASH);
 
//create the line geometry
Polyline lineGeometry = new Polyline();
lineGeometry.startPath(-302557,7570663);
lineGeometry.lineTo(-302959,7570868);
lineGeometry.lineTo(-303042,7571220);
lineGeometry.lineTo(-302700,7571803);
lineGeometry.lineTo(-304043,7576654);
lineGeometry.lineTo(-300544,7585289);
lineGeometry.lineTo(-294365,7592435);
lineGeometry.lineTo(-290122,7594445);
lineGeometry.lineTo(-285283,7595488);
 
//create the graphic using the geometry and the symbol
Graphic lineGraphic = new Graphic(lineGeometry, lineSymbol);
 
//add the graphic to the graphics layer
myGraphicsLayer.addGraphic(lineGraphic);

The code will result in a line which looks like this:

Screenshot of a line graphic

2/7/2013