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
removeEventListenerordisposeon the given object when you no longer need it.Name Type Description typestring The name of the event
handlerfunction An event handler function
opt_captureboolean optional trueindicates that the method should listen in the capture phase (bubble otherwise)opt_scopeObject optional An object defining the scope for the handler function
-
addOnDisposeCallback (callback, opt_scope) inherited
-
This method adds a callback which is triggered when the
EventTargetobject is being disposed.Name Type Description callbackfunction The callback function.
opt_scopeObject optional An optional scope for the callback function
-
dispatchEvent (evt) inherited
-
This method dispatches an event on the
EventTargetobject.Name Type Description evtH.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
EventTargetmay 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
nullif 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
setEnabledFeatureswas called before, then this method will return features previously passed to that setter. IfsetEnabledFeatureswasn'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
EventTargetinstance.Name Type Description typestring The name of the event
handlerfunction A previously added event handler
opt_captureboolean optional trueindicates that the method should listen in the capture phase (bubble otherwise)opt_scopeObject optional An object defining the scope for the handler function
-
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 enabledFeaturesArray.<{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
enabledFeaturesparameter 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: