Gets the unified events interface for this module, covering both user interactions and module lifecycle events.
User interaction events (click, contextmenu, hover, long-hover):
const unsub = baseMap.events.on('click', (feature, lngLat) => {
console.log('Clicked on:', feature.properties);
});
baseMap.events.off('hover'); // remove by type
Module lifecycle events (config-change):
const unsub = baseMap.events.on('config-change', (config) => {
console.log('Config changed:', config);
});
unsub(); // remove by returned function
Gets the source and layer identifiers for all sources managed by this module.
This property provides access to the MapLibre source and layer IDs that were created and are managed by this module. These IDs can be used to interact directly with MapLibre's API or to identify which layers belong to this module.
A record mapping each source name to its corresponding source ID and layer IDs. Each entry contains the MapLibre source identifier and an array of layer identifiers associated with that source.
The returned IDs are useful when you need to:
const ids = myModule.sourceAndLayerIDs;
console.log(ids);
// {
// mySource: {
// sourceID: 'my-source-id',
// layerIDs: ['layer-1', 'layer-2']
// }
// }
// Use with MapLibre API
const map = myModule.mapLibreMap;
ids.mySource.layerIDs.forEach(layerId => {
map.setLayoutProperty(layerId, 'visibility', 'visible');
});
Applies a configuration to this module.
This method updates the module's behavior and appearance based on the provided configuration. The configuration is stored internally and will be automatically reapplied if the map style changes.
The configuration object to apply to the module. Pass undefined to reset
the configuration to default values.
When a configuration is applied, the module updates its visual representation and behavior accordingly. The configuration persists across map style changes, ensuring consistent module behavior even when the map's base style is modified.
The given configuration replaces the current one rather than being merged into it. To change one part of it, use updateConfig.
// Apply a new configuration
myModule.applyConfig({ visible: true, opacity: 0.8 });
// Reset to default configuration
myModule.applyConfig(undefined);
Retrieves a copy of the current module configuration.
This method returns a shallow copy of the configuration object that is currently
applied to the module. If no configuration has been applied, it returns undefined.
A shallow copy of the current configuration object, or undefined if no
configuration is currently applied. The returned object is a copy to prevent
unintended modifications to the internal state.
The returned configuration object is a shallow copy, which means that while the top-level properties are copied, any nested objects or arrays are still referenced from the original configuration. This is sufficient for most use cases but should be kept in mind when dealing with complex configurations.
// Apply a configuration
myModule.applyConfig({ visible: true, opacity: 0.8 });
// Later, retrieve the current configuration
const currentConfig = myModule.getConfig();
console.log(currentConfig); // { visible: true, opacity: 0.8 }
// When no config is applied
myModule.resetConfig();
console.log(myModule.getConfig()); // undefined
The managed layer ids belonging to a single base-map layer group.
The layer group to look up.
The layer ids for that group, in style draw order (empty when none). A fresh array each call, safe to mutate.
The base-map layer ids grouped by BaseMapLayerGroupName, for the layers this module manages in the current style.
A record with an entry for every layer group (empty array when the
style has no layers for it). Layer ids keep their style draw order within
each group. Groups overlap by design (e.g. a city label is in both
cityLabels and allPlaceLabels), so a layer id can appear under several.
Whether the base map, or the layer groups asked about, is set to be shown.
Optionaloptions: { layerGroups?: BaseMapLayerGroups }
Optional settings for fine-grained control.
OptionallayerGroups?: BaseMapLayerGroupsAsk about specific layer groups instead of all layers.
true if at least one of the layers asked about is set to show, false if all are
set to hide.
Reads the settings, not the map: visible, then the groups and the StylingModule
toggles over them, the last that reaches a layer winning — the same order setVisible
writes them in.
A layer none of them reaches answers with what the style draws, which is how a per-group control reflects the state the style starts in.
Resets the configuration of this module to its default values.
This is a convenience method that clears any previously applied configuration
and restores the module to its initial state. This is equivalent to calling
applyConfig(undefined).
After calling this method, the module will behave as if no configuration was ever applied. Any custom settings, styling, or behavior modifications will be removed and replaced with default values.
// Apply some configuration
myModule.applyConfig({ visible: true, opacity: 0.5 });
// Later, reset to defaults
myModule.resetConfig();
Sets the visibility of base map layers.
true to show layers, false to hide them.
Optionaloptions: { layerGroups?: BaseMapLayerGroups }
Optional settings for fine-grained control.
OptionallayerGroups?: BaseMapLayerGroupsTarget specific layer groups instead of all layers.
Behavior:
options.layerGroups: Affects all base map layersoptions.layerGroups in include mode: Affects only the specified layer groupsexclude mode: Affects every layer outside the specified groups, which stay as they wereEvery call is kept in the configuration's groups (or visible), so a style change restores
all of them. A call takes the groups it sets over from the StylingModule toggles on
them (basemap.<group>, buildings.*, roads.shields), which it removes from the styling
settings; the toggles within a group, such as roads.arrows, stay set.
Layer Groups:
Available groups: land, water, buildings2D, roads, railways,
ferries, borders, buildings3D, natureLabels, roadLabels,
roadShields, houseNumbers, smallerTownLabels, stateLabels,
cityLabels, allPlaceLabels, capitalLabels, countryLabels.
See BaseMapLayerGroupName.
Show/hide all layers:
baseMap.setVisible(false); // Hide everything
baseMap.setVisible(true); // Show everything
Control specific groups:
// Hide only buildings
baseMap.setVisible(false, {
layerGroups: {
mode: 'include',
names: ['buildings2D', 'buildings3D']
}
});
// Show everything except labels
baseMap.setVisible(true, {
layerGroups: {
mode: 'exclude',
names: ['allPlaceLabels', 'cityLabels', 'countryLabels']
}
});
Changes part of the configuration and keeps the rest.
The given properties are laid over the current configuration — one level deep, so a nested
object you pass replaces the nested object that was there — and the result is applied with
applyConfig. This is the same on every module, whatever its applyConfig does with a
whole configuration.
The properties to change.
routing.applyConfig({ displayUnits: 'imperial', color: '#0a3653' });
routing.updateConfig({ color: '#c2185b' }); // displayUnits stays imperial
applyConfig to apply a whole configuration
ProtectedwaitStaticgetAsynchronously retrieves a BaseMapModule instance for the given map.
This is the recommended way to create a BaseMapModule. It ensures the map is fully loaded before initializing the module.
The TomTomMap instance to attach this module to.
Optionalconfig: BaseMapModuleConfig
Optional configuration for module initialization.
A promise that resolves to the initialized BaseMapModule.
Instances:
BaseMapModule controls the base-map source and layers the map style already provides, under
fixed global IDs, so every map has exactly one — a second get() returns the same instance.
To work with part of the map, name the layer groups per call: setVisible(false, { layerGroups }) for visibility, events.where({ layerGroups }) for events.
Initialization:
Configuration Options:
visible: Initial visibility stategroups: Visibility per layer group
Base Map Module for controlling standard map layers and their visibility.
This module manages the fundamental map layers including background, water, land, roads, buildings, labels, and other vector tile layers from the base map style.
Remarks
What this module owns: whether each base-map layer group is shown. How the base map looks is StylingModule knobs. Its group toggles (
basemap.<group>,buildings.*,roads.shields) write through this module: the later of a toggle and a setVisible of that group wins. Its toggles within a group (roads.arrows,roads.exitNumbers, …) hide their layers inside what this module shows, and never show them in a group it hides. See Who owns what. baseMapKnobCatalogue lists every setting of its configuration.Managed Layers:
Does NOT Include:
Use Cases:
Example
Basic usage:
Example
Working with layer groups:
Example
Event handling:
See