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

leaflet-compare

v1.0.1

Published

Compare two Leaflet layers side by side

Downloads

385

Readme

leaflet-compare

A Leaflet control to add a split screen to compare two map overlays.

This project is a fork of the fork (leaflet-splitmap) of the leaflet-side-by-side plugin

screencast example

L.control.compare(leftLayer[s], rightLayer[s], options)

Creates a new Leaflet Control for comparing two layers or collections of layers. It does not add the layers to the map - you need to do that manually. Extends L.Control but setPosition() and getPosition() are used differently compared to a normal L.Control object. Currently setPosition(offset) sets the position of the slider by a given offset between 0 and 1. getPosition() returns the position of the slider in pixels. The latter can be converted to a slider offset between 0 and 1 by dividing by map.getSize().x.

Parameters

| parameter | type | description | | ---------- | -------------- | ------------- | | leftLayers | L.Layer|array | A Leaflet Layer or array of layers to show on the left side of the map. Any layer added to the map that is in this array will be shown on the left | | rightLayers | L.Layer|array | A Leaflet Layer or array of layers to show on the right side of the map. Any layer added to the map that is in this array will be shown on the right. These should not be the same as any layers in leftLayers | | options | Object | Options | | options.thumbSize | Number | Width of the slider thumb in pixels. Defaults to 44 | | options.padding | Number | Padding between slider min/max and the edge of the screen in pixels. Defaults to 0 | | options.position | Number | Initial position of the slider given by a number between 0 (left/min) and 1 (right/max) for. Defaults to 0.5 |

Events

Subscribe to events using these methods

| Event | Data | Description | | ---------- | -------------- | ------------- | | dividermove | {x: Number} | Fired when the divider is moved. Returns an event object with the property x = the pixels of the divider from the left side of the map container. |

Example

Live Example see source

Installation

leaflet-compare is compatible with Leaflet 1.7.1 but should also work with older versions.

To install it you can use npm:

npm install leaflet-compare

Then import it in your project:

import "leaflet-compare"

This will assign the Compare class to the L.Control namespace and the factory function compare to the L.control namespace.

As an alternative you can import the Compare class directly:

import { Compare } from "leaflet-compare"

Be sure to have included the Leaflet css and js files and the plugin's files leaflet-compare.css before you use the plugin. Otherwise the slider will not be shown.

Usage in the browser without ES6 imports

You can use leaflet-compare from a CDN like unpkg. Include the plugin's css and js files after the links to the Leaflet files. Then either use myScript.js or use script tags in the body of the referencing html page.

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

Limitations

  • The divider is not movable with IE.
  • Probably won't work in IE8, but what does?

License

MIT