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

mapboxgl-comparison

v1.0.1

Published

[![npm version](https://badge.fury.io/js/mapboxgl-comparison.svg)](https://www.npmjs.com/package/mapboxgl-comparison) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Readme

mapboxgl-comparison

npm version License: MIT

A lightweight, high-performance comparison layer for Mapbox GL JS. Overlay and compare raster tile sources using WebGL shaders — without the overhead of multiple map instances.

Features

  • Single map instance — No duplicate maps or data, just efficient shader-based rendering
  • Dual-axis comparison — Control visibility via both X and Y offsets
  • WebGL-powered — GPU-accelerated rendering for smooth performance
  • TypeScript support — Full type definitions included
  • Framework-agnostic — Works with vanilla JS, React, Vue, or any framework

Installation

npm install mapboxgl-comparison mapbox-gl

Requirements

  • mapbox-gl: ^3.3.0 or higher
  • Modern browser with WebGL support

Quick Start

import mapboxgl from "mapbox-gl";
import { ComparisonLayer } from "mapboxgl-comparison";

mapboxgl.accessToken = "YOUR_MAPBOX_TOKEN";

const map = new mapboxgl.Map({
  container: "map",
  style: "mapbox://styles/mapbox/streets-v12",
  center: [-74.5, 40],
  zoom: 9,
});

// Create the comparison layer
const comparisonLayer = new ComparisonLayer(
  "comparison-layer",      // Unique layer ID
  "overlay-source",        // Source ID for the overlay tiles
  {
    type: "raster",
    tiles: ["https://tile.waymarkedtrails.org/hiking/{z}/{x}/{y}.png"],
  },
  { offsetX: 0.5, offsetY: 0 }  // Initial position (0-1 range)
);

// Add to map
map.once("load", () => {
  map.addLayer(comparisonLayer);
});

// Update position dynamically
comparisonLayer.updateData({ offsetX: 0.7, offsetY: 0 });

API Reference

ComparisonLayer

A custom Mapbox GL JS layer for comparing raster tile sources.

Constructor

new ComparisonLayer(
  id: string,              // Unique layer identifier
  sourceId: string,        // Source ID for overlay tiles
  tileJson: RasterSource,  // Mapbox raster source specification
  data: {                  // Initial offset configuration
    offsetX: number;       // Horizontal offset (0-1)
    offsetY: number;       // Vertical offset (0-1)
  }
)

Methods

| Method | Description | |--------|-------------| | updateData(data) | Updates the offset values and triggers a repaint | | onRemove() | Cleans up resources when layer is removed |

Properties

| Property | Type | Description | |----------|------|-------------| | id | string | Layer identifier | | sourceId | string | Overlay source identifier | | type | "custom" | Mapbox layer type |

How It Works

Unlike mapbox-gl-compare, which creates two separate map instances, this library uses a single map with a custom WebGL layer. The overlay raster tiles are rendered via fragment shaders, with visibility controlled by offsetX and offsetY uniforms.

This approach offers:

  • Lower memory usage — One map instance instead of two
  • Better performance — No synchronization overhead between maps
  • Simpler API — Just update offset values to control visibility

Use Cases

  • Compare historical vs. current imagery
  • Overlay sensor data on base maps
  • Visualize before/after scenarios
  • Display alternative routing options

Browser Support

Requires WebGL support. Compatible with all modern browsers:

  • Chrome 60+
  • Firefox 55+
  • Safari 11+
  • Edge 79+

License

MIT © Vinicius Carra

Acknowledgments

Inspired by Stamen's work on raster map shaders.