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

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Feature/Vector.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
// TRASH THIS
 
6
OpenLayers.State = {
 
7
    /** states */
 
8
    UNKNOWN: 'Unknown',
 
9
    INSERT: 'Insert',
 
10
    UPDATE: 'Update',
 
11
    DELETE: 'Delete'
 
12
};
 
13
 
 
14
/**
 
15
 * @requires OpenLayers/Feature.js
 
16
 * @requires OpenLayers/Util.js
 
17
 */
 
18
 
 
19
/**
 
20
 * Class: OpenLayers.Feature.Vector
 
21
 * Vector features use the OpenLayers.Geometry classes as geometry description.
 
22
 * They have an 'attributes' property, which is the data object, and a 'style'
 
23
 * property, the default values of which are defined in the 
 
24
 * <OpenLayers.Feature.Vector.style> objects.
 
25
 * 
 
26
 * Inherits from:
 
27
 *  - <OpenLayers.Feature>
 
28
 */
 
29
OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
 
30
 
 
31
    /** 
 
32
     * Property: fid 
 
33
     * {String} 
 
34
     */
 
35
    fid: null,
 
36
    
 
37
    /** 
 
38
     * APIProperty: geometry 
 
39
     * {<OpenLayers.Geometry>} 
 
40
     */
 
41
    geometry: null,
 
42
 
 
43
    /** 
 
44
     * APIProperty: attributes 
 
45
     * {Object} This object holds arbitrary properties that describe the
 
46
     *     feature.
 
47
     */
 
48
    attributes: null,
 
49
 
 
50
    /** 
 
51
     * Property: state 
 
52
     * {String} 
 
53
     */
 
54
    state: null,
 
55
    
 
56
    /** 
 
57
     * APIProperty: style 
 
58
     * {Object} 
 
59
     */
 
60
    style: null,
 
61
    
 
62
    /**
 
63
     * Property: renderIntent
 
64
     * {String} rendering intent currently being used
 
65
     */
 
66
    renderIntent: "default",
 
67
 
 
68
    /** 
 
69
     * Constructor: OpenLayers.Feature.Vector
 
70
     * Create a vector feature. 
 
71
     * 
 
72
     * Parameters:
 
73
     * geometry - {<OpenLayers.Geometry>} The geometry that this feature
 
74
     *     represents.
 
75
     * attributes - {Object} An optional object that will be mapped to the
 
76
     *     <attributes> property. 
 
77
     * style - {Object} An optional style object.
 
78
     */
 
79
    initialize: function(geometry, attributes, style) {
 
80
        OpenLayers.Feature.prototype.initialize.apply(this,
 
81
                                                      [null, null, attributes]);
 
82
        this.lonlat = null;
 
83
        this.geometry = geometry ? geometry : null;
 
84
        this.state = null;
 
85
        this.attributes = {};
 
86
        if (attributes) {
 
87
            this.attributes = OpenLayers.Util.extend(this.attributes,
 
88
                                                     attributes);
 
89
        }
 
90
        this.style = style ? style : null; 
 
91
    },
 
92
    
 
93
    /** 
 
94
     * Method: destroy
 
95
     * nullify references to prevent circular references and memory leaks
 
96
     */
 
97
    destroy: function() {
 
98
        if (this.layer) {
 
99
            this.layer.removeFeatures(this);
 
100
            this.layer = null;
 
101
        }
 
102
            
 
103
        this.geometry = null;
 
104
        OpenLayers.Feature.prototype.destroy.apply(this, arguments);
 
105
    },
 
106
    
 
107
    /**
 
108
     * Method: clone
 
109
     * Create a clone of this vector feature.  Does not set any non-standard
 
110
     *     properties.
 
111
     *
 
112
     * Returns:
 
113
     * {<OpenLayers.Feature.Vector>} An exact clone of this vector feature.
 
114
     */
 
115
    clone: function () {
 
116
        return new OpenLayers.Feature.Vector(
 
117
            this.geometry ? this.geometry.clone() : null,
 
118
            this.attributes,
 
119
            this.style);
 
120
    },
 
121
 
 
122
    /**
 
123
     * Method: onScreen
 
124
     * Determine whether the feature is within the map viewport.  This method
 
125
     *     tests for an intersection between the geometry and the viewport
 
126
     *     bounds.  If a more effecient but less precise geometry bounds
 
127
     *     intersection is desired, call the method with the boundsOnly
 
128
     *     parameter true.
 
129
     *
 
130
     * Parameters:
 
131
     * boundsOnly - {Boolean} Only test whether a feature's bounds intersects
 
132
     *     the viewport bounds.  Default is false.  If false, the feature's
 
133
     *     geometry must intersect the viewport for onScreen to return true.
 
134
     * 
 
135
     * Returns:
 
136
     * {Boolean} The feature is currently visible on screen (optionally
 
137
     *     based on its bounds if boundsOnly is true).
 
138
     */
 
139
    onScreen:function(boundsOnly) {
 
140
        var onScreen = false;
 
141
        if(this.layer && this.layer.map) {
 
142
            var screenBounds = this.layer.map.getExtent();
 
143
            if(boundsOnly) {
 
144
                var featureBounds = this.geometry.getBounds();
 
145
                onScreen = screenBounds.intersectsBounds(featureBounds);
 
146
            } else {
 
147
                var screenPoly = screenBounds.toGeometry();
 
148
                onScreen = screenPoly.intersects(this.geometry);
 
149
            }
 
150
        }    
 
151
        return onScreen;
 
152
    },
 
153
    
 
154
    /**
 
155
     * Method: createMarker
 
156
     * HACK - we need to decide if all vector features should be able to
 
157
     *     create markers
 
158
     * 
 
159
     * Returns:
 
160
     * {<OpenLayers.Marker>} For now just returns null
 
161
     */
 
162
    createMarker: function() {
 
163
        return null;
 
164
    },
 
165
 
 
166
    /**
 
167
     * Method: destroyMarker
 
168
     * HACK - we need to decide if all vector features should be able to
 
169
     *     delete markers
 
170
     * 
 
171
     * If user overrides the createMarker() function, s/he should be able
 
172
     *   to also specify an alternative function for destroying it
 
173
     */
 
174
    destroyMarker: function() {
 
175
        // pass
 
176
    },
 
177
 
 
178
    /**
 
179
     * Method: createPopup
 
180
     * HACK - we need to decide if all vector features should be able to
 
181
     *     create popups
 
182
     * 
 
183
     * Returns:
 
184
     * {<OpenLayers.Popup>} For now just returns null
 
185
     */
 
186
    createPopup: function() {
 
187
        return null;
 
188
    },
 
189
 
 
190
    /**
 
191
     * Method: atPoint
 
192
     * Determins whether the feature intersects with the specified location.
 
193
     * 
 
194
     * Parameters: 
 
195
     * lonlat - {<OpenLayers.LonLat>} 
 
196
     * toleranceLon - {float} Optional tolerance in Geometric Coords
 
197
     * toleranceLat - {float} Optional tolerance in Geographic Coords
 
198
     * 
 
199
     * Returns:
 
200
     * {Boolean} Whether or not the feature is at the specified location
 
201
     */
 
202
    atPoint: function(lonlat, toleranceLon, toleranceLat) {
 
203
        var atPoint = false;
 
204
        if(this.geometry) {
 
205
            atPoint = this.geometry.atPoint(lonlat, toleranceLon, 
 
206
                                                    toleranceLat);
 
207
        }
 
208
        return atPoint;
 
209
    },
 
210
 
 
211
    /**
 
212
     * Method: destroyPopup
 
213
     * HACK - we need to decide if all vector features should be able to
 
214
     * delete popups
 
215
     */
 
216
    destroyPopup: function() {
 
217
        // pass
 
218
    },
 
219
 
 
220
    /**
 
221
     * Method: move
 
222
     * Moves the feature and redraws it at its new location
 
223
     *
 
224
     * Parameters:
 
225
     * state - {OpenLayers.LonLat or OpenLayers.Pixel} the
 
226
     *         location to which to move the feature.
 
227
     */
 
228
    move: function(location) {
 
229
 
 
230
        if(!this.layer || !this.geometry.move){
 
231
            //do nothing if no layer or immoveable geometry
 
232
            return;
 
233
        }
 
234
 
 
235
        var pixel;
 
236
        if (location.CLASS_NAME == "OpenLayers.LonLat") {
 
237
            pixel = this.layer.getViewPortPxFromLonLat(location);
 
238
        } else {
 
239
            pixel = location;
 
240
        }
 
241
        
 
242
        var lastPixel = this.layer.getViewPortPxFromLonLat(this.geometry.getBounds().getCenterLonLat());
 
243
        var res = this.layer.map.getResolution();
 
244
        this.geometry.move(res * (pixel.x - lastPixel.x),
 
245
                           res * (lastPixel.y - pixel.y));
 
246
        this.layer.drawFeature(this);
 
247
        return lastPixel;
 
248
    },
 
249
    
 
250
    /**
 
251
     * Method: toState
 
252
     * Sets the new state
 
253
     *
 
254
     * Parameters:
 
255
     * state - {String} 
 
256
     */
 
257
    toState: function(state) {
 
258
        if (state == OpenLayers.State.UPDATE) {
 
259
            switch (this.state) {
 
260
                case OpenLayers.State.UNKNOWN:
 
261
                case OpenLayers.State.DELETE:
 
262
                    this.state = state;
 
263
                    break;
 
264
                case OpenLayers.State.UPDATE:
 
265
                case OpenLayers.State.INSERT:
 
266
                    break;
 
267
            }
 
268
        } else if (state == OpenLayers.State.INSERT) {
 
269
            switch (this.state) {
 
270
                case OpenLayers.State.UNKNOWN:
 
271
                    break;
 
272
                default:
 
273
                    this.state = state;
 
274
                    break;
 
275
            }
 
276
        } else if (state == OpenLayers.State.DELETE) {
 
277
            switch (this.state) {
 
278
                case OpenLayers.State.INSERT:
 
279
                    // the feature should be destroyed
 
280
                    break;
 
281
                case OpenLayers.State.DELETE:
 
282
                    break;
 
283
                case OpenLayers.State.UNKNOWN:
 
284
                case OpenLayers.State.UPDATE:
 
285
                    this.state = state;
 
286
                    break;
 
287
            }
 
288
        } else if (state == OpenLayers.State.UNKNOWN) {
 
289
            this.state = state;
 
290
        }
 
291
    },
 
