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

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Layer/PointTrack.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-2007 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
 * @requires OpenLayers/Layer/Vector.js
 
7
 */
 
8
 
 
9
/**
 
10
 * Class: OpenLayers.Layer.PointTrack
 
11
 * Vector layer to display ordered point features as a line, creating one
 
12
 * LineString feature for each pair of two points.
 
13
 *
 
14
 * Inherits from:
 
15
 *  - <OpenLayers.Layer.Vector> 
 
16
 */
 
17
OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, {
 
18
  
 
19
    /**
 
20
     * APIProperty:
 
21
     * dataFrom  - {<OpenLayers.Layer.PointTrack.dataFrom>} optional. If the
 
22
     *             lines should get the data/attributes from one of the two
 
23
     *             points, creating it, which one should it be?
 
24
     */
 
25
    dataFrom: null,
 
26
    
 
27
    /**
 
28
     * Constructor: OpenLayers.PointTrack
 
29
     * Constructor for a new OpenLayers.PointTrack instance.
 
30
     *
 
31
     * Parameters:
 
32
     * name     - {String} name of the layer
 
33
     * options  - {Object} Optional object with properties to tag onto the
 
34
     *            instance.
 
35
     */    
 
36
    initialize: function(name, options) {
 
37
        OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments);
 
38
    },
 
39
        
 
40
    /**
 
41
     * APIMethod: addNodes
 
42
     * Adds point features that will be used to create lines from, using point
 
43
     * pairs. The first point of a pair will be the source node, the second
 
44
     * will be the target node.
 
45
     * 
 
46
     * Parameters:
 
47
     * pointFeatures - {Array(<OpenLayers.Feature>)}
 
48
     * 
 
49
     */
 
50
    addNodes: function(pointFeatures) {
 
51
        if (pointFeatures.length < 2) {
 
52
            OpenLayers.Console.error(
 
53
                    "At least two point features have to be added to create" +
 
54
                    "a line from");
 
55
            return;
 
56
        }
 
57
        
 
58
        var lines = new Array(pointFeatures.length-1);
 
59
        
 
60
        var pointFeature, startPoint, endPoint;
 
61
        for(var i=0, len=pointFeatures.length; i<len; i++) {
 
62
            pointFeature = pointFeatures[i];
 
63
            endPoint = pointFeature.geometry;
 
64
            
 
65
            if (!endPoint) {
 
66
              var lonlat = pointFeature.lonlat;
 
67
              endPoint = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
 
68
            } else if(endPoint.CLASS_NAME != "OpenLayers.Geometry.Point") {
 
69
                OpenLayers.Console.error(
 
70
                        "Only features with point geometries are supported.");
 
71
                return;
 
72
            }
 
73
            
 
74
            if(i > 0) {
 
75
                var attributes = (this.dataFrom != null) ?
 
76
                        (pointFeatures[i+this.dataFrom].data ||
 
77
                                pointFeatures[i+this.dataFrom].attributes) :
 
78
                        null;
 
79
                var line = new OpenLayers.Geometry.LineString([startPoint,
 
80
                        endPoint]);
 
81
                        
 
82
                lines[i-1] = new OpenLayers.Feature.Vector(line, attributes);
 
83
            }
 
84
            
 
85
            startPoint = endPoint;
 
86
        }
 
87
 
 
88
        this.addFeatures(lines);
 
89
    },
 
90
    
 
91
    CLASS_NAME: "OpenLayers.Layer.PointTrack"
 
92
});
 
93
 
 
94
/**
 
95
 * Constant: OpenLayers.Layer.PointTrack.dataFrom
 
96
 * {Object} with the following keys
 
97
 * - SOURCE_NODE: take data/attributes from the source node of the line
 
98
 * - TARGET_NODE: take data/attributes from the target node of the line
 
99
 */
 
100
OpenLayers.Layer.PointTrack.dataFrom = {'SOURCE_NODE': -1, 'TARGET_NODE': 0};
 
101