Hide chart link when altitudes not available

This commit is contained in:
Bartek Fabiszewski 2017-05-23 11:32:50 +02:00
parent 090c86a62a
commit 67f407635b
4 changed files with 18 additions and 11 deletions

View File

@ -154,7 +154,7 @@
<div id="summary"></div>
<div id="other">
<a href="javascript:void(0);" onclick="toggleChart();"><?= $lang["chart"] ?></a>
<a id="altitudes" href="javascript:void(0);" onclick="toggleChart();"><?= $lang["chart"] ?></a>
</div>
<div id="api">

View File

@ -65,8 +65,6 @@ function displayTrack(xml, update) {
// update polyline
path.push(p.coordinates);
latlngbounds.extend(p.coordinates);
// save altitudes for chart
altitudes[i] = p.altitude;
}
if (update) {
map.fitBounds(latlngbounds);

View File

@ -104,8 +104,6 @@ function displayTrack(xml, update) {
var point = new OpenLayers.Geometry.Point(p.longitude, p.latitude).transform(wgs84, mercator);
latlngbounds.extend(point);
points.push(point);
// save altitudes for chart
altitudes[i] = p.altitude;
}
var lineString = new OpenLayers.Geometry.LineString(points);
var lineFeature = new OpenLayers.Feature.Vector(lineString, null, lineStyle);

View File

@ -46,10 +46,8 @@ function displayChart() {
data.addColumn('number', 'altitude');
var altLen = altitudes.length;
for (var i = 0; i < altLen; i++) {
if (altitudes[i]!=null){
data.addRow([(i + 1), Math.round((altitudes[i] * factor_m))]);
}
}
var options = {
title: lang['altitude'] + ' (' + unit_m + ')',
@ -74,13 +72,21 @@ function toggleChart(i) {
if (i == 0) {
chart.clearChart();
e.style.display = 'none';
}
else {
} else {
e.style.display = 'block';
displayChart();
}
}
function toggleChartLink() {
var link = document.getElementById('altitudes');
if (altitudes.length > 1) {
link.style.visibility = 'visible';
} else {
link.style.visibility = 'hidden';
}
}
function toggleMenu(i) {
var emenu = document.getElementById('menu');
var emain = document.getElementById('main');
@ -127,6 +133,7 @@ function loadTrack(userid, trackid, update) {
if (positions.length > 0) {
clearMap();
displayTrack(xml, update);
toggleChartLink();
}
}
xhr = null;
@ -143,7 +150,11 @@ function parsePosition(p) {
var latitude = getNode(p, 'latitude');
var longitude = getNode(p, 'longitude');
var altitude = getNode(p, 'altitude'); // may be null
if (altitude != null) { altitude = parseInt(altitude); }
if (altitude != null) {
altitude = parseInt(altitude);
// save altitudes for chart
altitudes.push(altitude);
}
var speed = getNode(p, 'speed'); // may be null
if (speed != null) { speed = parseInt(speed); }
var bearing = getNode(p, 'bearing'); // may be null