292
    
 
293
    CLASS_NAME: "OpenLayers.Feature.Vector"
 
294
});
 
295
 
 
296
 
 
297
/**
 
298
 * Constant: OpenLayers.Feature.Vector.style
 
299
 * OpenLayers features can have a number of style attributes. The 'default' 
 
300
 *     style will typically be used if no other style is specified.
 
301
 *
 
302
 * Default style properties:
 
303
 *
 
304
 *  - fillColor: "#ee9900",
 
305
 *  - fillOpacity: 0.4, 
 
306
 *  - hoverFillColor: "white",
 
307
 *  - hoverFillOpacity: 0.8,
 
308
 *  - strokeColor: "#ee9900",
 
309
 *  - strokeOpacity: 1,
 
310
 *  - strokeWidth: 1,
 
311
 *  - strokeLinecap: "round",  [butt | round | square]
 
312
 *  - strokeDashstyle: "solid", [dot | dash | dashdot | longdash | longdashdot | solid]
 
313
 *  - hoverStrokeColor: "red",
 
314
 *  - hoverStrokeOpacity: 1,
 
315
 *  - hoverStrokeWidth: 0.2,
 
316
 *  - pointRadius: 6,
 
317
 *  - hoverPointRadius: 1,
 
318
 *  - hoverPointUnit: "%",
 
319
 *  - pointerEvents: "visiblePainted"
 
320
 *  - cursor: ""
 
321
 *
 
322
 * Other style properties that have no default values:
 
323
 *
 
324
 *  - externalGraphic,
 
325
 *  - graphicWidth,
 
326
 *  - graphicHeight,
 
327
 *  - graphicOpacity,
 
328
 *  - graphicXOffset,
 
329
 *  - graphicYOffset,
 
330
 *  - graphicName,
 
331
 *  - display
 
332
 */ 
 
333
OpenLayers.Feature.Vector.style = {
 
334
    'default': {
 
335
        fillColor: "#ee9900",
 
336
        fillOpacity: 0.4, 
 
337
        hoverFillColor: "white",
 
338
        hoverFillOpacity: 0.8,
 
339
        strokeColor: "#ee9900",
 
340
        strokeOpacity: 1,
 
341
        strokeWidth: 1,
 
342
        strokeLinecap: "round",
 
343
        strokeDashstyle: "solid",
 
344
        hoverStrokeColor: "red",
 
345
        hoverStrokeOpacity: 1,
 
346
        hoverStrokeWidth: 0.2,
 
347
        pointRadius: 6,
 
348
        hoverPointRadius: 1,
 
349
        hoverPointUnit: "%",
 
350
        pointerEvents: "visiblePainted",
 
351
        cursor: "inherit"
 
352
    },
 
353
    'select': {
 
354
        fillColor: "blue",
 
355
        fillOpacity: 0.4, 
 
356
        hoverFillColor: "white",
 
357
        hoverFillOpacity: 0.8,
 
358
        strokeColor: "blue",
 
359
        strokeOpacity: 1,
 
360
        strokeWidth: 2,
 
361
        strokeLinecap: "round",
 
362
        strokeDashstyle: "solid",
 
363
        hoverStrokeColor: "red",
 
364
        hoverStrokeOpacity: 1,
 
365
        hoverStrokeWidth: 0.2,
 
366
        pointRadius: 6,
 
367
        hoverPointRadius: 1,
 
368
        hoverPointUnit: "%",
 
369
        pointerEvents: "visiblePainted",
 
370
        cursor: "pointer"
 
371
    },
 
372
    'temporary': {
 
373
        fillColor: "yellow",
 
374
        fillOpacity: 0.2, 
 
375
        hoverFillColor: "white",
 
376
        hoverFillOpacity: 0.8,
 
377
        strokeColor: "yellow",
 
378
        strokeOpacity: 1,
 
379
        strokeLinecap: "round",
 
380
        strokeWidth: 4,
 
381
        strokeDashstyle: "solid",
 
382
        hoverStrokeColor: "red",
 
383
        hoverStrokeOpacity: 1,
 
384
        hoverStrokeWidth: 0.2,
 
385
        pointRadius: 6,
 
386
        hoverPointRadius: 1,
 
387
        hoverPointUnit: "%",
 
388
        pointerEvents: "visiblePainted",
 
389
        cursor: "inherit"
 
390
    }
 
391
};