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.
This commit is contained in:
Henrik Fehlauer 2020-06-08 18:00:00 +00:00
parent e4e1c8a19e
commit ba0bb39fd5
2 changed files with 23 additions and 2 deletions

View file

@ -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;
};