Fix mapping between altitudes and positions
This commit is contained in:
parent
678a2267c2
commit
8f50ac80ef
@ -43,7 +43,7 @@ function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function displayTrack(xml, update) {
|
function displayTrack(xml, update) {
|
||||||
altitudes.length = 0;
|
altitudes = {};
|
||||||
var totalMeters = 0;
|
var totalMeters = 0;
|
||||||
var totalSeconds = 0;
|
var totalSeconds = 0;
|
||||||
// init polyline
|
// init polyline
|
||||||
@ -54,7 +54,7 @@ function displayTrack(xml, update) {
|
|||||||
var positions = xml.getElementsByTagName('position');
|
var positions = xml.getElementsByTagName('position');
|
||||||
var posLen = positions.length;
|
var posLen = positions.length;
|
||||||
for (var i = 0; i < posLen; i++) {
|
for (var i = 0; i < posLen; i++) {
|
||||||
var p = parsePosition(positions[i]);
|
var p = parsePosition(positions[i], i);
|
||||||
totalMeters += p.distance;
|
totalMeters += p.distance;
|
||||||
totalSeconds += p.seconds;
|
totalSeconds += p.seconds;
|
||||||
p['totalMeters'] = totalMeters;
|
p['totalMeters'] = totalMeters;
|
||||||
@ -131,7 +131,14 @@ function setMarker(p, i, posLen) {
|
|||||||
popup.setContent(content);
|
popup.setContent(content);
|
||||||
popup.open(map, marker);
|
popup.open(map, marker);
|
||||||
if (document.getElementById('bottom').style.display == 'block') {
|
if (document.getElementById('bottom').style.display == 'block') {
|
||||||
chart.setSelection([{ row: i, column: null }]);
|
var index = 0;
|
||||||
|
for (var key in altitudes) {
|
||||||
|
if (altitudes.hasOwnProperty(key) && key == i) {
|
||||||
|
chart.setSelection([{ row: index, column: null }]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})(marker, content));
|
})(marker, content));
|
||||||
@ -139,12 +146,12 @@ function setMarker(p, i, posLen) {
|
|||||||
popups.push(popup);
|
popups.push(popup);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addChartEvent(chart) {
|
function addChartEvent(chart, data) {
|
||||||
google.visualization.events.addListener(chart, 'select', function () {
|
google.visualization.events.addListener(chart, 'select', function () {
|
||||||
if (popup) { popup.close(); clearTimeout(altTimeout); }
|
if (popup) { popup.close(); clearTimeout(altTimeout); }
|
||||||
var selection = chart.getSelection()[0];
|
var selection = chart.getSelection()[0];
|
||||||
if (selection) {
|
if (selection) {
|
||||||
var id = selection.row;
|
var id = data.getValue(selection.row, 0) - 1;
|
||||||
var icon = markers[id].getIcon();
|
var icon = markers[id].getIcon();
|
||||||
markers[id].setIcon('//maps.google.com/mapfiles/marker_orange.png');
|
markers[id].setIcon('//maps.google.com/mapfiles/marker_orange.png');
|
||||||
altTimeout = setTimeout(function () { markers[id].setIcon(icon); }, 2000);
|
altTimeout = setTimeout(function () { markers[id].setIcon(icon); }, 2000);
|
||||||
|
@ -85,7 +85,7 @@ function init() {
|
|||||||
layerMarkers = new OpenLayers.Layer.Markers('Markers');
|
layerMarkers = new OpenLayers.Layer.Markers('Markers');
|
||||||
}
|
}
|
||||||
function displayTrack(xml, update) {
|
function displayTrack(xml, update) {
|
||||||
altitudes.length = 0;
|
altitudes = {};
|
||||||
var totalMeters = 0;
|
var totalMeters = 0;
|
||||||
var totalSeconds = 0;
|
var totalSeconds = 0;
|
||||||
var points = new Array();
|
var points = new Array();
|
||||||
@ -93,7 +93,7 @@ function displayTrack(xml, update) {
|
|||||||
var positions = xml.getElementsByTagName('position');
|
var positions = xml.getElementsByTagName('position');
|
||||||
var posLen = positions.length;
|
var posLen = positions.length;
|
||||||
for (var i = 0; i < posLen; i++) {
|
for (var i = 0; i < posLen; i++) {
|
||||||
var p = parsePosition(positions[i]);
|
var p = parsePosition(positions[i], i);
|
||||||
totalMeters += p.distance;
|
totalMeters += p.distance;
|
||||||
totalSeconds += p.seconds;
|
totalSeconds += p.seconds;
|
||||||
p['totalMeters'] = totalMeters;
|
p['totalMeters'] = totalMeters;
|
||||||
@ -169,17 +169,24 @@ function setMarker(p, i, posLen) {
|
|||||||
var popup = new OpenLayers.Popup.FramedCloud("popup_" + (i + 1), lonLat, null, content, icon, true);
|
var popup = new OpenLayers.Popup.FramedCloud("popup_" + (i + 1), lonLat, null, content, icon, true);
|
||||||
map.addPopup(popup);
|
map.addPopup(popup);
|
||||||
if (document.getElementById('bottom').style.display == 'block') {
|
if (document.getElementById('bottom').style.display == 'block') {
|
||||||
chart.setSelection([{ row: i, column: null }]);
|
var index = 0;
|
||||||
|
for (var key in altitudes) {
|
||||||
|
if (altitudes.hasOwnProperty(key) && key == i) {
|
||||||
|
chart.setSelection([{ row: index, column: null }]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})());
|
})());
|
||||||
}
|
}
|
||||||
|
|
||||||
function addChartEvent(chart) {
|
function addChartEvent(chart, data) {
|
||||||
google.visualization.events.addListener(chart, 'select', function () {
|
google.visualization.events.addListener(chart, 'select', function () {
|
||||||
var selection = chart.getSelection()[0];
|
var selection = chart.getSelection()[0];
|
||||||
if (selection) {
|
if (selection) {
|
||||||
var id = selection.row;
|
var id = data.getValue(selection.row, 0) - 1;
|
||||||
var marker = layerMarkers.markers[id];
|
var marker = layerMarkers.markers[id];
|
||||||
var url = marker.icon.url;
|
var url = marker.icon.url;
|
||||||
marker.setUrl('//www.openstreetmap.org/openlayers/img/marker-gold.png');
|
marker.setUrl('//www.openstreetmap.org/openlayers/img/marker-gold.png');
|
||||||
|
20
js/main.js
20
js/main.js
@ -35,7 +35,7 @@ if (units == 'imperial') {
|
|||||||
var latest = 0;
|
var latest = 0;
|
||||||
var live = 0;
|
var live = 0;
|
||||||
var chart;
|
var chart;
|
||||||
var altitudes = new Array();
|
var altitudes = {};
|
||||||
var altTimeout;
|
var altTimeout;
|
||||||
var gm_error = false;
|
var gm_error = false;
|
||||||
|
|
||||||
@ -43,10 +43,12 @@ function displayChart() {
|
|||||||
if (chart) { google.visualization.events.removeAllListeners(chart); }
|
if (chart) { google.visualization.events.removeAllListeners(chart); }
|
||||||
var data = new google.visualization.DataTable();
|
var data = new google.visualization.DataTable();
|
||||||
data.addColumn('number', 'id');
|
data.addColumn('number', 'id');
|
||||||
data.addColumn('number', 'altitude');
|
data.addColumn('number', lang['altitude']);
|
||||||
var altLen = altitudes.length;
|
|
||||||
for (var i = 0; i < altLen; i++) {
|
for (var id in altitudes) {
|
||||||
data.addRow([(i + 1), Math.round((altitudes[i] * factor_m))]);
|
if (altitudes.hasOwnProperty(id)) {
|
||||||
|
data.addRow([parseInt(id) + 1, Math.round((altitudes[id] * factor_m))]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
@ -58,7 +60,7 @@ function displayChart() {
|
|||||||
chart = new google.visualization.LineChart(document.getElementById('chart'));
|
chart = new google.visualization.LineChart(document.getElementById('chart'));
|
||||||
chart.draw(data, options);
|
chart.draw(data, options);
|
||||||
|
|
||||||
addChartEvent(chart);
|
addChartEvent(chart, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleChart(i) {
|
function toggleChart(i) {
|
||||||
@ -80,7 +82,7 @@ function toggleChart(i) {
|
|||||||
|
|
||||||
function toggleChartLink() {
|
function toggleChartLink() {
|
||||||
var link = document.getElementById('altitudes');
|
var link = document.getElementById('altitudes');
|
||||||
if (altitudes.length > 1) {
|
if (Object.keys(altitudes).length > 1) {
|
||||||
link.style.visibility = 'visible';
|
link.style.visibility = 'visible';
|
||||||
} else {
|
} else {
|
||||||
link.style.visibility = 'hidden';
|
link.style.visibility = 'hidden';
|
||||||
@ -145,7 +147,7 @@ function loadTrack(userid, trackid, update) {
|
|||||||
setLoader(title);
|
setLoader(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parsePosition(p) {
|
function parsePosition(p, id) {
|
||||||
// read data
|
// read data
|
||||||
var latitude = getNode(p, 'latitude');
|
var latitude = getNode(p, 'latitude');
|
||||||
var longitude = getNode(p, 'longitude');
|
var longitude = getNode(p, 'longitude');
|
||||||
@ -153,7 +155,7 @@ function parsePosition(p) {
|
|||||||
if (altitude != null) {
|
if (altitude != null) {
|
||||||
altitude = parseInt(altitude);
|
altitude = parseInt(altitude);
|
||||||
// save altitudes for chart
|
// save altitudes for chart
|
||||||
altitudes.push(altitude);
|
altitudes[id] = altitude;
|
||||||
}
|
}
|
||||||
var speed = getNode(p, 'speed'); // may be null
|
var speed = getNode(p, 'speed'); // may be null
|
||||||
if (speed != null) { speed = parseInt(speed); }
|
if (speed != null) { speed = parseInt(speed); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user