Renderer.js
4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
* See http://svn.openlayers.org/trunk/openlayers/release-license.txt
* for the full text of the license. */
/**
* @class Renderer 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.Renderer = OpenLayers.Class.create();
OpenLayers.Renderer.prototype =
{
/** @type DOMElement */
container: null,
/** @type OpenLayers.Bounds */
extent: null,
/** @type OpenLayers.Size */
size: null,
/** cache of current map resolution
* @type float */
resolution: null,
/** Reference to the map -- this is set in Vector's setMap()
* @type OpenLayers.Map */
map: null,
/**
* @constructor
*
* @param {String} containerID
*/
initialize: function(containerID) {
this.container = $(containerID);
},
/**
*
*/
destroy: function() {
this.container = null;
this.extent = null;
this.size = null;
this.resolution = null;
this.map = null;
},
/**
* This should be overridden by specific subclasses
*
* @returns Whether or not the browser supports the VML renderer
* @type Boolean
*/
supported: function() {
return false;
},
/**
* 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.
*
* @param {OpenLayers.Bounds} extent
*/
setExtent: function(extent) {
this.extent = extent.clone();
this.resolution = null;
},
/**
* 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.
*
* @param {OpenLayers.Size} size
*/
setSize: function(size) {
this.size = size.clone();
this.resolution = null;
},
/** Uses cached copy of resolution if available to minimize computing
*
* @returns The current map's resolution
* @type float
*/
getResolution: function() {
this.resolution = this.resolution || this.map.getResolution();
return this.resolution;
},
/**
* 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().
*
* @param {OpenLayers.Feature.Vector} feature
* @param {Object} style
* @private
*/
drawFeature: function(feature, style) {
if(style == null) {
style = feature.style;
}
this.drawGeometry(feature.geometry, style, feature.id);
},
/**
* virtual function
*
* Draw a geometry. This should only be called from the renderer itself.
* Use layer.drawFeature() from outside the renderer.
*
* @param geometry {OpenLayers.Geometry}
* @param style {Object}
* @param {String} featureId
* @private
*/
drawGeometry: function(geometry, style, featureId) {},
/**
* virtual function
*
* Clear all vectors from the renderer
* @private
*/
clear: function() {},
/**
* virtual function
*
* 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().
*
* @param evt {OpenLayers.Event}
*
* @returns A feature id or null
* @type String
* @private
*/
getFeatureIdFromEvent: function(evt) {},
/**
* This is called by the layer to erase features
* @param {Array(OpenLayers.Feature.Vector)} features
* @private
*/
eraseFeatures: function(features) {
if(!(features instanceof Array)) {
features = [features];
}
for(var i=0; i<features.length; ++i) {
this.eraseGeometry(features[i].geometry);
}
},
/**
* virtual function
*
* Remove a geometry from the renderer (by id)
*
* @param geometry {OpenLayers.Geometry}
* @private
*/
eraseGeometry: function(geometry) {},
/** @final @type String */
CLASS_NAME: "OpenLayers.Renderer"
};