ArcGIS Blog

Developers

ArcGIS Location Platform

How to build open source applications using basemap sessions

By Sheryl Tania and Anita Kemp and Allan Laframboise

This blog contains resources for ArcGIS Location Platform developers who want to learn how to build applications that use basemap sessions. You’ll find steps, code examples, and tutorials for working with different open source mapping libraries such as MapLibre GL JS, Leaflet, or OpenLayers.

What is a basemap session?

Basemap sessions are a type of usage and charging model for displaying basemaps in a mapping application. Basemap sessions allow a user of an application access to an unlimited number of tiles from the ArcGIS Basemap Styles service for up to 12 hours. Sessions are commonly used to build applications that consume a high volume of basemap tiles through user interactions such as panning, zooming, searching, or displaying many different styles.

If you want to learn more about basemap sessions, check out our recent blog or go to the Basemap usage page in the Mapping and location services developer guide. 

How do you build an app that uses basemap sessions? 

Before creating a basemap session, you need to decide on its duration and which basemap style family you would like to access. The duration can range from as short as 10 seconds (helpful for testing) up to 12 hours (the maximum time). When the duration expires, you can refresh the session to maintain uninterrupted application use. You must also specify the style family — either Open style family or ArcGIS style family — that the session will access.

The general workflow is to:

1. Create a basemap session for a duration and a style family (arcgis or open).

2. Use the session token to access a basemap style.

3. Display the basemap style in a map.

4. Refresh the session when it expires and update the map.

Note: Your ArcGIS Location Platform subscription includes 1,000 free sessions per month for testing, developing, and deploying applications.

The way you apply a session token to display a basemap style depends on the mapping library you are using. If there is no native support for sessions, ArcGIS REST JS can be used with any of the JavaScript libraries. See the examples below.

MapLibre GL JS

If you’re using MapLibre GL JS, the new MapLibre ArcGIS plugin streamlines the workflow for creating and managing sessions. You can create a session with the BasemapSession class and use the session token to display a basemap style. The class also refreshes with a new session once it expires.

The plugin also automatically updates the tiles with the new token behind the scenes. This means you don’t have to write custom logic to reload or reapply tiles manually.

Here’s what the code looks like:

Check out the full tutorial in the MapLibre GL JS and ArcGIS developer guide. 

Leaflet

If you are using Leaflet, you can combine the Esri Leaflet plugin with ArcGIS REST JS to create and manage the session. To start a new session, use the BasemapStyleSession class in ArcGIS REST JS. Then, use Esri Leaflet to display a basemap style using the session token.

When the session expires, you remove the old layer and add a new one with the refreshed token. 

Here’s what the code looks like:

Check out the full tutorial in the Esri Leaflet and ArcGIS developer guide. 

OpenLayers

If you are using OpenLayers, you can it alongside ArcGIS REST JS library to create and manage the session. To do so, start a new session with the BasemapStyleSession class. Next, display a basemap style with the session token using a library such as ol-mapbox-style

When the session expires, create a new session and update your map by looping through the layers and replacing the expired token with the new one.

Here’s what the code looks like:

Check out the full tutorial in the OpenLayers and ArcGIS developer guide. 

What’s next?

Learn more about building applications with basemap sessions in the Basemap usage page in the Mapping and location services developer guide. 

You can also learn more about ArcGIS Location Platform by exploring Esri’s website, checking out our latest blog, or by signing up for an account to start experimenting with the technology. 

Also, stay in the loop with the latest in developer technology by subscribing to the Esri Developer Newsletter! 

Share this article

Subscribe
Notify of
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments