0

「OpenLayers メソッドは特に十分に文書化されていません」と誰かが言ったので、gpx ファイルの「ele」データを読み取り、合計し、取得した高さを表示する方法を理解できません。

実行トレースを示す 2 つの gpx レイヤーを含むマップがあり、実行の長さを示す div と、レイヤーのオンとオフを切り替えるためのコントロールがあります。ここに1つのレイヤーがあります:

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 に答える