~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Renderer.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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. */
 
4
 
 
5
/**
 
6
 * Class: OpenLayers.Renderer 
 
7
 * This is the base class for all renderers.
 
8
 *
 
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.
 
12
 * 
 
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' 
 
15
 *  value. 
 
16
 * 
 
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 
 
19
 *  cacheing system.
 
20
 *
 
21
 */
 
22
OpenLayers.Renderer = OpenLayers.Class({
 
23
 
 
24
    /** 
 
25
     * Property: container
 
26
     * {DOMElement} 
 
27
     */
 
28
    container: null,
 
29
    
 
30
    /** 
 
31
     * Property: extent
 
32
     * {<OpenLayers.Bounds>}
 
33
     */
 
34
    extent: null,
 
35
 
 
36
    /**
 
37
     * Property: locked
 
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'
 
43
     *     flag. 
 
44
     */  
 
45
    locked: false,
 
46
    
 
47
    /** 
 
48
     * Property: size
 
49
     * {<OpenLayers.Size>} 
 
50
     */
 
51
    size: null,
 
52
    
 
53
    /**
 
54
     * Property: resolution
 
55
     * {Float} cache of current map resolution
 
56
     */
 
57
    resolution: null,
 
58
    
 
59
    /**
 
60
     * Property: map  
 
61
     * {<OpenLayers.Map>} Reference to the map -- this is set in Vector's setMap()
 
62
     */
 
63
    map: null,
 
64
    
 
65
    /**
 
66
     * Constructor: OpenLayers.Renderer 
 
67
     *
 
68
     * Parameters:
 
69
     * containerID - {<String>} 
 
70
     * options - {Object} options for this renderer. See sublcasses for
 
71
     *     supported options.
 
72
     */
 
73
    initialize: function(containerID, options) {
 
74
        this.container = OpenLayers.Util.getElement(containerID);
 
75
    },
 
76
    
 
77
    /**
 
78
     * APIMethod: destroy
 
79
     */
 
80
    destroy: function() {
 
81
        this.container = null;
 
82
        this.extent = null;
 
83
        this.size =  null;
 
84
        this.resolution = null;
 
85
        this.map = null;
 
86
    },
 
87
 
 
88
    /**
 
89
     * APIMethod: supported
 
90
     * This should be overridden by specific subclasses
 
91
     * 
 
92
     * Returns:
 
93
     * {Boolean} Whether or not the browser supports the renderer class
 
94
     */
 
95
    supported: function() {
 
96
        return false;
 
97
    },    
 
98
    
 
99
    /**
 
100
     * Method: setExtent
 
101
     * Set the visible part of the layer.
 
102
     *
 
103
     * Resolution has probably changed, so we nullify the resolution 
 
104
     * cache (this.resolution) -- this way it will be re-computed when 
 
105
     * next it is needed.
 
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.
 
109
     *
 
110
     * Parameters:
 
111
     * extent - {<OpenLayers.Bounds>}
 
112
     * resolutionChanged - {Boolean}
 
113
     */
 
114
    setExtent: function(extent, resolutionChanged) {
 
115
        this.extent = extent.clone();
 
116
        if (resolutionChanged) {
 
117
            this.resolution = null;
 
118
        }
 
119
    },
 
120
    
 
121
    /**
 
122
     * Method: setSize
 
123
     * Sets the size of the drawing surface.
 
124
     * 
 
125
     * Resolution has probably changed, so we nullify the resolution 
 
126
     * cache (this.resolution) -- this way it will be re-computed when 
 
127
     * next it is needed.
 
128
     *
 
129
     * Parameters:
 
130
     * size - {<OpenLayers.Size>} 
 
131
     */
 
132
    setSize: function(size) {
 
133
        this.size = size.clone();
 
134
        this.resolution = null;
 
135
    },
 
136
    
 
137
    /** 
 
138
     * Method: getResolution
 
139
     * Uses cached copy of resolution if available to minimize computing
 
140
     * 
 
141
     * Returns:
 
142
     * The current map's resolution
 
143
     */
 
144
    getResolution: function() {
 
145
        this.resolution = this.resolution || this.map.getResolution();
 
146
        return this.resolution;
 
147
    },
 
148
    
 
149
    /**
 
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().
 
154
     *
 
155
     * Parameters:
 
156
     * feature - {<OpenLayers.Feature.Vector>} 
 
157
     * style - {<Object>}
 
158
     * 
 
159
     * Returns:
 
160
     * {Boolean} true if the feature has been drawn completely, false if not,
 
161
     *     undefined if the feature had no geometry
 
162
     */
 
163
    drawFeature: function(feature, style) {
 
164
        if(style == null) {
 
165
            style = feature.style;
 
166
        }
 
167
        if (feature.geometry) {
 
168
            var bounds = feature.geometry.getBounds();
 
169
            if(bounds) {
 
170
                if (!bounds.intersectsBounds(this.extent)) {
 
171
                    style = {display: "none"};
 
172
                }
 
173
                return this.drawGeometry(feature.geometry, style, feature.id);
 
174
            }
 
175
        }
 
176
    },
 
177
 
 
178
 
 
179
    /** 
 
180
     * Method: drawGeometry
 
181
     * 
 
182
     * Draw a geometry.  This should only be called from the renderer itself.
 
183
     * Use layer.drawFeature() from outside the renderer.
 
184
     * virtual function
 
185
     *
 
186
     * Parameters:
 
187
     * geometry - {<OpenLayers.Geometry>} 
 
188
     * style - {Object} 
 
189
     * featureId - {<String>} 
 
190
     */
 
191
    drawGeometry: function(geometry, style, featureId) {},
 
192
        
 
193
    /**
 
194
     * Method: clear
 
195
     * Clear all vectors from the renderer.
 
196
     * virtual function.
 
197
     */    
 
198
    clear: function() {},
 
199
 
 
200
    /**
 
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().
 
205
     * Virtual function.
 
206
     * 
 
207
     * Parameters:
 
208
     * evt - {<OpenLayers.Event>} 
 
209
     *
 
210
     * Returns:
 
211
     * {String} A feature id or null.
 
212
     */
 
213
    getFeatureIdFromEvent: function(evt) {},
 
214
    
 
215
    /**
 
216
     * Method: eraseFeatures 
 
217
     * This is called by the layer to erase features
 
218
     * 
 
219
     * Parameters:
 
220
     * features - {Array(<OpenLayers.Feature.Vector>)} 
 
221
     */
 
222
    eraseFeatures: function(features) {
 
223
        if(!(features instanceof Array)) {
 
224
            features = [features];
 
225
        }
 
226
        for(var i=0, len=features.length; i<len; ++i) {
 
227
            this.eraseGeometry(features[i].geometry);
 
228
        }
 
229
    },
 
230
    
 
231
    /**
 
232
     * Method: eraseGeometry
 
233
     * Remove a geometry from the renderer (by id).
 
234
     * virtual function.
 
235
     * 
 
236
     * Parameters:
 
237
     * geometry - {<OpenLayers.Geometry>} 
 
238
     */
 
239
    eraseGeometry: function(geometry) {},
 
240
 
 
241
    CLASS_NAME: "OpenLayers.Renderer"
 
242
});
 
 
b'\\ No newline at end of file'