Skip to main content

WemapMap

wemap-sdk-js


Class: WemapMap

A thin, opinionated wrapper around a maplibre-gl Map for Wemap livemaps.

It owns the underlying maplibre instance (created from options.container) and adds first-class helpers for camera control, event subscription, and multi-level / indoor display via setLevel.

The raw maplibre map remains available through maplibre for anything the wrapper does not cover.

Requires core.init() from @wemap/core beforehand — map style, bounds, zoom range, and indoor settings are read from the parsed livemap snippet. Pass any WemapMapOptions field in the constructor to override them.

Implements​

Constructors​

Constructor​

new WemapMap(options): WemapMap

Parameters​

options​

WemapMapOptions

Returns​

WemapMap

Properties​

maplibre​

readonly maplibre: Map$1

The underlying maplibre-gl map instance.

Escape hatch for anything this wrapper doesn't cover. Not covered by semver: the maplibre-gl version and this accessor may change in any minor release, so code written directly against .maplibre can break without a major version bump. Prefer the wrapper API wherever one exists.

Methods​

addControl()​

addControl(control, position?): this

Add a maplibre control to the map (e.g. LevelControl).

Thin passthrough to the underlying maplibre addControl.

Parameters​

control​

IControl

position?​

ControlPosition

Returns​

this


addLayer()​

addLayer(layer, options?): this

Add a layer to the style, optionally wiring it into level management.

Safe to call before the style has loaded. When the style is already loaded (e.g. after whenReady), the layer is added synchronously. Adding the layer is a no-op if its id already exists. Use { indoor: true } for layers whose features carry a level so they follow setLevel.

map.addSource('my-src', { type: 'geojson', data });
map.addLayer({ id: 'my-rooms', type: 'fill', source: 'my-src' }, { indoor: true });

Parameters​

layer​

AddLayerObject

The layer to add.

options?​

AddLayerOptions = {}

AddLayerOptions.

Returns​

this


addSource()​

addSource(id, source): this

Add a source to the style. Safe to call before the style has loaded — the source is added as soon as the style is ready. When the style is already loaded (e.g. after whenReady), the source is added synchronously. No-op if the id already exists.

Parameters​

id​

string

Unique source id.

source​

SourceSpecification

The source specification.

Returns​

this


clearSearch()​

clearSearch(): this

Undo the highlight/filter applied by search when interaction.autoHighlightSearch is on: clear the highlight and show all pinpoints again. The current selection is left intact.

Returns​

this


easeTo()​

easeTo(options): this

Animate the camera to a new center/zoom with a smooth transition.

Parameters​

options​

WemapEaseToOptions

Returns​

this


filterPois()​

filterPois(ids): this

Restrict default POI layers to the given pinpoint ids.

An empty array is equivalent to hideAllPois.

Parameters​

ids​

number[]

Returns​

this


fitBounds()​

fitBounds(bounds, options?): this

Pan and zoom the map to contain the given bounds.

Parameters​

bounds​

BoundingBox

options?​

FitBoundsOptions

Returns​

this


flyTo()​

flyTo(options): this

Animate the camera to a new center/zoom with an arcing motion.

Parameters​

options​

WemapFlyToOptions

Returns​

this


getBounds()​

getBounds(): BoundingBox

The current viewport bounds.

Returns​

BoundingBox

Implementation of​

MapViewport.getBounds


getCenter()​

getCenter(): Coordinates

The current map center.

Returns​

Coordinates

Implementation of​

MapViewport.getCenter


getCurrentBuilding()​

getCurrentBuilding(): Building | null

The building nearest the viewport center, or null when indoor is disabled in the snippet, zoom is below indoor.minZoom, or no building is in view.

Returns​

Building | null


getLevel()​

getLevel(): number | null

The currently displayed level, or null when none has been set.

Returns​

number | null

Implementation of​

MapViewport.getLevel


getPoiFilter()​

getPoiFilter(): number[] | null

Read the current POI visibility filter.

  • null — no filter, all pinpoints shown (minus highlight/selected excludes).
  • number[] — whitelist; an empty array means all hidden.

Returns​

number[] | null


getPoiHighlighted()​

getPoiHighlighted(): number[]

Returns​

number[]


getPoiSelected()​

getPoiSelected(): number[]

Returns​

number[]


getViewportPinpoints()​

getViewportPinpoints(): Pinpoint[]

The API pinpoints currently inside the viewport and matching the active level, read synchronously from the loaded set. Pull this after whenReady for a deterministic first paint instead of waiting for the first onViewportPinpointsChange emit.

Returns​

Pinpoint[]


getZoom()​

getZoom(): number

The current zoom level.

Returns​

number

Implementation of​

MapViewport.getZoom


hideAllPois()​

hideAllPois(): this

Hide all pinpoints on default layers.

Returns​

this


off()​

Call Signature​

off<T>(type, layer, listener): this

Type Parameters​
T​

T extends keyof MapLayerEventType

Parameters​
type​

T

layer​

string | string[]

listener​

(ev) => void

Returns​

this

Implementation of​

MapViewport.off

Call Signature​

off<T>(type, listener): this

Type Parameters​
T​

T extends keyof MapEventType

Parameters​
type​

T

listener​

(ev) => void

Returns​

this

Implementation of​

MapViewport.off

Call Signature​

off(type, listener): this

Parameters​
type​

"load" | "moveend"

listener​

() => void

Returns​

this

Implementation of​

MapViewport.off


on()​

Call Signature​

on<T>(type, layer, listener): this

Type Parameters​
T​

