0.3.5 • Published 4 years ago

leaflet-html-legend v0.3.5

Weekly downloads
275
License
-
Repository
github
Last release
4 years ago

Leaflet.HtmlLegend

A simple Leaflet plugin for creating legends with HTML.

Tested with Leaflet 1.3.x

Install

From NPM:

npm install leaflet-html-legend

Usage

Include the CSS:

<link rel="stylesheet" href="L.Control.HtmlLegend.css" />

Include the JavaScript:

<script src="L.Control.HtmlLegend.min.js"></script>

Control Options:

OptionTypeDefaultDescription
positionString'topright'Map position of element
legendArray-Array of legend entries (see legend options below for details)
collapseSimpleboolfalseWhether to use compact presentation for legend entries that are from a simple renderer
detectStrechedboolfalseTest to see if legend entries look stretched (these are usually in sets of 3 with the middle element having no label)
collapsedOnInitboolfalseWhether to initialize instance in collapsed mode
updateOpacityfunctionnullIf set, this function is used to update opacity of the attached layer (it receives the layer and opacity as arguments)
defaultOpacitynumber1Default opacity for layers in specified in legends
removeIconString'leaflet-html-legend-icon-remove'css class for the remove icon
visibleIconString'leaflet-html-legend-icon-eye'css class for the visible icon on opacity slider
hiddenIconString'leaflet-html-legend-icon-eye-slash'css class for the hidden icon on opacity slider
toggleIconString'leaflet-html-legend-icon-eye-slash'css class for the icon on visibility toggle button

Legend Options:

OptionTypeDefaultDescription
nameString-Legend label
layerLeaflet layer-The leafel layer to connect to this legend. The legend can control the layer visiblity via opacity slider, if disableVisibilityControls is set to true
allowRemovebooleanfalseWhether to add a remove icon that allows removal of the legend from the control
disableVisibilityControlsboolfalseWhether to add visibility toggle button and opacity slider
elementsArray-Array of elements (see element options below for details)

Element options:

OptionTypeDefaultDescription
labelString-Entry label
htmlString-String representaiton of an HTML elemnt that goes into the legend block
styleObject-An object containing css styling of the legend block

You can use addLegend method to add legends to existing instances of HtmlLegend:

var htmlLegend = L.control.htmllegend({...});
htmlLegend.addLegend({
        name: 'Layer name',
        layer: layerInstance,
        elements: [{
            html: '<div>Legend description</div>'
        }]
    })

An existing entry in a legend control instance can be removed using removeLegend. This method needs id of the entry, which can be obtained from htmllegend._entries (see the example for usage).

See the example for usage details.

Contributors:

0.3.5

4 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago