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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@drecchia/maplibre-layer-control

v2.1.0

Published

MapLibre Layer Control, the best independent layer control tool.

Readme

LayersControl — MapLibre Layer Manager

A compact, modern, and extensible layer control for MapLibre GL JS, designed for production apps needing:

  • Fast, testable code with clear separation of concerns
  • Flexible UX: grouping, per-overlay and group opacity, pan-on-add
  • Dynamic data loading via renderOnClick (async overlays)
  • Deck.gl integration for high-performance overlays
  • State persistence (base, overlays, opacity, order, viewport)
  • Event-driven API for analytics, telemetry, or custom UI

UI interaction Dynamic loader


Features

  • Base map switching (setStyle or toggleBackground strategies)
  • Overlay grouping and group-level opacity
  • Per-overlay opacity sliders and status indicators (loading/error/zoom-filtered)
  • panOnAdd: fly to overlay location on enable
  • renderOnClick: async remote overlay loader (with caching and retry)
  • State persistence: base, overlays, opacity, order, viewport (via localStorage)
  • Event system for all state changes and overlay lifecycle
  • Works with MapLibre and optionally deck.gl

Installation

Include MapLibre GL JS, deck.gl, LayersControl JS, and CSS in your page:

<script src="https://unpkg.com/maplibre-gl/dist/maplibre-gl.js"></script>
<script src="https://unpkg.com/deck.gl/dist.min.js"></script>
<script src="path/to/layers-control.js"></script>
<link rel="stylesheet" href="path/to/main.css">

Usage (Minimal Example)

const baseStyles = [
  { id: 'osm', label: 'OpenStreetMap', style: 'https://demotiles.maplibre.org/style.json', strategy: 'setStyle' }
];

const overlays = [
  {
    id: 'traffic',
    label: 'Traffic Flow',
    deckLayers: [
      {
        id: 'traffic-lines',
        type: 'LineLayer',
        props: {
          data: [ /* your line data */ ],
          getSourcePosition: d => d.from,
          getTargetPosition: d => d.to,
          getColor: [255,0,0],
          getWidth: 2
        }
      }
    ],
    opacityControls: true,
    defaultVisible: false
  }
];

const layersControl = new LayersControl({
  baseStyles,
  overlays,
  defaultBaseId: 'osm',
  persist: { localStorageKey: 'my-app-layers' },
  position: 'top-right'
});

const map = new maplibregl.Map({
  container: 'map',
  style: LayersControl.getInitialStyle({
    baseStyles,
    defaultBaseId: 'osm',
    persist: { localStorageKey: 'my-app-layers' }
  }) || baseStyles[0].style,
  center: [0, 0],
  zoom: 2
});

map.on('load', () => {
  layersControl.addTo(map);
  const vp = LayersControl.getInitialViewport({ persist: { localStorageKey: 'my-app-layers' } });
  if (vp) map.jumpTo(vp);
});

Configuration

See docs/CONFIGURATION.md for all options and persisted state schema.

  • baseStyles: Array of base map styles (id, label, style, strategy)
  • overlays: Array of overlays (id, label, group, deckLayers, renderOnClick, opacityControls, etc.)
  • groups: Optional array for overlay grouping
  • persist: { localStorageKey } for state persistence
  • position: MapLibre control position
  • i18n: Label translation function
  • autoClose, showOpacity, showLegends: UI options

Supported Overlay Types

  • Only deckLayers and renderOnClick overlays are supported.
  • MapLibre source/layers overlays are NOT supported.

See docs/RENDER_ON_CLICK.md for the dynamic overlay contract.


Events

LayersControl emits events for all state changes and overlay lifecycle:

  • basechange, overlaychange, overlaygroupchange, change
  • loading, success, error
  • styleload, sourceloaded, viewportchange, zoomfilter, memorycleared

See docs/EVENTS.md for event payloads and usage.


Persistence

  • State is saved to localStorage under the configured key.
  • Persisted: baseId, overlays (visibility, opacity), groups, layerOrder, viewport.

CSS Customization

All UI classes are defined in src/css/main.css.
Override these classes in your own CSS for custom themes or layout.

See docs/CSS.md for a full class reference.


Reference & Further Documentation


License

MIT (see LICENSE)