1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
6
* Class: OpenLayers.Renderer
7
* This is the base class for all renderers.
9
* This is based on a merger code written by Paul Spencer and Bertil Chapuis.
10
* It is largely composed of virtual functions that are to be implemented
11
* in technology-specific subclasses, but there is some generic code too.
13
* The functions that *are* implemented here merely deal with the maintenance
14
* of the size and extent variables, as well as the cached 'resolution'
17
* A note to the user that all subclasses should use getResolution() instead
18
* of directly accessing this.resolution in order to correctly use the
22
OpenLayers.Renderer = OpenLayers.Class({
32
* {<OpenLayers.Bounds>}
38
* {Boolean} If the renderer is currently in a state where many things
39
* are changing, the 'locked' property is set to true. This means
40
* that renderers can expect at least one more drawFeature event to be
41
* called with the 'locked' property set to 'true': In some renderers,
42
* this might make sense to use as a 'only update local information'
54
* Property: resolution
55
* {Float} cache of current map resolution
61
* {<OpenLayers.Map>} Reference to the map -- this is set in Vector's setMap()
66
* Constructor: OpenLayers.Renderer
69
* containerID - {<String>}
70
* options - {Object} options for this renderer. See sublcasses for
73
initialize: function(containerID, options) {
74
this.container = OpenLayers.Util.getElement(containerID);
81
this.container = null;
84
this.resolution = null;
89
* APIMethod: supported
90
* This should be overridden by specific subclasses
93
* {Boolean} Whether or not the browser supports the renderer class
95
supported: function() {
101
* Set the visible part of the layer.
103
* Resolution has probably changed, so we nullify the resolution
104
* cache (this.resolution) -- this way it will be re-computed when
106
* We nullify the resolution cache (this.resolution) if resolutionChanged
107
* is set to true - this way it will be re-computed on the next
108
* getResolution() request.
111
* extent - {<OpenLayers.Bounds>}
112
* resolutionChanged - {Boolean}
114
setExtent: function(extent, resolutionChanged) {
115
this.extent = extent.clone();
116
if (resolutionChanged) {
117
this.resolution = null;
123
* Sets the size of the drawing surface.
125
* Resolution has probably changed, so we nullify the resolution
126
* cache (this.resolution) -- this way it will be re-computed when
130
* size - {<OpenLayers.Size>}
132
setSize: function(size) {
133
this.size = size.clone();
134
this.resolution = null;
138
* Method: getResolution
139
* Uses cached copy of resolution if available to minimize computing
142
* The current map's resolution
144
getResolution: function() {
145
this.resolution = this.resolution || this.map.getResolution();
146
return this.resolution;
150
* Method: drawFeature
151
* Draw the feature. The optional style argument can be used
152
* to override the feature's own style. This method should only
153
* be called from layer.drawFeature().
156
* feature - {<OpenLayers.Feature.Vector>}
160
* {Boolean} true if the feature has been drawn completely, false if not,
161
* undefined if the feature had no geometry
163
drawFeature: function(feature, style) {
165
style = feature.style;
167
if (feature.geometry) {
168
var bounds = feature.geometry.getBounds();
170
if (!bounds.intersectsBounds(this.extent)) {
171
style = {display: "none"};
173
return this.drawGeometry(feature.geometry, style, feature.id);
180
* Method: drawGeometry
182
* Draw a geometry. This should only be called from the renderer itself.
183
* Use layer.drawFeature() from outside the renderer.
187
* geometry - {<OpenLayers.Geometry>}
189
* featureId - {<String>}
191
drawGeometry: function(geometry, style, featureId) {},
195
* Clear all vectors from the renderer.
198
clear: function() {},
201
* Method: getFeatureIdFromEvent
202
* Returns a feature id from an event on the renderer.
203
* How this happens is specific to the renderer. This should be
204
* called from layer.getFeatureFromEvent().
208
* evt - {<OpenLayers.Event>}
211
* {String} A feature id or null.
213
getFeatureIdFromEvent: function(evt) {},
216
* Method: eraseFeatures
217
* This is called by the layer to erase features
220
* features - {Array(<OpenLayers.Feature.Vector>)}
222
eraseFeatures: function(features) {
223
if(!(features instanceof Array)) {
224
features = [features];
226
for(var i=0, len=features.length; i<len; ++i) {
227
this.eraseGeometry(features[i].geometry);
232
* Method: eraseGeometry
233
* Remove a geometry from the renderer (by id).
237
* geometry - {<OpenLayers.Geometry>}
239
eraseGeometry: function(geometry) {},
241
CLASS_NAME: "OpenLayers.Renderer"
b'\\ No newline at end of file'