Skip to content

BasemapSession

Class

Manages the creation and lifecycle of a basemap session for use with BasemapStyle .

The BasemapSession class provides:

  • Session token management with auto-refresh capabilities
  • Event handling for session lifecycle (refresh, expiration, errors)
  • Integration with ArcGIS Basemap Styles Service

> An access token is required to use basemap sessions. The token must be from an ArcGIS Location Platform account and have the Basemaps privilege.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Create and start a session
const basemapSession = await BasemapSession.start({
 token: "your-arcgis-token",
 styleFamily: "arcgis",
 duration: 3600,
 autoRefresh: true
});

// Listen for session events
basemapSession.on("BasemapSessionRefreshed", (e) => {
 console.log("Session refreshed", e.current.token);
});

basemapSession.on("BasemapSessionExpired", (e) => {
 console.log("Session expired", e.token);
});

basemapSession.on("BasemapSessionError", (e) => {
 console.error("Session error", e);
});

Constructors

constructor

Class Constructor
BasemapSession(optionsIBasemapSessionOptions): BasemapSession

Creates a new BasemapSession instance but does not start it. Use the BasemapSession.initialize method to begin the session manually. Creating basemap sessions in this way using the constructor directly is discouraged. The recommended method is to use BasemapSession.start .

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
const basemapSession = new BasemapSession({
 token: 'your-arcgis-token',
 styleFamily: 'arcgis-navigation',
 duration: 3600,
 autoRefresh: false
});
await session.initialize();
Parameters
ParameterTypeNotes
optionsIBasemapSessionOptions

Configuration options for the session

Returns 
BasemapSession

Accessors

AccessorReturns
endTime()Date
isStarted()boolean
safeEndTime()Date
startTime()Date
styleFamily()StyleFamily
token()string

endTime

Class Accessor
endTime(): Date

Gets the end time of the session returned by the basemap styles service.

Returns 
Date

isStarted

Class Accessor
isStarted(): boolean

Returns 'true' if the session is started, and false otherwise.

Returns 
boolean

safeEndTime

Class Accessor
safeEndTime(): Date

Gets the functional end time of the session. This is equivalent to the session end time plus the safety margin, and is used to tell when the session should be refreshed.

Returns 
Date

startTime

Class Accessor
startTime(): Date

Gets the session start time.

Returns 
Date

styleFamily

Class Accessor
styleFamily(): StyleFamily

Gets the sessions StyleFamily value.

Returns 
StyleFamily

token

Class Accessor
token(): string

Gets the current session token.

Returns 
string

Methods

MethodReturnsNotes
initialize()Promise<void>

Starts the session if it has not been started already.

off<K>(eventName, handler)void

Unregister an event handler

on<K>(eventName, handler)void

Register an event handler

refresh()Promise<void>

Manually refresh the session token.

start(options)Promise<BasemapSession>

Factory method that creates a new basemap session and starts it.

initialize

Class Method
initialize(): Promise<void>

Starts the session if it has not been started already.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
const basemapSession = new BasemapSession({
 token: 'your-arcgis-token',
 styleFamily: 'arcgis-navigation',
 duration: 3600,
 autoRefresh: false
});
await session.initialize();
Returns 
Promise<void>

off

Class Method
off<K>(eventNameK, handler(dataBasemapSessionEventMap[K]) => void): void

Unregister an event handler

Use dark colors for code blocksCopy
1
2
const basemapSession = await BasemapSession.start(options);
basemapSession.off('BasemapSessionExpired', handler);
Type Parameters
ParameterType
KkeyofBasemapSessionEventMap
Parameters
ParameterType
eventNameK
handler(dataBasemapSessionEventMap[K]) => void
Returns 
void

on

Class Method
on<K>(eventNameK, handler(dataBasemapSessionEventMap[K]) => void): void

Register an event handler

Use dark colors for code blocksCopy
1
2
3
4
const basemapSession = await BasemapSession.start(options);
basemapSession.on('BasemapSessionExpired', (data) => {
  console.log('Session expired:', data);
});
Type Parameters
ParameterType
KkeyofBasemapSessionEventMap
Parameters
ParameterType
eventNameK
handler(dataBasemapSessionEventMap[K]) => void
Returns 
void

refresh

Class Method
refresh(): Promise<void>

Manually refresh the session token.

Use dark colors for code blocksCopy
1
2
3
4
5
basemapSession.on("BasemapSessionExpired", () => {
  console.log('Session expired');
  // Manually refresh the session token using the refresh method.
  basemapSession.refresh();
});
Returns 
Promise<void>

start

static
Class Method
start(optionsIBasemapSessionOptions): Promise<BasemapSession>

Factory method that creates a new basemap session and starts it.

Use dark colors for code blocksCopy
1
2
3
4
5
const basemapSession = await BasemapSession.start({
  token: 'your-access-token',
  styleFamily: 'arcgis',
  autoRefresh: true
});
Parameters
ParameterTypeNotes
optionsIBasemapSessionOptions

Options for constructing the basemap session.

Returns 
Promise<BasemapSession>

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