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. */
6
* @requires OpenLayers/Layer/Vector.js
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.
15
* - <OpenLayers.Layer.Vector>
17
OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, {
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?
28
* Constructor: OpenLayers.PointTrack
29
* Constructor for a new OpenLayers.PointTrack instance.
32
* name - {String} name of the layer
33
* options - {Object} Optional object with properties to tag onto the
36
initialize: function(name, options) {
37
OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments);
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.
47
* pointFeatures - {Array(<OpenLayers.Feature>)}
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" +
58
var lines = new Array(pointFeatures.length-1);
60
var pointFeature, startPoint, endPoint;
61
for(var i=0, len=pointFeatures.length; i<len; i++) {
62
pointFeature = pointFeatures[i];
63
endPoint = pointFeature.geometry;
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.");
75
var attributes = (this.dataFrom != null) ?
76
(pointFeatures[i+this.dataFrom].data ||
77
pointFeatures[i+this.dataFrom].attributes) :
79
var line = new OpenLayers.Geometry.LineString([startPoint,
82
lines[i-1] = new OpenLayers.Feature.Vector(line, attributes);
85
startPoint = endPoint;
88
this.addFeatures(lines);
91
CLASS_NAME: "OpenLayers.Layer.PointTrack"
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
100
OpenLayers.Layer.PointTrack.dataFrom = {'SOURCE_NODE': -1, 'TARGET_NODE': 0};