Git Product home page Git Product logo

leaflet.htmllegend's Introduction

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>

Options:

Option Type Default Description
position String 'topright' Map position of element
legend Array - Array of legend entries (see below for the structure)
collapseSimple bool false Whether to use compact presentation for legend entries that are from a simple renderer
detectStreched bool false Test to see if legend entries look stretched (these are usually in sets of 3 with the middle element having no label)
collapsedOnInit bool false Whether to initialize instance in collapsed mode
disableVisibilityControls bool false Whether to add visibility toggle button and opacity sliders
updateOpacity function null If set, this function is used to update opacity of the attached layer (it receives the layer and opacity as arguments)
defaultOpacity number 1 Default opacity for layers in specified in legends
visibleIcon String 'leaflet-html-legend-icon-eye' css class for the visible icon on opacity slider
hiddenIcon String 'leaflet-html-legend-icon-eye-slash' css class for the hidden icon on opacity slider
toggleIcon String 'leaflet-html-legend-icon-eye-slash' css class for the icon on visibility toggle button

Each entry in legends array can have the following keys:

  • name
  • array of elements

Each element has:

  • label (optional)
  • html (optional): string representaiton of an HTML elemnt that goes into the legend block
  • style (optional): 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:

leaflet.htmllegend's People

Contributors

devlet avatar jon-harald avatar ka7eh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.