From ba0bb39fd5075ee28f575d7063251bcb5de8d258 Mon Sep 17 00:00:00 2001 From: Henrik Fehlauer Date: Mon, 8 Jun 2020 18:00:00 +0000 Subject: [PATCH] Add shortcut to toggle Strava layer Press 'S' to show the Strava buttons (if the API key has been set) as well as the Strava segments layer (once it has been fetched). Note that fetching and updating data from Strava still needs to be triggered manually by clicking the respective biking or running button. --- js/plugin/stravaSegments.js | 21 +++++++++++++++++++++ locales/en.json | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/js/plugin/stravaSegments.js b/js/plugin/stravaSegments.js index 91d3534..a4de7ec 100644 --- a/js/plugin/stravaSegments.js +++ b/js/plugin/stravaSegments.js @@ -16,6 +16,12 @@ BR.stravaSegments = function(map, layersControl) { ); }; + L.setOptions(this, { + shortcut: { + toggleLayer: 83 // char code for 's' + } + }); + // hide strava buttons when layer is inactive var toggleStravaControl = function() { var stravaBar = stravaControl.runningButton.button.parentElement; @@ -24,5 +30,20 @@ BR.stravaSegments = function(map, layersControl) { toggleStravaControl(); stravaControl.stravaLayer.on('add remove', toggleStravaControl); + L.DomEvent.addListener( + document, + 'keydown', + function(e) { + if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.shortcut.toggleLayer) { + if (map.hasLayer(stravaControl.stravaLayer)) { + map.removeLayer(stravaControl.stravaLayer); + } else { + map.addLayer(stravaControl.stravaLayer); + } + } + }, + this + ); + return stravaControl; }; diff --git a/locales/en.json b/locales/en.json index cd27425..6766c76 100644 --- a/locales/en.json +++ b/locales/en.json @@ -128,8 +128,8 @@ "route-quality-altitude": "Altitude coding (C key to toggle)", "route-quality-cost": "Cost coding (C key to toggle)", "route-quality-incline": "Incline coding (C key to toggle)", - "strava-biking": "Show Strava biking segments", - "strava-running": "Show Strava running segments", + "strava-biking": "Show Strava biking segments\n(S key to toggle layer, click to reload for current area)", + "strava-running": "Show Strava running segments\n(S key to toggle layer, click to reload for current area)", "zoomInTitle": "Zoom in (+ key)", "zoomOutTitle": "Zoom out (- key)" },