0
“OpenLayers方法没有特别好记录”有人说,这就是为什么我无法理解如何读取gpx中的'ele'数据文件,总结它,并显示获得的高度。OpenLayers:解析GPX文件,读取'ele'标签并计算获得的高度
我有一个带有2个gpx图层的地图,显示了运行轨迹,其中一个div显示了运行和控件的开关长度。下面是一层:
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 <strong>——————
</strong> " + m +" miles" +" (" +kms + "k)";
});
唷在几秒钟的时间,我必须说,我也很讨厌的OpenLayers文档,虽然我爱的框架,我没有GPX文件试试看。我会用萤火虫检查它。根据http://dev.openlayers.org/docs/files/OpenLayers/Format/GPX-js.html(给你一个方向),我会考虑寻找lgpx.geometry.getVertices()并遍历数组。它应该给你从gpx文件的每个点的高度 –
给我一般指针是没有好处的!如果我可以编写代码,我可以从API中派生出代码。我可以看到我应该遍历一个数组,并且大概总结了标签之间的连续差异。但我不能写代码。我一直搜索,直到我脸上发青,我找不到任何例子。 getLength非常简单,但没有相应的方法来获得高度。 –