Class: Legend

ol.control. Legend


new Legend(options)

Create a legend for styles

Parameters:
Name Type Description
options *
Properties
Name Type Description
className String

class of the control

title String

Legend title

size ol.size | undefined

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

margin int | undefined

Size of the symbole's margin, default 10

collapsed boolean | undefined

Specify if attributions should be collapsed at startup. Default is true.

collapsible boolean | undefined

Specify if attributions can be collapsed, default true.

target Element | string | undefined

Specify a target if you want the control to be rendered outside of the map's viewport.

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

a style or a style function to use with features

Fires:
  • event:select

Extends

Methods


addRow(options)

Add a new row to the legend

  • You can provide in options:
  • a feature width a style
  • or a feature that will use the legend style function
  • or properties ans a geometry type that will use the legend style function
  • or a style and a geometry type
Parameters:
Name Type Description
options *

a list of parameters

Properties
Name Type Description
feature ol.Feature

a feature to draw

style ol.style.Style

the style to use if no feature is provided

properties *

properties to use with a style function

typeGeom string

type geom to draw with the style or the properties


getLength()

Get a legend row

Returns:
Type
int

getRow(index)

Get a legend row

Parameters:
Name Type Description
index int
Returns:
Type
*

getStyleImage(options, canvas, row)

Get the image for a style You can provide in options:

  • a feature width a style
  • or a feature that will use the legend style function
  • or properties and a geometry type that will use the legend style function
  • or a style and a geometry type
Parameters:
Name Type Description
options *
Properties
Name Type Description
feature ol.Feature

a feature to draw

style ol.style.Style

the style to use if no feature is provided

properties *

properties to use with a style function

typeGeom string

type geom to draw with the style or the properties

canvas Canvas | undefined

a canvas to draw in

row int | undefined

row number to draw in canvas

Returns:
Type
CanvasElement

hide()

Hide control


refresh()

Refresh the legend


removeRow(index)

Remove a row from the legend

Parameters:
Name Type Description
index int

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


show()

Show control


toggle()

Toggle control