Home Reference Source Repository
import {DiscreteLegend} from 'leaflet-coverage/'
public class | source



L.Control → DiscreteLegend

Displays a discrete palette legend for the parameter displayed by the given Coverage layer. Supports category parameters only at the moment.


Coverage data layer
new C.DiscreteLegend(covLayer).addTo(map)
// changing the palette of the layer automatically updates the legend 
covLayer.palette = C.discretePalette(['red', 'blue'])
Fake layer
var fakeLayer = {
  parameter: {
    observedProperty: {
      label: { en: 'Land cover' },
      categories: [{
        label: { en: 'Land' }
      }, {
        label: { en: 'Water' }
  palette: C.directPalette(['gray', 'blue']) // CSS colors in category order
var legend = new C.DiscreteLegend(fakeLayer).addTo(map)

// change the palette and trigger a manual update
fakeLayer.palette = C.discretePalette(['red', 'blue'])

Constructor Summary

Public Constructor

constructor(covLayer: object, options: object)

Creates a discrete legend control.

Method Summary

Public Methods


Triggers a manual update of the legend.

Public Constructors

public constructor(covLayer: object, options: object) source

Creates a discrete legend control.


covLayer object

The coverage data layer, or any object with palette and parameter properties. If the object has on/off methods, then the legend will listen for "paletteChange" events and update itself automatically. If the layer fires a "remove" event, then the legend will remove itself from the map.

options object
  • optional

Legend options.

options.position string
  • optional
  • default: 'bottomright'

The initial position of the control (see Leaflet docs).

options.language string
  • optional

A language tag, indicating the preferred language to use for labels.

options.templateId string
  • optional

Uses the HTML element with the given id as template.

Public Methods

public update() source

Triggers a manual update of the legend.

Useful if the supplied coverage data layer is not a real layer and won't fire the necessary events for automatic updates.