# OpenLayers.Renderer.Canvas

A renderer based on the 2D ‘canvas’ drawing element.

#### Inherits

- OpenLayers.Renderer

Summary

OpenLayers.Renderer.Canvas | A renderer based on the 2D ‘canvas’ drawing element.
Properties |
hitDetection | {Boolean} Allow for hit detection of features.
hitOverflow | {Number} The method for converting feature identifiers to color values supports 16777215 sequential values.
canvas | {Canvas} The canvas context object.
features | {Object} Internal object of feature/style pairs for use in redrawing the layer.
pendingRedraw | {Boolean} The renderer needs a redraw call to render features added while the renderer was locked.
Constructor |
OpenLayers.Renderer.Canvas |
Functions |
eraseGeometry | Erase a geometry from the renderer.
supported | {Boolean} Whether or not the browser supports the renderer class
setSize | Sets the size of the drawing surface.
drawFeature | Draw the feature.
drawGeometry | Used when looping (in redraw) over the features; draws the canvas.
drawExternalGraphic | Called to draw External graphics.
setCanvasStyle | Prepare the canvas for drawing by setting various global settings.
featureIdToHex | Convert a feature ID string into an RGB hex string.
setHitContextStyle | Prepare the hit canvas for drawing by setting various global settings.
drawPoint | This method is only called by the renderer itself.
drawLineString | This method is only called by the renderer itself.
drawLinearRing | This method is only called by the renderer itself.
renderPath | Render a path with stroke and optional fill.
drawPolygon | This method is only called by the renderer itself.
drawText | This method is only called by the renderer itself.
getLocalXY | transform geographic xy into pixel xy
clear | Clear all vectors from the renderer.
getFeatureIdFromEvent | Returns a feature id from an event on the renderer.
eraseFeatures | This is called by the layer to erase features; removes the feature from the list, then redraws the layer.
redraw | The real ‘meat’ of the function: any time things have changed, redraw() can be called to loop over all the data and (you guessed it) redraw it.
Constants |
OpenLayers.Renderer.Canvas.LABEL_ALIGN | {Object}
OpenLayers.Renderer.Canvas.LABEL_FACTOR | {Object}
OpenLayers.Renderer.Canvas.drawImageScaleFactor | {Number} Scale factor to apply to the canvas drawImage arguments.

### Properties

### hitDetection

{Boolean} Allow for hit detection of features. Default is true.

### hitOverflow

{Number} The method for converting feature identifiers to color values supports 16777215 sequential values. Two features cannot be predictably detected if their identifiers differ by more than this value. The hitOverflow allows for bigger numbers (but the difference in values is still limited).

### canvas

{Canvas} The canvas context object.

### features

{Object} Internal object of feature/style pairs for use in redrawing the layer.

### pendingRedraw

{Boolean} The renderer needs a redraw call to render features added while the renderer was locked.

### Constructor

### OpenLayers.Renderer.Canvas

#### Parameters

containerID | {String}
options | {Object} Optional properties to be set on the renderer.

### Functions

### eraseGeometry

> eraseGeometry: function( | geometry,
> | featureId | )

Erase a geometry from the renderer. Because the Canvas renderer has ‘memory’ of the features that it has drawn, we have to remove the feature so it doesn’t redraw.

#### Parameters

geometry | {OpenLayers.Geometry}
featureId | {String}

### supported

> supported: function()

#### Returns

{Boolean} Whether or not the browser supports the renderer class

### setSize

> setSize: function( | size | )

Sets the size of the drawing surface.

Once the size is updated, redraw the canvas.

#### Parameters

size | {OpenLayers.Size}

### drawFeature

> drawFeature: function( | feature,
> | style | )

Draw the feature. Stores the feature in the features list, then redraws the layer.

#### Parameters

feature | {OpenLayers.Feature.Vector}
style | {<Object>}

#### Returns

{Boolean} The feature has been drawn completely. If the feature has no geometry, undefined will be returned. If the feature is not rendered for other reasons, false will be returned.

### drawGeometry

> drawGeometry: function( | geometry,
> | style,
> | featureId | )

Used when looping (in redraw) over the features; draws the canvas.

#### Parameters

geometry | {OpenLayers.Geometry}
style | {Object}

### drawExternalGraphic

> drawExternalGraphic: function( | geometry,
> | style,
> | featureId | )

Called to draw External graphics.

#### Parameters

geometry | {OpenLayers.Geometry}
style | {Object}
featureId | {String}

### setCanvasStyle

> setCanvasStyle: function( | type,
> | style | )

Prepare the canvas for drawing by setting various global settings.

#### Parameters

type | {String} one of ‘stroke’, ‘fill’, or ‘reset’
style | {Object} Symbolizer hash

### featureIdToHex

> featureIdToHex: function( | featureId | )

Convert a feature ID string into an RGB hex string.

#### Parameters

featureId | {String} Feature id

#### Returns

{String} RGB hex string.

### setHitContextStyle

> setHitContextStyle: function( | type,
> | featureId,
> | symbolizer | )

Prepare the hit canvas for drawing by setting various global settings.

#### Parameters

type | {String} one of ‘stroke’, ‘fill’, or ‘reset’
featureId | {String} The feature id.
symbolizer | {OpenLayers.Symbolizer} The symbolizer.

### drawPoint

> drawPoint: function( | geometry,
> | style,
> | featureId | )

This method is only called by the renderer itself.

#### Parameters

geometry | {OpenLayers.Geometry}
style | {Object}
featureId | {String}

### drawLineString

> drawLineString: function( | geometry,
> | style,
> | featureId | )

This method is only called by the renderer itself.

#### Parameters

geometry | {OpenLayers.Geometry}
style | {Object}
featureId | {String}

### drawLinearRing

> drawLinearRing: function( | geometry,
> | style,
> | featureId | )

This method is only called by the renderer itself.

#### Parameters

geometry | {OpenLayers.Geometry}
style | {Object}
featureId | {String}

### renderPath

> renderPath: function( | context,
> | geometry,
> | style,
> | featureId,
> | type | )

Render a path with stroke and optional fill.

### drawPolygon

> drawPolygon: function( | geometry,
> | style,
> | featureId | )

This method is only called by the renderer itself.

#### Parameters

geometry | {OpenLayers.Geometry}
style | {Object}
featureId | {String}

### drawText

> drawText: function( | location,
> | style | )

This method is only called by the renderer itself.

#### Parameters

location | {<OpenLayers.Point>}
style | {Object}

### getLocalXY

> getLocalXY: function( | point | )

transform geographic xy into pixel xy

#### Parameters

point | {OpenLayers.Geometry.Point}

### clear

> clear: function()

Clear all vectors from the renderer.

### getFeatureIdFromEvent

> getFeatureIdFromEvent: function( | evt | )

Returns a feature id from an event on the renderer.

#### Parameters

evt | {OpenLayers.Event}

#### Returns

{<OpenLayers.Feature.Vector} A feature or null. This method returns a feature instead of a feature id to avoid an unnecessary lookup on the layer.

### eraseFeatures

> eraseFeatures: function( | features | )

This is called by the layer to erase features; removes the feature from the list, then redraws the layer.

#### Parameters

features | {Array(OpenLayers.Feature.Vector)}

### redraw

> redraw: function()

The real ‘meat’ of the function: any time things have changed, redraw() can be called to loop over all the data and (you guessed it) redraw it. Unlike Elements-based Renderers, we can’t interact with things once they’re drawn, to remove them, for example, so instead we have to just clear everything and draw from scratch.

### Constants

### OpenLayers.Renderer.Canvas.LABEL_ALIGN

{Object}

### OpenLayers.Renderer.Canvas.LABEL_FACTOR

{Object}

### OpenLayers.Renderer.Canvas.drawImageScaleFactor

{Number} Scale factor to apply to the canvas drawImage arguments. This is always 1 except for Android 2.1 devices, to work around http://code.google.com/p/android/issues/detail?id=5141.

> eraseGeometry: function( | geometry,
> | featureId | )

Erase a geometry from the renderer.

> supported: function()

{Boolean} Whether or not the browser supports the renderer class

> setSize: function( | size | )

Sets the size of the drawing surface.

> drawFeature: function( | feature,
> | style | )

Draw the feature.

> drawGeometry: function( | geometry,
> | style,
> | featureId | )

Used when looping (in redraw) over the features; draws the canvas.

> drawExternalGraphic: function( | geometry,
> | style,
> | featureId | )

Called to draw External graphics.

> setCanvasStyle: function( | type,
> | style | )

Prepare the canvas for drawing by setting various global settings.

> featureIdToHex: function( | featureId | )

Convert a feature ID string into an RGB hex string.

> setHitContextStyle: function( | type,
> | featureId,
> | symbolizer | )

Prepare the hit canvas for drawing by setting various global settings.

> drawPoint: function( | geometry,
> | style,
> | featureId | )

This method is only called by the renderer itself.

> drawLineString: function( | geometry,
> | style,
> | featureId | )

This method is only called by the renderer itself.

> drawLinearRing: function( | geometry,
> | style,
> | featureId | )

This method is only called by the renderer itself.

> renderPath: function( | context,
> | geometry,
> | style,
> | featureId,
> | type | )

Render a path with stroke and optional fill.

> drawPolygon: function( | geometry,
> | style,
> | featureId | )

This method is only called by the renderer itself.

> drawText: function( | location,
> | style | )

This method is only called by the renderer itself.

> getLocalXY: function( | point | )

transform geographic xy into pixel xy

> clear: function()

Clear all vectors from the renderer.

> getFeatureIdFromEvent: function( | evt | )

Returns a feature id from an event on the renderer.

> eraseFeatures: function( | features | )

This is called by the layer to erase features; removes the feature from the list, then redraws the layer.

> redraw: function()

The real ‘meat’ of the function: any time things have changed, redraw() can be called to loop over all the data and (you guessed it) redraw it.
This is the base class for all renderers.
Contains convenience functions for string manipulation.
A Geometry is a description of a geographic object.
Instances of this class represent a width/height pair
Vector features use the OpenLayers.Geometry classes as geometry description.
Base class representing a symbolizer used for feature rendering.
Point geometry class.
Utility functions for event handling.
Close