Skip to content

This sample uses multiple Swipe components to create an seemingly infinite scroll between different Educational Attainment layers in Mexico.

How it works

For each layer loaded from a WebMap, a Swipe is created, and the layer is added to the endLayers.

// create a swipe component for each layer
const swipes = layers.map((layer) => {
layer.visible = true;
const swipe = document.createElement("arcgis-swipe");
swipe.endLayers = [layer];
// set other swipe properties
return swipe;
});

When the user scrolls through the app, the startLayers and endLayers update as the Swipe’s position changes to achieve the infinite scroll effect.

// 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();
}