From 2a00e3c351f68e048585b24ea2ccee0b4b306cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Wed, 18 Mar 2020 22:11:40 +0100 Subject: [PATCH] GeoInfo: show heading --- lang/en.json | 8 ++++++++ src/GeoInfo.js | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/lang/en.json b/lang/en.json index aa2a7dca..d39e9f5a 100644 --- a/lang/en.json +++ b/lang/en.json @@ -45,6 +45,14 @@ "header:attributes": "Attributes", "header:export": "Export", "header:osm_meta": "OSM Meta", + "heading:N": "N", + "heading:NE": "NE", + "heading:E": "E", + "heading:SE": "SE", + "heading:S": "S", + "heading:SW": "SW", + "heading:W": "W", + "heading:NW": "NW", "images": "Images", "invalid value": "invalid value", "loading": "Loading ...", diff --git a/src/GeoInfo.js b/src/GeoInfo.js index aaf46c05..9191431f 100644 --- a/src/GeoInfo.js +++ b/src/GeoInfo.js @@ -7,6 +7,10 @@ const tabs = require('modulekit-tabs') const formatUnits = require('./formatUnits') require('./GeoInfo.css') +function heading (value) { + return [ 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N' ][Math.round(value / 45)] +} + register_hook('init', function () { let tab = new tabs.Tab({ id: 'search', @@ -105,6 +109,7 @@ register_hook('init', function () { (typeof e.accuracy !== 'undefined' ? (global.options.formatUnitsCoordSpacer || ', ') + '± ' + formatUnits.distance(e.accuracy.toFixed(0)) : '') + '
' + (typeof e.altitude !== 'undefined' ? ' ' + formatUnits.height(e.altitude) + (typeof e.altitudeAccuracy !== 'undefined' ? ' ± ' + formatUnits.distance(e.altitudeAccuracy) : '') + ' ' : '') + (typeof e.speed !== 'undefined' ? ' ' + formatUnits.speed(e.speed) + ' ' : '') + + (typeof e.heading !== 'undefined' ? ' ' + lang('heading:' + heading(e.heading)) + ' (' + e.heading.toFixed(0) + '°)' : '') + '' domLocation.classList.remove('empty') }