This is the base class for all renderers.
This is based on a merger code written by Paul Spencer and Bertil Chapuis. It is largely composed of virtual functions that are to be implemented in technology-specific subclasses, but there is some generic code too.
The functions that are implemented here merely deal with the maintenance of the size and extent variables, as well as the cached ‘resolution’ value.
A note to the user that all subclasses should use getResolution() instead of directly accessing this.resolution in order to correctly use the cacheing system.
OpenLayers. | This is the base class for all renderers. |
Properties | |
container | {DOMElement} |
root | {DOMElement} |
extent | {OpenLayers.Bounds} |
locked | {Boolean} If the renderer is currently in a state where many things are changing, the ‘locked’ property is set to true. |
size | {OpenLayers.Size} |
resolution | {Float} cache of current map resolution |
map | {OpenLayers.Map} Reference to the map -- this is set in Vector’s setMap() |
featureDx | {Number} Feature offset in x direction. |
Constructor | |
OpenLayers. | |
Functions | |
destroy | |
supported | This should be overridden by specific subclasses |
setExtent | Set the visible part of the layer. |
setSize | Sets the size of the drawing surface. |
getResolution | Uses cached copy of resolution if available to minimize computing |
drawFeature | Draw the feature. |
calculateFeatureDx | {Number} Calculates the feature offset in x direction. |
drawGeometry | Draw a geometry. |
drawText | Function for drawing text labels. |
removeText | Function for removing text labels. |
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 |
eraseGeometry | Remove a geometry from the renderer (by id). |
moveRoot | moves this renderer’s root to a (different) renderer. |
getRenderLayerId | Gets the layer that this renderer’s output appears on. |
applyDefaultSymbolizer | |
Constants | |
OpenLayers. | {Object} Properties from this symbolizer will be applied to symbolizers with missing properties. |
OpenLayers. | Coordinate arrays for well known (named) symbols. |
{Boolean} If the renderer is currently in a state where many things are changing, the ‘locked’ property is set to true. This means that renderers can expect at least one more drawFeature event to be called with the ‘locked’ property set to ‘true’: In some renderers, this might make sense to use as a ‘only update local information’ flag.
{OpenLayers.Map} Reference to the map -- this is set in Vector’s setMap()
{Number} Feature offset in x direction. Will be calculated for and applied to the current feature while rendering (see calculateFeatureDx).
containerID | {String} |
options | {Object} options for this renderer. See sublcasses for supported options. |
setExtent: function( extent, resolutionChanged )
Set the visible part of the layer.
Resolution has probably changed, so we nullify the resolution cache (this.resolution) -- this way it will be re-computed when next it is needed. We nullify the resolution cache (this.resolution) if resolutionChanged is set to true - this way it will be re-computed on the next getResolution() request.
extent | {OpenLayers.Bounds} |
resolutionChanged | {Boolean} |
{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.
setSize: function( size )
Sets the size of the drawing surface.
Resolution has probably changed, so we nullify the resolution cache (this.resolution) -- this way it will be re-computed when next it is needed.
size | {OpenLayers.Size} |
drawFeature: function( feature, style )
Draw the feature. The optional style argument can be used to override the feature’s own style. This method should only be called from layer.drawFeature().
feature | {OpenLayers.Feature.Vector} |
style | {<Object>} |
{Boolean} true if the feature has been drawn completely, false if not, undefined if the feature had no geometry
calculateFeatureDx: function( bounds, worldBounds )
{Number} Calculates the feature offset in x direction. Looking at the center of the feature bounds and the renderer extent, we calculate how many world widths the two are away from each other. This distance is used to shift the feature as close as possible to the center of the current enderer extent, which ensures that the feature is visible in the current viewport.
bounds | {OpenLayers.Bounds} Bounds of the feature |
worldBounds | {OpenLayers.Bounds} Bounds of the world |
drawGeometry: function( geometry, style, featureId )
Draw a geometry. This should only be called from the renderer itself. Use layer.drawFeature() from outside the renderer. virtual function
geometry | {OpenLayers.Geometry} |
style | {Object} |
featureId | {String} |
drawText: function( featureId, style, location )
Function for drawing text labels. This method is only called by the renderer itself.
featureId | {String} style - |
location | {OpenLayers.Geometry.Point} |
getFeatureIdFromEvent: function( evt )
Returns a feature id from an event on the renderer. How this happens is specific to the renderer. This should be called from layer.getFeatureFromEvent(). Virtual function.
evt | {OpenLayers.Event} |
{String} A feature id or undefined.
eraseFeatures: function( features )
This is called by the layer to erase features
features | {Array(OpenLayers.Feature.Vector)} |
eraseGeometry: function( geometry, featureId )
Remove a geometry from the renderer (by id). virtual function.
geometry | {OpenLayers.Geometry} |
featureId | {String} |
moveRoot: function( renderer )
moves this renderer’s root to a (different) renderer. To be implemented by subclasses that require a common renderer root for feature selection.
renderer | {OpenLayers.Renderer} target renderer for the moved root |
{Object} Properties from this symbolizer will be applied to symbolizers with missing properties. This can also be used to set a global symbolizer default in OpenLayers. To be SLD 1.x compliant, add the following code before rendering any vector features:
OpenLayers.Renderer.defaultSymbolizer = { fillColor: "#808080", fillOpacity: 1, strokeColor: "#000000", strokeOpacity: 1, strokeWidth: 1, pointRadius: 3, graphicName: "square" };
destroy: function()
This should be overridden by specific subclasses
supported: function()
Set the visible part of the layer.
setExtent: function( extent, resolutionChanged )
Sets the size of the drawing surface.
setSize: function( size )
Uses cached copy of resolution if available to minimize computing
getResolution: function()
Draw the feature.
drawFeature: function( feature, style )
{Number} Calculates the feature offset in x direction.
calculateFeatureDx: function( bounds, worldBounds )
Draw a geometry.
drawGeometry: function( geometry, style, featureId )
Function for drawing text labels.
drawText: function( featureId, style, location )
Function for removing text labels.
removeText: function( featureId )
Clear all vectors from the renderer.
clear: function()
Returns a feature id from an event on the renderer.
getFeatureIdFromEvent: function( evt )
This is called by the layer to erase features
eraseFeatures: function( features )
Remove a geometry from the renderer (by id).
eraseGeometry: function( geometry, featureId )
moves this renderer’s root to a (different) renderer.
moveRoot: function( renderer )
Gets the layer that this renderer’s output appears on.
getRenderLayerId: function()
applyDefaultSymbolizer: function( symbolizer )