XML - legend element
The legend element (along with the legendItem element), is used to describe map legends. The legend element can contain any number of legendItem elements. The legend element is a child of the cgview element.
The following sample CGView document shows how the legend element can be used to add text to a map:
<?xml version="1.0" encoding="ISO-8859-1"?>
<cgview backboneRadius="160" sequenceLength="50000" height="600" width="600">
<featureSlot strand="direct">
<feature color="green" decoration="clockwise-arrow" label="T7">
<featureRange start="21650" stop="21700" />
</feature>
<feature color="red" decoration="arc" label="SV40">
<featureRange start="40000" stop="40050" />
</feature>
</featureSlot>
<legend position="upper-center">
<legendItem text="A legend" font="Monospaced,plain,20" textAlignment="center" />
</legend>
<legend position="upper-right" font="SansSerif,plain,20">
<legendItem text="Promoter" drawSwatch="true" swatchColor="green" />
<legendItem text="Terminator" drawSwatch="true" swatchColor="red" />
</legend>
<legend position="lower-left">
<legendItem text="Another legend" font="Serif, bold, 20" fontColor="purple" />
</legend>
<legend position="lower-right">
<legendItem text="Created using CGView" font="SansSerif,bold-italic,20" />
</legend>
</cgview>
This is the map generated by the above document:
Required legend attributes
Attribute
|
Description
|
Values
|
-
|
-
|
-
|
|
Optional legend attributes
Attribute
|
Description
|
Values
|
Default value
|
allowLabelClash
|
Specifies whether or not feature labels should be drawn when they clash with this legend.
|
true - feature labels should be drawn when they clash with this legend.
false - feature labels should not be drawn when they clash with this legend.
|
false
|
backgroundColor
|
Sets the background color of this legend.
|
color
|
Inherited from the backgroundColor attribute of the parent cgview element.
|
backgroundOpacity
|
Sets the opacity of the background of this legend.
|
real between 0.0 and 1.0, with 0.0 being completely transparent.
|
1.0
|
drawWhenZoomed
|
Specifies whether or not this legend should be drawn when zoomed maps are generated.
|
true - this legend should be drawn when a zoomed map is generated.
false - this legend should not be drawn when a zoomed map is generated.
|
true
|
font
|
Sets the font used for the text in this legend. legendItem elements can override this setting using their own font attribute.
|
font
|
SansSerif, plain, 8
|
fontColor
|
Sets the color of the text used for this legend. legendItem elements can override this setting using their own fontColor attribute.
|
color
|
black
|
position
|
Specifies where this legend should be placed on the map canvas.
|
upper-left
upper-center
upper-right
middle-left
middle-center
middle-right
lower-left
lower-center
lower-right
|
upper-right
|
textAlignment
|
Specifies how text should be aligned inside this legend. legendItem elements can override this setting using their own textAlignment attribute.
|
left - text should be aligned to the left.
center - text should be aligned to the center.
right - text should be aligned to the right.
|
left
|
color = the color name (black for example), or the RGB values for the color (rgb(0,255,0) for example). The following color names are supported: aqua, black, blue, fuchsia, gray (and grey), green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow.
font = the name of the font, followed by the style, and then the size. An example font is Monospaced, bold, 50. Valid font names are: Default, Dialog, DialogInput, Monospaced, Serif, and SansSerif. Valid styles are: plain, bold, italic, and bold-italic.
integer = a whole number between -2,147,483,648 and +2,147,483,647.
real = a real number between 1.4e-45 and 3.4e+38.
Citing CGView:
|