Maps API for JavaScript Developer's Guide

H.map.layer.CanvasLayer

Class Summary

Extends: H.map.layer.Layer

This class represents a layer for drawing 2D or 3D graphics on the map.

[ For full details, see the Class Details ]

Method Summary

Table 1. Methods
Methods

isValid (zoomLevel) : {boolean}

This method checks if a zoom level can be served by the given layer.

setMin (min) : {H.map.layer.Layer}

This method sets the minimum zoom level at which the given layer provides content.

setMax (max) : {H.map.layer.Layer}

This method sets the maximum zoom level at which the given layer provides content.

getCopyrights (bounds, level) : {?Array<H.map.ICopyright>}

This method retrieves the copyright of the current data provider.

addEventListener (type, handler, opt_capture, opt_scope)

This method adds a listener for a specific event.

removeEventListener (type, handler, opt_capture, opt_scope)

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

dispatchEvent (evt)

This method dispatches an event on the EventTarget object.

dispose ()

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.

addOnDisposeCallback (callback, opt_scope)

This method adds a callback which is triggered when the EventTarget object is being disposed.

Events Summary

Table 2. Events
Events

update : {H.util.Event}

Event fired when the data associated with the given layer is updated.

minchange : {H.util.ChangeEvent}

Event fired when the minimum zoom level for the given layer changes.

maxchange : {H.util.ChangeEvent}

Event fired when the maximum zoom level for the given layer changes.

Class Description

This class represents a layer for drawing 2D or 3D graphics on the map.

Note that there is no need to create own animation frame, as rendering callback is called within main animation frame used for rendering all other layers on the map.

Example

map.addLayer(new H.map.layer.CanvasLayer(function(ctx, renderParams) {
  var x = renderParams.screenCenter.x,
    y = renderParams.screenCenter.y;

  ctx.fillStyle = "red";
  ctx.fillText(
  "Zoom: " + renderParams.zoom + ", Bounds Center: " + renderParams.bounds.getCenter(),
  50, 50
  );
  ctx.moveTo(x - 20, y - 20);
  ctx.lineTo(x + 20, y + 20);
  ctx.moveTo(x + 20, y - 20);
  ctx.lineTo(x - 20, y + 20);
  ctx.stroke();
  return H.map.render.RenderState.DONE;
}));

Constructor Details

H.map.layer.CanvasLayer(renderCallback, opt_options)

Parameters:
 
renderCallback:
{function((CanvasRenderingContext2D | WebGLRenderingContext), H.map.render.RenderingParams) : H.map.render.RenderState}
 
A custom callback to render the layer's content in each animation frame. It is called with RenderingContext according to canvas type and attributes specified via opt_options and other rendering parameters. The return value of the render callback indicates the rendering state. See H.map.render.RenderState. If render callback returns H.map.render.RenderState.DONE or H.map.render.RenderState.PENDING the rendering engine might go to sleep mode. Call this.dispatchEvent('update') to restart the rendering engine. Note that due to nature of the rendering engine 2d canvas is cleared before each render loop. Note that in some cases (layer is removed from the map, engine is switched) the underlying canvas changes, therefore it might be required to reinitialize the rendering scene. In order to have higher rendering performance and responsiveness of the map it is recommended to execute any expensive operations asynchronously or – even better – in a web worker and perform only the absolute necessary operations synchronously within the render callback.
opt_options:
{H.map.layer.CanvasLayer.Options=} [optional]
 
An optional configuration object
Throws:
 
{H.lang.InvalidArgumentError}
 
If passed arguments are invalid

Method Details

isValid (zoomLevel) : {boolean}

This method checks if a zoom level can be served by the given layer.

Parameters:
 
zoomLevel:
{number}
 
The zoom level to check
Returns:
 
{boolean}
true if the given layer can provide data for the zoom level, otherwise false

setMin (min) : {H.map.layer.Layer}

This method sets the minimum zoom level at which the given layer provides content.

Parameters:
 
min:
{number}
 
The new minimum zoom level for the given layer
Returns:
 
{H.map.layer.Layer}
An object representing the given layer
Throws:
 
{H.lang.InvalidArgumentError}
 
Throws an exception if the min parameter is not a number or if it is larger that the current maximum zoom level

setMax (max) : {H.map.layer.Layer}

This method sets the maximum zoom level at which the given layer provides content.

Parameters:
 
max:
{number}
 
The new maximum zoom level for the given layer
Returns:
 
{H.map.layer.Layer}
An object representing the given layer
Throws:
 
{H.lang.InvalidArgumentError}
 
Throws an exception if the max parameter is not a number or if it is smaller that the current minimum zoom level

getCopyrights (bounds, level) : {?Array<H.map.ICopyright>}

This method retrieves the copyright of the current data provider.

Note: This function must be overridden by any class derived from Layer. The default implementation returns null.

Parameters:
 
bounds:
{H.geo.Rect}
 
The bounding area for which to retrieve the copyright information
level:
{number}
 
The zoom level for which to retrieve the copyright information
Returns:
 
{?Array<H.map.ICopyright>}
A list of copyright information objects for the provided area and zoom level

addEventListener (type, handler, opt_capture, opt_scope)

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.

Parameters:
 
type:
{string}
 
The name of the event
handler:
{!Function}
 
An event handler function
opt_capture:
{boolean=} [optional]
 
true indicates that the method should listen in the capture phase (bubble otherwise)
opt_scope:
{Object=} [optional]
 
An object defining the scope for the handler function

removeEventListener (type, handler, opt_capture, opt_scope)

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

Parameters:
 
type:
{string}
 
The name of the event
handler:
{!Function}
 
A previously added event handler
opt_capture:
{boolean=} [optional]
 
true indicates that the method should listen in the capture phase (bubble otherwise)
opt_scope:
{Object=} [optional]
 
An oject defining the scope for the handler function

dispatchEvent (evt)

This method dispatches an event on the EventTarget object.

Parameters:
 
evt:
{(H.util.Event | string)}
 
An object representing the event or a string with the event name

dispose ()

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.

addOnDisposeCallback (callback, opt_scope)

This method adds a callback which is triggered when the EventTarget object is being disposed.

Parameters:
 
callback:
{!Function}
 
The callback function.
opt_scope:
{Object=} [optional]
 
An optional scope for the callback function

Event Details

update: {H.util.Event}

Event fired when the data associated with the given layer is updated.

minchange: {H.util.ChangeEvent}

Event fired when the minimum zoom level for the given layer changes.

Deprecated:
since 3.0.7.0

maxchange: {H.util.ChangeEvent}

Event fired when the maximum zoom level for the given layer changes.

Deprecated:
since 3.0.7.0