# 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.
cachedSymbolBounds | {Object} Internal cache of calculated symbol extents.
Constructor |
OpenLayers.Renderer.Canvas |
Functions |
setExtent | Set the visible part of the layer.
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.
drawNamedSymbol | Called to draw Well Known Graphic Symbol Name.
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.

### cachedSymbolBounds

{Object} Internal cache of calculated symbol extents.

### Constructor

### OpenLayers.Renderer.Canvas

#### Parameters

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

### Functions

### setExtent

> setExtent: function()

Set the visible part of the layer.

#### Parameters

extent | {OpenLayers.Bounds}
resolutionChanged | {Boolean}

#### Returns

{Boolean} true to notify the layer that the new extent does not exceed the coordinate range, and the features will not need to be redrawn. False otherwise.

### 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}

### drawNamedSymbol

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

Called to draw Well Known Graphic Symbol Name. This method is only called by the renderer itself.

#### 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,
> | strokeScaling | )

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 undefined. 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.

> setExtent: function()

Set the visible part of the layer.

> 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.

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

Called to draw Well Known Graphic Symbol Name.

> 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,
> | strokeScaling | )

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.
Instances of this class represent bounding boxes.
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