T extends keyof MapLayerEventType

Parameters​
type​

T

layer​

string | string[]

listener​

(ev) => void

Returns​

this

Implementation of​

MapViewport.on

Call Signature​

on<T>(type, listener): this

Type Parameters​
T​

T extends keyof MapEventType

Parameters​
type​

T

listener​

(ev) => void

Returns​

this

Implementation of​

MapViewport.on

Call Signature​

on(type, listener): this

Parameters​
type​

"load" | "moveend"

listener​

() => void

Returns​

this

Implementation of​

MapViewport.on


onBuildingChange()​

onBuildingChange(listener): () => void

Subscribe to active-building changes. No-op when indoor.enable is false in the livemap snippet.

Parameters​

listener​

BuildingChangeListener

Returns​

An unsubscribe function.

() => void


once()​

Call Signature​

once<T>(type, layer, listener): this

Type Parameters​
T​

T extends keyof MapLayerEventType

Parameters​
type​

T

layer​

string | string[]

listener​

(ev) => void

Returns​

this

Call Signature​

once<T>(type, listener): this

Type Parameters​
T​

T extends keyof MapEventType

Parameters​
type​

T

listener​

(ev) => void

Returns​

this


onLevelChange()​

onLevelChange(listener): () => void

Subscribe to level changes.

Parameters​

listener​

LevelChangeListener

Called with the new level on every setLevel.

Returns​

An unsubscribe function.

() => void


onPoiClick()​

onPoiClick(listener): () => void

Subscribe to clicks on stylesheet pinpoint features.

Parameters​

listener​

PoiClickListener

Returns​

An unsubscribe function.

() => void


onPoiClickError()​

onPoiClickError(listener): () => void

Subscribe to pinpoint click resolution failures.

Parameters​

listener​

PoiClickErrorListener

Returns​

An unsubscribe function.

() => void


onViewportPinpointsChange()​

onViewportPinpointsChange(listener): () => void

Subscribe to pinpoint content refreshes driven by map preload (load, debounced moveend, level change).

Parameters​

listener​

ViewportPinpointsChangeListener

Returns​

() => void


registerIndoorLayer()​

registerIndoorLayer(layerId): this

Register an extra layer as level-aware, so setLevel filters it too.

Use this for layers added at runtime (via maplibre) whose ids don't match the indoorLayerFilter predicate. The current level is applied immediately.

map.maplibre.addLayer(myLevelAwareLayer);
map.registerIndoorLayer(myLevelAwareLayer.id);

Parameters​

layerId​

string

The id of a layer in the current style.

Returns​

this


remove()​

remove(options?): void

Destroy the map and release all resources.

Optional layers (UserLocationLayer, DomMarkerLayer, ItineraryLayer) are not destroyed unless options.layers is true. When omitted, those layers keep their maplibre listeners and DOM markers attached to a removed map instance — call each layer's destroy() first, or pass { layers: true }.

Parameters​

options?​

WemapMapRemoveOptions

Returns​

void


removeControl()​

removeControl(control): this

Remove a previously added maplibre control.

Parameters​

control​

IControl

Returns​

this


removeLayer()​

removeLayer(layerId): this

Remove a layer from the style. Safe to call before the style has loaded — the removal is deferred until the style is ready. No-op when the layer does not exist.

Parameters​

layerId​

string

The id of the layer to remove.

Returns​

this


removeSource()​

removeSource(id): this

Remove a source from the style. Safe to call before the style has loaded — the removal is deferred until the style is ready. No-op when the source does not exist.

Parameters​

id​

string

The id of the source to remove.

Returns​

this


search(query, options?): Promise<PinpointSearchResponse>

Search the livemap's pinpoints within the current viewport and level.

When interaction.autoHighlightSearch is enabled, the result pinpoints are highlighted and every other pinpoint is filtered out of the default layers (setPoiHighlighted + filterPois). Otherwise the map is left untouched and only the response is returned. Clear the applied state with clearSearch.

Parameters​

query​

string

Free-text search term.

options?​

WemapSearchOptions = {}

Optional overrides (limit, tags, level).

Returns​

Promise<PinpointSearchResponse>


setCenter()​

setCenter(center): this

Recenter the map instantly (no animation).

Parameters​

center​

LatLngLike

Returns​

this


setLevel()​

setLevel(level): this

Display a single level across all level-aware layers.

Safe to call before the style has loaded; the level is applied as soon as the style is ready and re-applied across style swaps.

Parameters​

level​

number

The level to display.

Returns​

this


setPoiHighlighted()​

setPoiHighlighted(ids): this

Replace the full list of highlighted stylesheet pinpoint ids.

Parameters​

ids​

number[]

Returns​

this


setPoiSelected()​

setPoiSelected(ids): this

Replace the full list of selected stylesheet pinpoint ids.

Parameters​

ids​

number[]

Returns​

this


setZoom()​

setZoom(zoom): this

Set the zoom level instantly (no animation).

Parameters​

zoom​

number

Returns​

this


showAllPois()​

showAllPois(): this

Clear the POI visibility filter — show all pinpoints on default layers.

Returns​

this


unregisterIndoorLayer()​

unregisterIndoorLayer(layerId): this

Stop treating a previously-registered layer as level-aware and restore its original filter.

Parameters​

layerId​

string

The id passed to registerIndoorLayer.

Returns​

this


whenReady()​

whenReady(): Promise<void>

Resolves when the map style is ready — safe to await in async setup code without racing on('load'). Resolves immediately if the style is already loaded.

Returns​

Promise<void>