Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-side-by-side

Package Overview
Dependencies
Maintainers
7
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-side-by-side

Compare two Leaflet layers side by side

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
885
decreased by-39.05%
Maintainers
7
Weekly downloads
 
Created
Source

leaflet-side-by-side

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

screencast example

L.control.sideBySide(leftLayer[s], rightLayer[s])

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 noop because the position is always the same - it does not make sense for this control to be in the corner like other Leaflet controls.

Parameters

parametertypedescription
leftLayersL.Layer|arrayA 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
rightLayersL.Layer|arrayA 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
optionsObjectOptions
options.paddingNumberPadding between slider min/max and the edge of the screen in pixels. Defaults to 44 - the width of the slider thumb

Events

Subscribe to events using these methods

EventDataDescription
leftlayeraddLayerEventFired when a layer is added to the left-hand-side pane
leftlayerremoveLayerEventFired when a layer is removed from the left-hand-side pane
rightlayeraddLayerEventFired when a layer is added to the right-hand-side pane
rightlayerremoveLayerEventYou guessed it... fired when a layer is removed from the right-hand-side pane
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.

Methods

MethodReturnsDescription
setLeftLayersthisSet the layer(s) for the left side
setRightLayersthisSet the layer(s) for the right side

Usage

Add the script to the top of your page (css is included in the javascript):

<script src="leaflet-side-by-side.js"></script>

Or if you are using browserify:

var sideBySide = require('leaflet-side-by-side')

Then create a map, add two layers to it, and create the SideBySide control and add it to the map:

var map = L.map('map').setView([51.505, -0.09], 13);

var myLayer1 = L.tileLayer(...).addTo(map);

var myLayer2 = L.tileLayer(...).addTo(map)

L.control.sideBySide(myLayer1, myLayer2).addTo(map);

Example

Live Example see source

Limitations

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

License

MIT

Keywords

FAQs

Package last updated on 25 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc