From 67f407635bdff624cb48cf76c95f46242206e4f8 Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Tue, 23 May 2017 11:32:50 +0200 Subject: [PATCH] Hide chart link when altitudes not available --- index.php | 2 +- js/api_gmaps.js | 2 -- js/api_openlayers.js | 2 -- js/main.js | 23 +++++++++++++++++------ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index 12b7270..64037b0 100755 --- a/index.php +++ b/index.php @@ -154,7 +154,7 @@
- +
diff --git a/js/api_gmaps.js b/js/api_gmaps.js index 2093bdc..a8086d0 100755 --- a/js/api_gmaps.js +++ b/js/api_gmaps.js @@ -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); diff --git a/js/api_openlayers.js b/js/api_openlayers.js index 0f1535c..35f1d99 100755 --- a/js/api_openlayers.js +++ b/js/api_openlayers.js @@ -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); diff --git a/js/main.js b/js/main.js index 648e3a4..54bee9e 100755 --- a/js/main.js +++ b/js/main.js @@ -46,9 +46,7 @@ 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))]); - } + data.addRow([(i + 1), Math.round((altitudes[i] * factor_m))]); } var options = { @@ -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