RouteMAP IMS 3.0 Java API

Labeling and Drawing

There is an extensive set of methods which allow drawing several types of symbols or simple figures such as callouts, circles, ellipses, rectangles, or polygons on the map.

There are three basic types of objects: callouts, ellipses, and polygons.

The steps to add any symbol to the map are:
1) Create and initialize the object that represents your figure or symbol;
2) Get or create the Symbol object, that controls how the figure will be displayed;
3) Set optional attributes such as color, style, or size using auxiliary objects;
4) Add your symbol to the enumeration of the objects of type.

Let's see how to draw the most frequently used object, the Callout object:


// step 1
Callout callout = new Callout();

// step 2
Symbol symbol = new Symbol();

// step 3
Color color = new Color( 0xFF0000); // red
TextFont font = new TextFont();

symbol.setSize(30);
symbol.setColor( Symbol.SYMBOL_COLOR, color);

font.setColor( color);
font.setBold( true);
font.setUnderline( true);
font.setItalic( true);
font.setSize( 20);

// define the point on the map where callout will be displayed (pixels)
callout.setAnchor( map.toMapUnits( 250, 200));
callout.setOrientation( Callout.TOP_CENTER);
callout.setFont( font);
callout.setText( "Sample Callout");

// step 4
CosmeticLayer cLayer = map.getCosmeticLayer();
cLayer.getCallouts().add(callout);

The result should look like this:



Here is an example for drawing an ellipse:


// step 1
EllipseSymbol es = new EllipseSymbol();
GeoEllipse ellipse = new GeoEllipse();
ellipse.center = map.toMapUnits( 220, 160);
ellipse.height = map.convertDistance( 120, MeasureUnit.PIXELS, MeasureUnit.MAPUNITS);
ellipse.width = map.convertDistance( 200, MeasureUnit.PIXELS, MeasureUnit.MAPUNITS);
es.setEllipse(ellipse);

// step 2
Symbol symbol = es.getSymbol();

// step 3
Color color = new Color( 0, 0, 255); // blue
symbol.setColor(Symbol.BRUSH_COLOR, color);
symbol.setBrushStyle("brush:bdiagonal");

// step 4
CosmeticLayer cLayer = map.getCosmeticLayer();
cLayer.getEllipses().add(es);


This next example shows how to draw a polygon symbol:


// step 1
PolygonSymbol ps = new PolygonSymbol();

GeoPoint[] vertex = new GeoPoint[4];
vertex[0] = map.toMapUnits( 125, 300); // bottom/left
vertex[1] = map.toMapUnits( 125, 100); // top/left
vertex[2] = map.toMapUnits( 475, 100); // top/right
vertex[3] = map.toMapUnits( 475, 300); // bottom/right

GeoPointsImpl gp = new GeoPointsImpl();

for(int i = 0; i < vertex.length; i++)
    gp.addPoint( vertex[i].x, vertex[i].y);
    
ps.setPoints( gp);

// step 2	
Symbol symbol = ps.getSymbol();

// step 3
Color color = new Color( 0x0000FF); // blue
symbol.setColor(Symbol.BRUSH_COLOR, color);

color = new Color( 0xFF0000); // red
symbol.setColor(Symbol.SYMBOL_COLOR, color);

symbol.setBrushStyle("brush:bdiagonal");

// step 4
CosmeticLayer cLayer = map.getCosmeticLayer();
cLayer.getPolygons().add(ps);