0

"The OpenLayers method is not especially well documented" someone said, which is why I can't fathom how to read the 'ele' data in a gpx file, sum it, and display the height gained.

I have a map with 2 gpx layers showing run traces, with a div showing the length of runs and controls to switch layers on and off. Here is one layer:

var lgpx = new OpenLayers.Layer.Vector("wed training fast", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
   url: "../gpx/27-Mar-13fast.gpx",
   format: new OpenLayers.Format.GPX({
   extractWaypoints: true, extractRoutes: true,
    extractAttributes: true})
}),
styleMap: gpxStyles,
projection: new OpenLayers.Projection("EPSG:4326")
});

map.addLayer(lgpx); //fast
bounds = new OpenLayers.Bounds();

// fit fast layer to bounds of window and add start, finish pins
lgpx.events.register("loadend", lgpx, function() {
//add extent of layer to bounds
    bounds = this.getDataExtent();
//add startpoint marker
    var startPoint = this.features[0].geometry.components[0];               
    layerMarkers.addMarker(new OpenLayers.Marker
        (new OpenLayers.LonLat(startPoint.x, startPoint.y),iconfast));
//add endpoint marker           
    var endPoint=this.features[0].geometry.components
        [this.features[0].geometry.components.length-1];
    layerMarkers.addMarker(new OpenLayers.Marker
        (new OpenLayers.LonLat(endPoint.x, endPoint.y),iconfast2));
//calculate length of trace
    var len = this.features[0].geometry.getGeodesicLength
        (new OpenLayers.Projection("EPSG:900913"))/1000 + " k";
    (Math.round(value*100)/100).toFixed(2);
    var kms = +(parseFloat(len).toFixed(2));
    var m = +(parseFloat(kms*0.621371).toFixed(2));
//write the result to the page      
    document.getElementById("fastbox").innerHTML=
   "Fast run &nbsp;&nbsp;&nbsp;<strong>&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
       </strong>&nbsp;&nbsp;" + m +" miles"  +"&nbsp;&nbsp;(" +kms + "k)";
});
4

1 回答 1

0

我无法判断 OpenLayers 2。但对于 OpenLayers 3,您可以拥有 3 或 4 维坐标,其中包括时间测量。你可以用这个检查:

> feature.getGeometry().getLayout()
"XYZM"

如果是这种情况,只需检查“M”。

> feature.getGeometry().getCoordinates()[3]
991452420

这是自 1970 年以来的秒数。

> d=new Date(); d.setTime(991452420*1000); d
Date {Sat Jun 02 2001 05:27:00 GMT+0200 (CEST)}
于 2014-11-15T14:06:25.777 回答