Class: Legend

ol.legend. Legend

Legend class to draw features in a legend element


new Legend(options [, layer])

Parameters:
Name Type Argument Default Description
options *
Properties
Name Type Argument Default Description
title String

Legend title

maxWidth number <optional>

maximum legend width

size ol.size <optional>

Size of the symboles in the legend, default [40, 25]

margin number <optional>
10

Size of the symbole's margin, default 10

layer ol.layer.Base <optional>

layer associated with the legend

options.textStyle ol.style.Text <optional>
'16px sans-serif'

a text style for the legend, default 16px sans-serif

options.titleStyle ol.style.Text <optional>
'bold 16px sans-serif'

a text style for the legend title, default textStyle + bold

options.style ol.style.Style | Array.<ol.style.Style> | ol.StyleFunction | undefined

a style or a style function to use with features

Fires:
  • event:select
  • event:refresh

Methods


<static> getLegendImage(item, canvas, offsetY)

Get a symbol image for a given legend item

Parameters:
Name Type Description
item olLegendItemOptions
canvas Canvas | undefined

a canvas to draw in, if none creat one

offsetY int | undefined

Y offset to draw in canvas, default 0


addItem(item)

Add a new item to the legend

Parameters:
Name Type Description
item olLegendItemOptions | ol.legend.Item

getCanvas()

Get legend canvas

Returns:
Type
HTMLCanvasElement

getHeight()

Calculate the legend height

Returns:
Type
number

getItems()

Get item collection

Parameters:
Type Description
ol.Collection

getLegendImage(item, canvas, offsetY)

Get the image for a style

Parameters:
Name Type Description
item olLegendItemOptions
canvas Canvas | undefined

a canvas to draw in, if none create one

offsetY int | undefined

Y offset to draw in canvas, default 0

Returns:
Type
CanvasElement

getListElement()

Get legend list element

Returns:
Type
Element

getTextStyle()

Get text Style

Returns:
Type
ol.style.Text

getTitle()

Get legend title

Returns:
Type
string

getWidth()

Calculate the legend height

Returns:
Type
number

refresh()

Refresh the legend


removeItem(item)

Remove an item at index

Parameters:
Name Type Description
item ol.legend.Item

removeItemAt(index)

Remove an item at index

Parameters:
Name Type Description
index number

set(size)

Set legend size

Parameters:
Name Type Description
size ol.size

setLayer( [layer])

Set the layer associated with the legend

Parameters:
Name Type Argument Description
layer ol.layer.Layer <optional>

setStyle(style)

Set the style

Parameters:
Name Type Description
style ol.style.Style | Array.<ol.style.Style> | ol.StyleFunction | undefined

a style or a style function to use with features


setTitle(title)

Set legend title

Parameters:
Name Type Description
title string