Class: Style
- Last UpdatedMay 21, 2025
- 4 minute read
Creates an instance of style.
Name | Type | Description |
---|---|---|
config |
string | Object |
Either a URL to load the style from or an object describing the rendering style.
The URL can be absolute or relative, but should end with |
Extends
Methods
-
This method adds a listener for a specific event.
Note that to prevent potential memory leaks, you must either call
removeEventListener
ordispose
on the given object when you no longer need it. -
addOnDisposeCallback (callback, opt_scope) inherited
-
This method adds a callback which is triggered when the
EventTarget
object is being disposed.Name Type Description callback
function The callback function.
opt_scope
Object optional An optional scope for the callback function
-
dispatchEvent (evt) inherited
-
This method dispatches an event on the
EventTarget
object.Name Type Description evt
H.util.Event | string An object representing the event or a string with the event name
-
dispose () inherited
-
This method removes listeners from the given object. Classes that extend
EventTarget
may need to override this method in order to remove references to DOM Elements and additional listeners. -
Returns the style base URL.
Returns:
Type Description string | undefined -
To get the current style configuration as a JavaScript Object, or
null
if there was an error loading/parsing the style configuration.Note that the copy of the configuration is returned.
Returns:
Type Description T -
To get the list of enabled style features. If
setEnabledFeatures
was called before, then this method will return features previously passed to that setter. IfsetEnabledFeatures
wasn't called before, then the result depends on the style state:- if the style is loaded, then this method will extract and return a list of features enabled by default from the style configuration.
- if the style is not loaded, then this method will return
undefined
.
Returns:
Type Description Array.<{feature: string, mode: (string|undefined)}> | undefined -
getState ()H.map.render.Style.State inherited overrides
-
Returns the state of the current style.
Returns:
Type Description H.map.render.Style.State -
Starts loading the style configuration if it was specified as a URL or parsing the style configuration if it was passed encoded string or object.
Returns:
Type Description void -
This method removes a previously added listener from the
EventTarget
instance. -
Enables style features. Style features allow to switch on and off certain map objects defined in the style configuration, for example: buildings, public transport, etc. The list of features supported by the current style configuration can be obtained by calling
style.getConfig().features
.This method dispatches "change" event.
Please note that this method overrides style features enabled by default. To preserve default features, you need to pass them to this method together with features you want to enable. This example shows how to preserve currently enabled features and additionally enable "road exit labels" feature in mode "all":
The mode
"none"
can be used to disable the feature.// Get the list of currently enabled features: const enabledFeatures = style.getEnabledFeatures(); // Define feature to enable and its mode: const featureToEnable = {feature: 'road exit labels', mode: 'all'}; // Add feature to the list of enabled features or replace its mode if it's already in the list: const featureIndex = enabledFeatures.findIndex(el => el.feature === featureToEnable.feature); enabledFeatures.splice(featureIndex, featureIndex === -1 ? 0 : 1, featureToEnable); // Apply changes: style.setEnabledFeatures(enabledFeatures);
Name Type Description enabledFeatures
Array.<{feature: string, mode: string}> | undefined The list of style features to enable, for example:
[ {feature: 'road exit labels', mode: 'all'}, {feature: 'congestion zones', mode: 'all'}, {feature: 'environmental zones', mode: 'all'} ]
If this parameter is
undefined
, then the list of enabled features will be taken from the style configuration. An empty array means that all style features should be disabled.Throws:
-
If
enabledFeatures
parameter has multiple occurrences of the same feature.
Returns:
Type Description void -
Events
-
Event fired when style changes
Type:
-
Event fired when error occurs during style load, parsing, etc.
Type: