Skip to main content

LocationSource

wemap-sdk-js


Abstract Class: LocationSource

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
}
}

Extended by​

Implements​

Constructors​

Constructor​

new LocationSource(): LocationSource

Returns​

LocationSource

Properties​

isStarted​

isStarted: boolean = false

Accessors​

locationState​

Get Signature​

get locationState(): LocationState

Get the current location state

Returns​

LocationState

The current location state

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();

Implementation of​

ILocationSource.dispose


offError()​

offError(callback): void

Remove the error callback

Parameters​

callback​

(error) => void

The callback function to remove

Returns​

void

Implementation of​

ILocationSource.offError


offLocationStateChange()​

offLocationStateChange(callback): void

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

Implementation of​

ILocationSource.offUpdate


onError()​

onError(callback): void

Register a callback to receive error events

Parameters​

callback​

(error) => void

Function to call when an error occurs

Returns​

void

Implementation of​

ILocationSource.onError


onLocationStateChange()​

onLocationStateChange(callback): void

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);
});

Implementation of​

ILocationSource.onUpdate


start()​

abstract start(): Promise<void>

Start the location source and begin emitting updates

Returns​

Promise<void>

Implementation of​

ILocationSource.start


stop()​

abstract stop(): Promise<void>

Stop the location source and stop emitting updates

Returns​

Promise<void>

Implementation of​

ILocationSource.stop