Skip to main content

VPSLocationSource

wemap-sdk-js


Class: VPSLocationSource

Base class for all location sources

Provides common functionality like callback management, pose merging, and map matching configuration that can be shared across different location source implementations.

Subclasses should implement the start() and stop() methods and call mergeAndEmitUpdate() when they receive pose updates from their underlying providers.

Example​

class CustomLocationSource extends LocationSource {
async start() {
// Start your provider
provider.onUpdate((data) => {
this.mergeAndEmitUpdate(data);
});
}

async stop() {
// Stop your provider
}
}

Extends​

Constructors​

Constructor​

new VPSLocationSource(config?): VPSLocationSource

Parameters​

config?​

VPSLocationSourceConfig = {}

Returns​

VPSLocationSource

Overrides​

LocationSource.constructor

Properties​

isStarted​

isStarted: boolean = false

Inherited from​

LocationSource.isStarted

Accessors​

backgroundScanStatus​

Get Signature​

get backgroundScanStatus(): VpsBackgroundScanStatus

Current background scan scheduler status.

Returns​

VpsBackgroundScanStatus


locationState​

Get Signature​

get locationState(): LocationState

Get the current location state

Returns​

LocationState

The current location state

Inherited from​

LocationSource.locationState


scanStatus​

Get Signature​

get scanStatus(): ScanStatus

Current scan status (manual or background).

Returns​

ScanStatus

Methods​

dispose()​

dispose(): Promise<void>

Permanently tear down the location source.

Stops the source (via stop) and clears every registered callback (update, error and location-state). Subclasses override this to release their own provider-level listeners, then call super.dispose().

After dispose() the instance should be discarded and not restarted.

Returns​

Promise<void>

Example​

await locationSource.dispose();

Overrides​

LocationSource.dispose


offBackgroundScanStatusChange()​

offBackgroundScanStatusChange(callback): void

Stop listening to changes of the background scan status.

Parameters​

callback​

(status) => void

Returns​

void


offError()​

offError(callback): void

Remove the error callback

Parameters​

callback​

(error) => void

The callback function to remove

Returns​

void

Inherited from​

LocationSource.offError


offLocationStateChange()​

offLocationStateChange(callback): void

Parameters​

callback​

(status) => void

Returns​

void

Inherited from​

LocationSource.offLocationStateChange


offScanStatusChange()​

offScanStatusChange(callback): void

Stop listening to changes of the main scan status.

Parameters​

callback​

(status) => void

Returns​

void


offUpdate()​

offUpdate(callback): void

Remove the update callback

Parameters​

callback​

(data) => void

The callback function to remove

Returns​

void

Inherited from​

LocationSource.offUpdate


onBackgroundScanStatusChange()​

onBackgroundScanStatusChange(callback): () => void

Listen to changes of the background scan status.

Parameters​

callback​

(status) => void

Returns​

() => void


onError()​

onError(callback): void

Register a callback to receive error events

Parameters​

callback​

(error) => void

Function to call when an error occurs

Returns​

void

Inherited from​

LocationSource.onError


onLocationStateChange()​

onLocationStateChange(callback): void

Parameters​

callback​

(status) => void

Returns​

void

Inherited from​

LocationSource.onLocationStateChange


onScanStatusChange()​

onScanStatusChange(callback): () => void

Listen to changes of the main scan status.

Parameters​

callback​

(status) => void

Returns​

() => void


onUpdate()​

onUpdate(callback): void

Register a callback to receive pose updates

The callback receives complete pose data. If there's already a current pose available, the callback will be called immediately with that data.

Parameters​

callback​

(data) => void

Function to call when pose data is updated

Returns​

void

Example​

locationSource.onUpdate((pose) => {
console.log('Current pose:', pose);
});

Inherited from​

LocationSource.onUpdate


start()​

start(): Promise<void>

Start the location source and begin emitting updates

Returns​

Promise<void>

Overrides​

LocationSource.start


startScan()​

startScan(): Promise<boolean>

Start the VPS scan

Initiates a visual positioning scan using the device camera. This should be called when the user wants to determine their initial position. The scan will continue until a successful match is found or an error occurs.

When background scan is enabled, a manual call to startScan() cancels any ongoing background scan and clears the 30s idle timer.

Note: This requires camera permissions and the user should point the camera at recognizable visual features in the environment.

Returns​

Promise<boolean>

Promise that resolves to true if the scan was successful, false otherwise

Throws​

If VPS is not available or endpoint is not configured

Example​

await vpsSource.start();
const success = await vpsSource.startScan();
if (success) {
console.log('Position found via VPS!');
} else {
console.log('VPS scan failed');
}

stop()​

stop(): Promise<void>

Stop the location source and stop emitting updates

Returns​

Promise<void>

Overrides​

LocationSource.stop


stopScan()​

stopScan(cancelled?): Promise<void>

Parameters​

cancelled?​

boolean = false

If true, resolve the current scan promise with false (e.g. when manual scan cancels a background scan)

Returns​

Promise<void>