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.
// 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 ConstructorBasemapSession(options: IBasemapSessionOptions): 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 .
const basemapSession = new BasemapSession({
token: 'your-arcgis-token',
styleFamily: 'arcgis-navigation',
duration: 3600,
autoRefresh: false
});
await session.initialize();
Parameters
Parameter | Type | Notes |
---|---|---|
options | IBasemapSessionOptions | Configuration options for the session |
Returns
BasemapSession
Accessors
Accessor | Returns |
---|---|
endTime() | Date |
isStarted() | boolean |
safeEndTime() | Date |
startTime() | Date |
styleFamily() | StyleFamily |
token() | string |
endTime
Class AccessorendTime(): Date
Gets the end time of the session returned by the basemap styles service.
Returns
Date
isStarted
Class AccessorisStarted(): boolean
Returns 'true' if the session is started, and false otherwise.
Returns
boolean
safeEndTime
Class AccessorsafeEndTime(): 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
styleFamily
Class AccessorstyleFamily(): StyleFamily
Gets the sessions StyleFamily value.
Returns
StyleFamily
Methods
Method | Returns | Notes |
---|---|---|
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 Methodinitialize(): Promise<void>
Starts the session if it has not been started already.
const basemapSession = new BasemapSession({
token: 'your-arcgis-token',
styleFamily: 'arcgis-navigation',
duration: 3600,
autoRefresh: false
});
await session.initialize();
Returns
Promise<void>
off
Class Methodoff<K>(eventName: K, handler: (data: BasemapSessionEventMap[K]) => void): void
Unregister an event handler
const basemapSession = await BasemapSession.start(options);
basemapSession.off('BasemapSessionExpired', handler);
Type Parameters
Parameter | Type |
---|---|
K | keyofBasemapSessionEventMap |
Parameters
Parameter | Type |
---|---|
event | K |
handler | (data: BasemapSessionEventMap[K]) => void |
Returns
void
on
Class Methodon<K>(eventName: K, handler: (data: BasemapSessionEventMap[K]) => void): void
Register an event handler
const basemapSession = await BasemapSession.start(options);
basemapSession.on('BasemapSessionExpired', (data) => {
console.log('Session expired:', data);
});
Type Parameters
Parameter | Type |
---|---|
K | keyofBasemapSessionEventMap |
Parameters
Parameter | Type |
---|---|
event | K |
handler | (data: BasemapSessionEventMap[K]) => void |
Returns
void
refresh
Class Methodrefresh(): Promise<void>
Manually refresh the session token.
basemapSession.on("BasemapSessionExpired", () => {
console.log('Session expired');
// Manually refresh the session token using the refresh method.
basemapSession.refresh();
});
Returns
Promise<void>
start
start(options: IBasemapSessionOptions): Promise<BasemapSession>
Factory method that creates a new basemap session and starts it.
const basemapSession = await BasemapSession.start({
token: 'your-access-token',
styleFamily: 'arcgis',
autoRefresh: true
});
Parameters
Parameter | Type | Notes |
---|---|---|
options | IBasemapSessionOptions | Options for constructing the basemap session. |
Returns
Promise<BasemapSession>