Powered by Zoomin Software. For more details please contactZoomin

HERE Maps API for JavaScript - API Reference

Product category
Technology
Doc type
Version
Product lifecycle
This publication

HERE Maps API for JavaScript - API Reference: Class: Style

Table of Contents

Class: Style

new H.map.render.webgl.Style (config, opt_baseUrl)

Instances of this class hold style configuration for rendering provider data using H.map.render.webgl.RenderEngine. It also provides utility methods for operating with the style.

Specify a URL as a config parameter value to load the YAML formatted style configuration. Note that all relative paths within that configuration (textures, imported sub-styles, fonts, etc.) are resolved relative to the hosting location of the main style. The styles are loaded automatically if a layer with the provider using the style is added to the map. Alternatively load() method can be called explicitly to start the loading when needed. Resulting style configuration can be obtain using the getConfig() method of the class.

import

The YAML configuration can contain an optional top-level import element, declaring an import parameter. The value can be a single URL like import: colors.yaml, or an array of URLs import: [a.yaml, b.yaml].

The import block allows to import one or more additional files (which can then in turn recursively import others). It works by deep-merging each imported scene into the current one: the "child" (imported) file is merged first, with the "parent" file merged after, overwriting any properties shared with the child.

The final style configuration is a JavaScript object as a result of merging the master style on top of all the imported styles following the order in which they are listed in the import.

Objects vs. Arrays

One important aspect of the merge behavior is that it applies to all YAML maps/JS objects, but not to YAML sequences/JS arrays. While key/value objects are merged (with new keys inserted, and existing keys overwriting the previous value), arrays are treated as scalar values that entirely overwrite the previous value (rather than merging the array contents).

Relative URLs

The relative URLs of the resources of the imported files are resolved relatively to the hosting location of that file. The optional opt_baseUrl is applied to the master file only.

Name Type Description
config string | H.map.render.webgl.StyleConfig

Either a URL to load the style from, YAML formatted string or an object describing the rendering style. The URL can be absolute or relative, but should end with either .yaml or .yml extension.

opt_baseUrl string optional

The base URL to use for resolving relative URLs in the style like textures, fonts. When URL is passed as a config, it is used as a default base URL. Otherwise resources with the relative paths are resolved relative to the page location.

Throws:

if the specified configuration is invalid.

Type
H.lang.InvalidArgumentError

Extends

Methods

H.map.render.webgl.Style.normalize (config, baseUrl) static

Normalize properties which can potentially hold relative URLs with the specified style config For example when A.yaml imports B.yaml, relative URLs in B should be resolved from the location of the B.yaml, rather then A.yaml.

Name Type Description
config H.map.render.webgl.StyleConfig

The YAML config

baseUrl string

The base URL to use for resolving relative resources

addEventListener (type, handler, opt_capture, opt_scope) inherited

This method adds a listener for a specific event.

Note that to prevent potential memory leaks, you must either call removeEventListener or dispose 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.

extractConfig (layerIds, opt_preserving, opt_excludeParentDraws)H.map.render.webgl.StyleConfig

Extracts the style configuration of the data layers with the specified ids. By default extracted layers are removed from the current layer, however that behavior can be changed by passing true as opt_preserving flag. Returned configuration object represents the extracted layers and can be used for creating a new H.map.render.webgl.Style with only that data layers.

Note that the copy of the configuration is returned.

Throws:

if any of the layers couldn't be resolved.

Type
H.lang.InvalidArgumentError
Returns:
Type Description
H.map.render.webgl.StyleConfig the style configuration for the extracted layers.

getBaseUrl ()string | undefined inherited overrides

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:

getProperty (path)*

Returns the value of the property specified by the . delimited path.

Note that the copy of the configuration is returned.

Name Type Description
path string

The . delimited property path within the style configuration.

Throws:

if current style state is not READY

Type
H.lang.IllegalOperationError
Returns:
Type Description
* The value of the property or undefined if it is not found.

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.

mergeConfig (config)

Merges the specified style configuration with the current one.

Name Type Description
config H.map.render.webgl.StyleConfig

An object describing the rendering style.

Throws:

removeEventListener (type, handler, opt_capture, opt_scope) inherited

This method removes a previously added listener from the EventTarget instance.

removeProperty (path)

Removes the property specified by the . delimited path.

Name Type Description
path string

The . delimited property path within the style configuration.

Throws:

if current style state is not READY

Type
H.lang.IllegalOperationError

setInteractive (layerIds, interactive, opt_recursive)

Enables or disables object picking on objects from the data layers with the specified ids.

Throws:

if any of the layers couldn't be resolved.

Type
H.lang.InvalidArgumentError
Example
// Assumption: style has sub data layer "landuse.park"
style.setInteractive('landuse.park', true);

setProperty (path, value, opt_force)

Sets the specified value to the property specified by the . delimited path. If property by the specified path does not exist, it is created according to the nesting levels.

Throws:
Example
// Assumption: style has sub data layer "landuse.park" with instructions to draw it as a polygon.
style.setProperty('layers.landuse.park.draw.polygons.color', 'red');

Events

change inherited

Event fired when style changes

Type:

error inherited

Event fired when error occurs during style load, parsing, etc.

Type:
Was this article helpful?
TitleResults for “How to create a CRG?”Also Available inAlert