Class: Legend

Legend

The Legend contains the legendItems for the maps and can be placed anywhere on the canvas or map.

Action and Events

Action Viewer Method Legend Method Event
Update - update() legends-update
Read legend - -

Attributes

Attribute Type Description
position String|Object Where to draw the legend [Default: 'top-right']. See Position for details.
anchor String|Object Where to anchor the legend box to the position [Default: 'auto']. See Anchor for details.
defaultFont String A string describing the default font [Default: 'SansSerif, plain, 8']. See Font for details.
defaultFontColor String A string describing the default font color [Default: 'black']. See Color for details.
defaultMinArcLength Number Default minimum length in pixels to use when drawing arcs. From 0 to 2 pixels [Default: 1]
textAlignment String Alignment of legend text: left, or right [Default: 'left']
backgroundColor String A string describing the background color of the legend [Default: 'white']. See Color for details.
onic String Place the legend relative to the 'canvas' or 'map' [Default: 'canvas']
itemsiu Array Array of legend item data.
visible Boolean Legend is visible [Default: true]
meta Object Meta data

ic Ignored on Legend creation iu Ignored on Legend update

Examples

new Legend(viewer, options, meta)

Create a new Legend.

Name Type Description
viewer Viewer

The viewer

options Object

Attributes used to create the legend

meta Object optional

User-defined Meta data to add to the legend.

Extends

Members

anchorAnchor

Get or set legend anchor

backgroundColorColor

Get or set the backgroundColor. When setting the color, a string representing the color or a Color object can be used. For details see Color.

canvasCanvas

Get the canvas.

defaultFontFont

Get or set the default font. When setting the font, a string representing the font or a Font object can be used. For details see Font.

defaultFontColorColor

Get or set the defaultFontColor. When setting the color, a string representing the color or a Color object can be used. For details see Color.

defaultMinArcLengthNumber

Get or set the defaultMinArcLength for legend items. The value must be between 0 to 2 pixels [Default: 1]. Minimum arc length refers to the minimum size (in pixels) an arc will be drawn. At some scales, small features will have an arc length of a fraction of a pixel. In these cases, the arcs are hard to see. A minArcLength of 0 means no adjustments will be made.

layoutLayout

Get the layout.

metaBoolean

Get or Set the meta data of this object. See the meta data tutorial for details.

onString

Get or set where the legend should be position: 'canvas', 'map'

positionPosition

Get or set the position

sequenceSequence

Get the sequence.

textAlignmentString

Get or set the text alignment. Possible values are left, or right.

viewerViewer

Get the viewer.

visibleBoolean

Get or Set the visibility of this object.

Methods

addItems(data){CGArray.<LegendItem>}

Add one or more legendItems (see attributes). See adding records for details

Name Type Description
data Object | Array

Object or array of objects describing the legendItems

Returns:
Type Description
CGArray.<LegendItem> CGArray of added legendItems

clear()

Clear the box containing the legend

inherited deleteFromObjects()

Remove the object from Viewer.objects

findLegendItemByName(name){LegendItem}

Find the legendItem with the provided name or return undefined.

Name Type Description
name String

Name of legendItem

Returns:
Type Description
LegendItem Returns undefined if not found

findLegendItemOrCreate(name, color, decoration){LegendItem}

Find the legendItem with the provided name or create a new legendItem.

Name Type Default Description
name String Unknown

Name of legendItem

color Color null

Use this color if creating a new legendItem

decoration String arc

Use this decoration if creating a new legendItem

Returns:
Type Description
LegendItem

invertColors()

Invert colors of all legendItems

Returns a CGArray of legendItems or a single legendItem. See reading records for details.

Name Type Description
term Integer | String | Array

See CGArray.get for details.

Returns:
Type Description
LegendItem | CGArray

moveItem(oldIndex, newIndex)

Move a legendItem from one index to a new one

Name Type Description
oldIndex Number

Index of legendItem to move (0-based)

newIndex Number

New index for the legendItem (0-based)

moveTo(duration)

Move to the Legend position (if it's position on the map)

Name Type Description
duration Number

Duration of the animation

removeItems(items)

Remove legendItems. See removing records for details

Name Type Description
items LegendItem | Array

legendItem or a array of legendItems to remove

toJSON()

Returns JSON representing the object

toString(){String}

Return the class name as a string.

Returns:
Type Description
String
  • 'Legend'

update(attributes)

Update legend attributes. See updating records for details.

Name Type Description
attributes Object

Object describing the properties to change

updateItems(itemsOrUpdates, attributes)

Update attributes for one or more legendItems. See updating records for details.

Name Type Description
itemsOrUpdates LegendItem | Array | Object

legendItem, array of legendItems or object describing updates

attributes Object

Object describing the properties to change