parse waypoints last, so that they're on top. patch by Edgemaster, r=elemoine,

(Closes #1763) 


git-svn-id: http://svn.openlayers.org/trunk/openlayers@8531 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-12-21 14:43:58 +00:00
parent 34959835fb
commit e2319ffa12
2 changed files with 17 additions and 17 deletions

View File

@@ -72,18 +72,6 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, {
}
var features = [];
if(this.extractWaypoints) {
var waypoints = doc.getElementsByTagName("wpt");
for (var l = 0, len = waypoints.length; l < len; l++) {
var attrs = {};
if(this.extractAttributes) {
attrs = this.parseAttributes(waypoints[l]);
}
var wpt = new OpenLayers.Geometry.Point(waypoints[l].getAttribute("lon"), waypoints[l].getAttribute("lat"));
features.push(new OpenLayers.Feature.Vector(wpt, attrs));
}
}
if(this.extractTracks) {
var tracks = doc.getElementsByTagName("trk");
for (var i=0, len=tracks.length; i<len; i++) {
@@ -115,6 +103,18 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, {
}
}
if(this.extractWaypoints) {
var waypoints = doc.getElementsByTagName("wpt");
for (var l = 0, len = waypoints.length; l < len; l++) {
var attrs = {};
if(this.extractAttributes) {
attrs = this.parseAttributes(waypoints[l]);
}
var wpt = new OpenLayers.Geometry.Point(waypoints[l].getAttribute("lon"), waypoints[l].getAttribute("lat"));
features.push(new OpenLayers.Feature.Vector(wpt, attrs));
}
}
if (this.internalProjection && this.externalProjection) {
for (var g = 0, featLength = features.length; g < featLength; g++) {
features[g].geometry.transform(this.externalProjection,

View File

@@ -21,16 +21,16 @@
var f = new OpenLayers.Format.GPX();
var features = f.read(gpx_data);
t.eq(features.length, 3, "Number of features read is correct");
t.eq(features[0].geometry.toString(), "POINT(-0.1853562259 51.3697845627)", "waypoint feature correctly created");
t.eq(features[1].geometry.toString(), "LINESTRING(-0.1721292044 51.3768216433,-0.1649230916 51.370833767,-0.1736741378 51.3644368725,-0.166259525 51.3576354272)", "track feature correctly created");
t.eq(features[2].geometry.toString(), "LINESTRING(-0.1829991904 51.3761803674,-0.1758887005 51.3697894659,-0.1833202965 51.3639790884,-0.1751119509 51.3567607069)", "route feature correctly created");
t.eq(features[2].geometry.toString(), "POINT(-0.1853562259 51.3697845627)", "waypoint feature correctly created");
t.eq(features[0].geometry.toString(), "LINESTRING(-0.1721292044 51.3768216433,-0.1649230916 51.370833767,-0.1736741378 51.3644368725,-0.166259525 51.3576354272)", "track feature correctly created");
t.eq(features[1].geometry.toString(), "LINESTRING(-0.1829991904 51.3761803674,-0.1758887005 51.3697894659,-0.1833202965 51.3639790884,-0.1751119509 51.3567607069)", "route feature correctly created");
}
function test_format_GPX_read_attributes(t) {
t.plan(2);
var f = new OpenLayers.Format.GPX();
var features = f.read(gpx_data);
t.eq(features[0].attributes['name'], "Mark", "Text attribute node read correctly.");
t.eq(features[0].attributes['sym'], "Flag", "CDATA attribute node read correctly.");
t.eq(features[2].attributes['name'], "Mark", "Text attribute node read correctly.");
t.eq(features[2].attributes['sym'], "Flag", "CDATA attribute node read correctly.");
}
</script>
</head>