“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)";
});
答案 0 :(得分: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)}