Making Layer.PointTrack play nicely with gx:Track from Format.KML. Thanks bartvde for the updated patch. r=fredj,bartvde (closes #2792)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11721 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-03-22 13:45:58 +00:00
parent 991a7314c3
commit 2d29236fb0

View File

@@ -20,12 +20,22 @@ OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, {
/**
* APIProperty:
* dataFrom - {<OpenLayers.Layer.PointTrack.dataFrom>} optional. If the
* lines should get the data/attributes from one of the two
* points, creating it, which one should it be?
* dataFrom - {<OpenLayers.Layer.PointTrack.TARGET_NODE>} or
* {<OpenLayers.Layer.PointTrack.SOURCE_NODE>} optional. If the lines
* should get the data/attributes from one of the two points it is
* composed of, which one should it be?
*/
dataFrom: null,
/**
* APIProperty:
* styleFrom - {<OpenLayers.Layer.PointTrack.TARGET_NODE>} or
* {<OpenLayers.Layer.PointTrack.SOURCE_NODE>} optional. If the lines
* should get the style from one of the two points it is composed of,
* which one should it be?
*/
styleFrom: null,
/**
* Constructor: OpenLayers.PointTrack
* Constructor for a new OpenLayers.PointTrack instance.
@@ -47,9 +57,12 @@ OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, {
*
* Parameters:
* pointFeatures - {Array(<OpenLayers.Feature>)}
* options - {Object}
*
* Supported options:
* silent - {Boolean} true to suppress (before)feature(s)added events
*/
addNodes: function(pointFeatures) {
addNodes: function(pointFeatures, options) {
if (pointFeatures.length < 2) {
OpenLayers.Console.error(
"At least two point features have to be added to create" +
@@ -78,26 +91,43 @@ OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, {
(pointFeatures[i+this.dataFrom].data ||
pointFeatures[i+this.dataFrom].attributes) :
null;
var style = (this.styleFrom != null) ?
(pointFeatures[i+this.styleFrom].style) :
null;
var line = new OpenLayers.Geometry.LineString([startPoint,
endPoint]);
lines[i-1] = new OpenLayers.Feature.Vector(line, attributes);
lines[i-1] = new OpenLayers.Feature.Vector(line, attributes,
style);
}
startPoint = endPoint;
}
this.addFeatures(lines);
this.addFeatures(lines, options);
},
CLASS_NAME: "OpenLayers.Layer.PointTrack"
});
/**
* Constant: OpenLayers.Layer.PointTrack.SOURCE_NODE
* {Number} value for <OpenLayers.Layer.PointTrack.dataFrom> and
* <OpenLayers.Layer.PointTrack.styleFrom>
*/
OpenLayers.Layer.PointTrack.SOURCE_NODE = -1;
/**
* Constant: OpenLayers.Layer.PointTrack.TARGET_NODE
* {Number} value for <OpenLayers.Layer.PointTrack.dataFrom> and
* <OpenLayers.Layer.PointTrack.styleFrom>
*/
OpenLayers.Layer.PointTrack.TARGET_NODE = 0;
/**
* Constant: OpenLayers.Layer.PointTrack.dataFrom
* {Object} with the following keys
* {Object} with the following keys - *deprecated*
* - SOURCE_NODE: take data/attributes from the source node of the line
* - TARGET_NODE: take data/attributes from the target node of the line
*/
OpenLayers.Layer.PointTrack.dataFrom = {'SOURCE_NODE': -1, 'TARGET_NODE': 0};