GISNJ

Open Leaflet plugin · Version 1.0.0

Leaflet.LayerSwipe

Compare two tile, WMS, image, or grouped layers with a draggable, keyboard-accessible divider. This demo pairs Leaflet.NJImagery years 1930 and 2020.

Flexible comparison

Use a vertical or horizontal reveal and change direction at runtime.

  • Mouse, touch, pen, and keyboard control
  • Vertical and horizontal orientation
  • Works with Leaflet.NJImagery WMS layers
  • No dependency beyond Leaflet

Quick start

<script src="leaflet-nj-imagery.js"></script>
<script src="leaflet-layer-swipe.js"></script>

const before = L.tileLayer.njImagery("BlackWhite1930").addTo(map);
const after = L.tileLayer.njImagery("Natural2020").addTo(map);

L.control.layerSwipe(before, after, {
  orientation: "vertical",
  initialPosition: 0.5
}).addTo(map);

API

L.control.layerSwipe()

Create a comparison control from two layers.

setOrientation()

Switch between vertical and horizontal at runtime.

setDividerPosition()

Move the divider to a value from 0 to 1.

setLeftLayer() / setRightLayer()

Replace either comparison layer.