Customizing the appearance of objects on a map
The net.rim.device.api.lbs.maps.view package contains the Style and StyleSet classes, that you can use to customize the appearance of any mappable objects that are displayed on a map. By using styles, you can customize your maps and give them a uniform appearance in a way that is analagous to applying CSS styles.
The Style class provides the following properties that define the visual characteristics of mappable objects.
- Edge: Specifies properties for the edge around a mappable object (color, opacity, and size)
- Fill: Specifies properties for the internal area of a mappable object (color and opacity)
- Label: Specifies properties for the label of a mappable object (color and opacity of the fill, and the alignment, color, family name, opacity, size, and style of the font)
The Style class also contains constants for the edge size and text alignment (for example, EDGE_SIZE_LARGE, and FONT_ALIGNMENT_RIGHT). You can find constants related to the font and color in the Font and Color classes, respectively. Opacity is represented by an integer between 0 and 255, where 0 is transparent and 255 is opaque.
The StyleSet class represents a set of individual styles that a map uses to render mappable objects on a screen. Maps have a default style set that you can retrieve and override with your own styles.
A StyleSet object can include three different types of styles, a base style, a class style, and an ID style. The base style defines a style for all mappable objects. The class style defines a style for all mappable objects of a particular class. The ID style defines a style for all mappable objects of a particular ID. To assign an ID to a mappable object, you must invoke AbstractMappable.setStyleId() on the object.
You can also create styles that inherit properties from parent styles (for example, an ID style can inherit from a class or base style). To inherit a property from a parent style, you can specify one of the INHERIT constants (for example, COLOR_INHERIT or EDGE_SIZE_INHERIT ).
Defining styles and applying them to a style set
// Base style for the entire map. Style baseStyle = new Style(); baseStyle.setLabelFontFamilyName("arial"); styles.setBaseStyle( baseStyle ); // Style for the MapLocation class. Style classStyle = new Style(); classStyle.setLabelFillColor( Color.BLACK ); classStyle.setLabelFontColor( Color.WHITE ); classStyle.setEdgeColor( Color.WHITE ); styles.addClassBasedStyle( MapLocation.class, classStyle ); // Style for a specific ID. Style idStyle = new Style(); classStyle.setEdgeColor( Color.RED ); styles.addIdBasedStyle("ID_1", idStyle);