Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

MapCompare

Swipe-compare two lonboard Maps with a draggable divider — drag it across the viewport to reveal one map over the other. Ideal for before/after imagery: satellite scenes from two dates, or pre- and post-event views of the same area.

The two maps are stacked, and the before map is clipped to one side of the divider (left for a vertical split, top for a horizontal one). Their cameras are locked together, so panning or zooming either map moves both — no kernel required, so it behaves the same live and in static export.

Import

from manywidgets.lonboard import MapCompare

Example

from lonboard import Map, BitmapTileLayer
from manywidgets.lonboard import MapCompare

# Two raster sources to compare. Swap these for two dated satellite layers
# (e.g. NASA GIBS MODIS imagery for two dates) to build a true before/after.
imagery = BitmapTileLayer(
    data="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
    tile_size=256, max_requests=-1, min_zoom=0, max_zoom=19,
)
streets = BitmapTileLayer(
    data="https://tile.openstreetmap.org/{z}/{x}/{y}.png",
    tile_size=256, max_requests=-1, min_zoom=0, max_zoom=19,
)

view = {"longitude": -122.45, "latitude": 37.78, "zoom": 11}
before = Map(imagery, basemap=None, view_state=view)
after = Map(streets, basemap=None, view_state=view)

MapCompare(before, after)

Drive the divider from a Sliderposition runs 0–1, the same range as the slider’s value, so a plain jslink keeps them in sync (both live and static):

from ipywidgets import jslink
from manywidgets import Column, Slider

swipe = Slider(value=0.5, min=0.0, max=1.0, step=0.01, label="Swipe")
compare = MapCompare(before, after)
jslink((swipe, "value"), (compare, "position"))  # bidirectional: drag either one
Column(swipe, compare)

API

TraitTypeDefaultDescription
beforeInstanceLonboard Map shown on the leading side of the swipe.
afterInstanceLonboard Map shown on the trailing side of the swipe.
positionFloat0.5Swipe divider position from 0 (start) to 1 (end).
orientationUnicode'vertical'Split direction: “vertical” (left/right) or “horizontal” (top/bottom).
sync_viewsBoolTrueKeep the two maps’ cameras locked together.
heightUnicode'500px'CSS height of the compare container.
initial_viewUnicode'before'Which map’s view_state to align to on load (“before” or “after”).
widget_idUnicode''Stable unique id used for cross-widget linking (auto-assigned).