Swipe Widget with Scroll

This sample uses multiple Swipe widgets 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 widget is created, and the layer is added to the trailingLayers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// create a swipe widget for each layer
swipes = layers.map((layer) => {
  return new Swipe({
    view: view,
    disabled: false,
    position: 100,
    direction: "vertical",
    trailingLayers: [layer],
    visibleElements: {
      handle: false,
      divider: true
    }
  });
});

When the user scrolls through the app, the leadingLayers and trailingLayers update as the Swipe widget's position changes to achieve the infinite scroll effect.

1
2
3
4
5
6
7
8
9
10
// 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.trailingLayers.length) {
  swipe.leadingLayers.addMany(swipe.trailingLayers);
  swipe.trailingLayers.removeAll();
} else if (position >= 0 && swipe.leadingLayers.length) {
  swipe.trailingLayers.addMany(swipe.leadingLayers);
  swipe.leadingLayers.removeAll();
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

The developer dashboard has moved

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close