Swipe and side-by-side compare

Compare shows two versions of the same map at once. In swipe mode one sits over the other and a divider cuts between them, so a reader drags it across to see what changed. In side by side mode the two sit next to each other. Both move together: pan, zoom, rotate or tilt either one and the other follows, in 2D and in the 3D terrain view.

Each side can show its own layers and its own point in time. That makes it the tool for before and after: flood extent against the normal river, a burn scar against last summer's forest, a city in 2015 against today.

Readers do not need you to set anything up. Any map with two or more layers in its layers panel, or with a time slider, has a compare button, and readers choose what each side shows. What you set in the builder is the starting comparison: what compare opens on, with your labels.

Choosing what each side shows

Open compare with the compare button. Each side has a label next to the divider; click it to choose what that side shows.

  • Layers: tick the layers to draw on that side. The list is the map's own layers panel.
  • Date on this side (the right side, on maps with a time slider): follow the time slider, or pick a fixed date and step to the date before or after it. The left side's date is the time slider itself.
  • Swap sides, and switch between Swipe and Side by side.
  • Back to the author's comparison, when the map has a starting comparison and a reader has changed it.

When a map has no starting comparison, compare opens on something useful straight away: on a map with a time slider, the right side shows the date before the one on the slider; otherwise the top layer is drawn on the left side only, so dragging the divider shows what is under it.

The layers panel still works while compare is open. Turning a layer on or off there changes both sides.

Setting it up in the builder

Open the map in the builder and expand Compare on the Map tab.

Let visitors compare is on by default. Turn it off to remove the compare button from the map altogether, starting comparison included.

To set a starting comparison:

  1. Tick Set a starting comparison.
  2. Pick the layout: Swipe (divider) or Side by side. For swipe, choose where the divider starts.
  3. For each side, give it a label (a date reads well) and tick the layers that belong on that side only. Layers you do not tick on either side show on both, so a basemap overlay or a boundary layer stays put while the imagery changes.
  4. To compare two moments of a time series, type a date for each side under Date. Each side then shows the frame of the series for its date. A side with no date follows the time slider.
  5. Tick Open compare when the map loads if the map is mainly about the comparison. Otherwise readers open it with the compare button.

A layer can be on one side or on both, never on two lists, and the two sides have to differ in some way: a layer on one side, or two different dates.

Before and after with a series

Before and after imagery is best uploaded as one time series with a frame per date, then added to the map once. Give the left side the earlier date and the right side the later one. The reader sees the two frames split by the divider, and every other time-aware layer on the map follows each side's date too.

Two separate rasters also work: put one on each side's list.

What readers can do

  • Drag the divider, or focus it and use the arrow keys (Home and End jump to the edges, Escape closes compare).
  • Click a feature on either side to open its popup. The click goes to the side it lands on.
  • Switch to 3D: both sides follow.
  • On a phone the divider runs across the screen, and side by side stacks the two maps.

Closing compare removes the second map, so the page is back to its normal weight.

Linking to it

Add ?compare=0.5 to the map's link to open it with the divider in the middle (any number from 0 to 1). ?compare=on opens it where the author set the divider, and ?compare=off keeps it closed even when the map opens it by default. Compare works in embeds too.

When a reader changes the sides, the address bar gains a compareSides value, so copying the link shares that exact comparison. Closing compare takes it off again.

Printing

Printing an open compare view prints both sides on one sheet, split where the divider is, with each side's name at the top of its half and both sides' layers in the legend. A side-by-side comparison prints as two panes. Changing the basemap, the overlays or the globe while compare is open changes both sides.

In the map document and through the API

The setting lives in spec.compare of the map document:

"compare": {
  "mode": "swipe",
  "position": 0.5,
  "left": { "time": "2019-07-01" },
  "right": { "time": "2024-07-01" },
  "leftLabel": "July 2019",
  "rightLabel": "July 2024"
}

mode is swipe (the default) or side-by-side, position is 0 to 1, and autoOpen opens it on load. Each side takes layerIds (layers drawn on that side only) and time (a date or an ISO 8601 date and time). Labels are up to 60 characters.

Through MCP or the API, set it with the setCompare operation of update_map, or remove it with compare: null. A full replace that leaves compare out keeps the stored setting.

The compare button itself is spec.chrome.compare: visible (the default) or hidden. Set it with the setChrome operation, for example {"op": "setChrome", "chrome": {"compare": "hidden"}}.