npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mmr-gl-legend

v0.0.13

Published

This module adds legend control which is able to create legend panel from MMR GL style to mmr-gl-legend

Downloads

91

Readme

mmr-gl-legend

This module adds legend control which is able to create legend panel from MMR GL style to mmr-gl. It was forked from maplibre-gl-legend.

This module is using source code of orangemug/legend-symbol. I just adopted this library to normal MMR GL Plugin. Thanks so much to develop this library!

Installation:

npm i mmr-gl-legend

Demo:

demo.gif

Usage:

import { MMRLegendControl } from "mmr-gl-legend";
import 'mmr-gl-legend/dist/maplibre-gl-legend.css';
import mmrgl from 'mmr-gl';

const map = new mmrgl.Map();
//please add legend control after loading mapbox stylefiles, otherwise it causes errors...
map.on('load', function() {
  const targets = {
    'subway entrance icon-hoverable': 'Subway',
  };
  
  // add legend control without checkbox, and it will be hide as default
  map.addControl(new MMRLegendControl(targets, {
    showDefault: false,
    showCheckbox: false,
    onlyRendered: false
  }), 'top-right');
  
  // add legend control with checkbox, and it will be shown as default
  map.addControl(new MMRLegendControl(targets, {showDefault: true}), 'bottom-right');
  
  // add legend control with all layers, and it reverse layer order
  map.addControl(new MMRLegendControl({}, {reverseOrder: false}), 'bottom-left');
})

Specify your layers which you want to add the legend by the control.

Options

  • showDefault
    • true: Legend will be shown as default
    • false: Legend will be hide as default
    • default value is true if you don't specify the option.
  • showCheckbox
    • true: the checkbox for switching visibility will be added as default
    • false: the checkbox will not be added as default
    • default value is true if you don't specify the option.
  • reverseOrder
    • true: layers will be ordered from top.
    • false: layers will be ordered from bottom.
    • default value is true if you don't specfify the option.
  • onlyRendered
    • true: only rendered layers will be shown on legend as default.
    • false: all layers' legend will be shown as default.
    • default value will be true.
  • title
    • the text shown above the icons
    • default: "Legend"

Use CDN

<script src="https://unpkg.com/[email protected]/dist/mmr-gl.js"></script>
<link href="https://unpkg.com/[email protected]/dist/mmr-gl.css" rel="stylesheet" />

<script src="./dist/mmr-gl-legend.umd.js"></script>
<link href="./dist/mmr-gl-legend.css" rel="stylesheet" />

<script>
  map.on('load', function() {
      const targets = {
          'subway entrance icon-hoverable': 'Subway',
      };
      map.addControl(new MMRLegendControl.MMRLegendControl(targets, {
          showDefault: false, 
          showCheckbox: false, 
          onlyRendered: true,
          reverseOrder: true
      }), 'top-right');
  })
</script>

Furthermore, you may download specific version's scripts and css locally from NPM page.

See an example HTML at index_umd.html

Development

npm run lint
npm run format
npm run dev

open http://localhost:5173.

If there are any changes on source code, it will be reflected automatically.

Build package

npm run build

The modules will be generated under dist folder.