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 🙏

© 2026 – Pkg Stats / Ryan Hefner

maplibre-gl-mask-plugin

v0.2.1

Published

Add mask to a feature in Maplibre-gl

Readme

Maplibre-gl Mask Plugin

Add a mask around a geojson feature in Maplibre GL JS.

This plugin is inspired by this QGis Mask plugin


Demo

👉 Live Demo

Demo screenshot

Installation

Install maplibre-gl-mask-plugin with npm

npm install maplibre-gl-mask-plugin

Or use it from CDN

<script type="module" src="https://unpkg.com/maplibre-gl-mask-plugin/dist/index.js"></script>

Usage

import maplibregl from 'maplibre-gl';
import { createMask } from 'maplibre-gl-mask-plugin';
import geojsonFeature from './feature.geojson';

const map = new maplibregl.Map({
  container: 'map',
  style: 'https://tiles.openfreemap.org/styles/bright'
});

createMask(map, 'mask', geojsonFeature);

API Reference

createMask

import { createMask } from 'maplibre-gl-mask-plugin';
createMask(map, name, feature, options);

| Parameter | Type | Description | |-----------|------------------------------------|-------------------------------------------| | map | maplibregl.Map | Maplibre map instance | | name | string | Unique mask name | | feature | Feature<Polygon \| MultiPolygon> | Geojson feature (polygon or multipolygon) | | options | Partial<MaskOptions> | Mask options (see below) |

removeMask

import { removeMask } from 'maplibre-gl-mask-plugin';
removeMask(map, name);

| Parameter | Type | Description | |-----------|------------------------------------|-----------------------| | map | maplibregl.Map | Maplibre map instance | | name | string | Created mask name |

MaskOptions

| Option | Type | Default | |----------------|--------------------------|---------| | simplify | @turf/simplify options | - |

If the feature polygon need to be simplified, pass @turf/simplify options here. See turf/simplify documentation. Polygons with more than 1000 coordinates will have poor performance.

| Option | Type | Default | |-------------------|----------|---------| | backgroundColor | string | #FFF |

Mask background color (ex: "#FFF", or "yellow")

| Option | Type | Default | |---------------------|----------|---------| | backgroundOpacity | number | 0.7 |

Mask background opacity (between 0 and 1). Use 0 if no background is needed

| Option | Type | Default | |-------------------|----------|---------| | gradientColor | string | #AAA |

Mask gradient color (ex: "#AAA", or "black")

| Option | Type | Default | |--------------------|----------|---------| | gradientLayers | number | 30 |

Gradient layers number. More layers is smoother but slower to compute. Use 0 if no gradient is needed. Gradient is computed incrementally by increasing layers. For example with 30 layers, it will display progressively 2 -> 3 -> 5 -> 6 -> 10 -> 15 -> 30 layers once they are fully computed. Using a prime number or a number with less factors will disable or decrease incremental computation.

| Option | Type | Default | |----------------------|----------------------|---------------------| | gradientLayerWidth | number \| function | 40960 / 2^zoom |

Gradient layers width. Total gradient width is the number of layers * this width. Default layer width will vary with map zoom, which gives the following results:

  • z6: 640m
  • z10: 40m
  • z14: 2.5m

If a number is given, it will be a factor of the default width function. Use 0 if no gradient is needed.

A custom function can also be provided. It should be of type (zoom: number) => number. Result will be in meters.

| Option | Type | Default | |----------------|-----------|-----------| | hideLabels | boolean | true |

Determines if symbols and labels outside feature polygon should be hidden.

The behaviour when enabling this option is to hide all symbol layers in the current style, and clone them adding geographic filter matching the feature given.

Peer Dependencies

This library requires the following peer dependencies to be installed in your project:

License

MIT