From d7d41f85910af79ab8a9a8e6fed235e32de3c8e5 Mon Sep 17 00:00:00 2001 From: Sebastiaan Andeweg Date: Tue, 11 Jul 2017 00:57:25 +0200 Subject: [PATCH] display speed in metric or imperial --- compass/public/assets/speed.js | 14 ++++++++++++-- compass/resources/views/map.blade.php | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compass/public/assets/speed.js b/compass/public/assets/speed.js index 1d80b50..4039af4 100644 --- a/compass/public/assets/speed.js +++ b/compass/public/assets/speed.js @@ -2,6 +2,16 @@ function speedSeries(response) { var data = response.linestring; + var system = { + label: 'mph', + multiplier: 2.23694 + }; + + if(document.getElementById('is-metric').value == true) { + system.label = 'km/h'; + system.multiplier = 3.6; + } + var series = { name: "Speed", yAxis: 1, @@ -9,7 +19,7 @@ function speedSeries(response) { animation: true, pointFormatter: function(){ moveMarkerToPosition(this); - return ''+this.y+'mph'; + return ''+this.y+system.label+''; } }, lineWidth: 1, @@ -27,7 +37,7 @@ function speedSeries(response) { series.data = data.properties.map(function(d,i){ return { x: new Date(d.unixtime*1000), - y: ('speed' in d && d.speed >= 0 ? Math.round(d.speed * 2.23694) : null), + y: ('speed' in d && d.speed >= 0 ? Math.round(d.speed * system.multiplier) : null), location: data.coordinates[i] } }); diff --git a/compass/resources/views/map.blade.php b/compass/resources/views/map.blade.php index 2eadcba..cb4855f 100644 --- a/compass/resources/views/map.blade.php +++ b/compass/resources/views/map.blade.php @@ -57,6 +57,7 @@
+