<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Swipe component with scroll | Sample | ArcGIS Maps SDK for JavaScript</title>
justify-content: space-evenly;
.scroller > .content > .slide {
justify-content: flex-start;
background: var(--calcite-color-foreground-1);
padding: var(--calcite-spacing-md);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
/* set visibility after map initialization */
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
<arcgis-map zoom="5" item-id="45725ba7d9fb47a0925398919b13d1fa" id="my-map"></arcgis-map>
<div class="content"></div>
const scroller = document.querySelector(".scroller");
const content = scroller.querySelector(".content");
const viewElement = document.querySelector("arcgis-map");
const mapHeight = viewElement.offsetHeight;
// wait for the view to be ready
await viewElement.viewOnReady();
const map = viewElement.map;
// get the layers from the webmap
const layers = map.layers;
// create a swipe component for each layer
const swipes = layers.map((layer) => {
const swipe = document.createElement("arcgis-swipe");
swipe.endLayers = [layer];
swipe.direction = "vertical";
swipe.referenceElement = "my-map";
// create a legend for each layer
layers.forEach((layer) => {
const slide = document.createElement("div");
slide.className = "slide";
const legend = document.createElement("arcgis-legend");
legend.referenceElement = "my-map";
legend.className = "legend";
slide.appendChild(legend);
content.appendChild(slide);
height = mapHeight * swipes.length;
setScroll(scroller.scrollTop);
content.style.height = height + "px";
function clamp(value, min, max) {
return Math.min(max, Math.max(min, value));
function setScroll(value) {
requestAnimationFrame(() => {
let pageRatio = scroll / mapHeight;
swipes.forEach((swipe, index, swipes) => {
viewElement.append(swipe);
let position = (index - pageRatio) * 100;
// To achieve this infinite scroll effect we need to swap the layers:
// The layer starts at the bottom, the divider goes up
// Then the next layer starts to show up, so we put back the divider at the bottom and swap the layers.
if (position < 0 && swipe.endLayers.length) {
swipe.startLayers.addMany(swipe.endLayers);
swipe.endLayers.removeAll();
} else if (position >= 0 && swipe.startLayers.length) {
swipe.endLayers.addMany(swipe.startLayers);
swipe.startLayers.removeAll();
swipe.position = clamp(position, 0, 100);
// show layer legends after map has loaded
const legends = document.getElementsByClassName("legend");
for (let i = 0; i < legends.length; i++) {
legends[i].style.visibility = "visible";
scroller.addEventListener("wheel", (event) => {
event.stopImmediatePropagation();
scroller.addEventListener("scroll", (event) => {
setScroll(scroller.scrollTop);