Add shortcut to toggle color coding button

Press 'C' repeatedly to switch between the various color coding options.
When the last one is reached, we show the regular route again.
This commit is contained in:
Henrik Fehlauer 2020-05-30 18:00:00 +00:00
parent d6c648d3eb
commit 8e78c858c1
2 changed files with 12 additions and 5 deletions

View file

@ -1,6 +1,7 @@
BR.RoutingPathQuality = L.Control.extend({ BR.RoutingPathQuality = L.Control.extend({
options: { options: {
shortcut: { shortcut: {
toggle: 67, // char code for 'c'
muteKeyCode: 77 // char code for 'm' muteKeyCode: 77 // char code for 'm'
} }
}, },
@ -140,7 +141,7 @@ BR.RoutingPathQuality = L.Control.extend({
}); });
} }
if (this.options.shortcut.muteKeyCode) { if (this.options.shortcut.muteKeyCode || this.options.shortcut.toggle) {
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this); L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
L.DomEvent.addListener(document, 'keyup', this._keyupListener, this); L.DomEvent.addListener(document, 'keyup', this._keyupListener, this);
} }
@ -192,10 +193,16 @@ BR.RoutingPathQuality = L.Control.extend({
}, },
_keydownListener: function(e) { _keydownListener: function(e) {
if (BR.Util.keyboardShortcutsAllowed(e) && this._active && e.keyCode === this.options.shortcut.muteKeyCode) { if (!BR.Util.keyboardShortcutsAllowed(e)) {
return;
}
if (this._active && e.keyCode === this.options.shortcut.muteKeyCode) {
this._muted = true; this._muted = true;
this._deactivate(this.routingPathButton); this._deactivate(this.routingPathButton);
} }
if (!this._muted && e.keyCode === this.options.shortcut.toggle) {
this.routingPathButton.button.click();
}
}, },
_keyupListener: function(e) { _keyupListener: function(e) {

View file

@ -122,9 +122,9 @@
"preview": "Preview", "preview": "Preview",
"privacy": "Privacy", "privacy": "Privacy",
"reverse-route": "Reverse route", "reverse-route": "Reverse route",
"route-quality-altitude": "Altitude coding", "route-quality-altitude": "Altitude coding (C key to toggle)",
"route-quality-cost": "Cost coding", "route-quality-cost": "Cost coding (C key to toggle)",
"route-quality-incline": "Incline coding", "route-quality-incline": "Incline coding (C key to toggle)",
"strava-biking": "Show Strava biking segments", "strava-biking": "Show Strava biking segments",
"strava-running": "Show Strava running segments", "strava-running": "Show Strava running segments",
"zoomInTitle": "Zoom in (+ key)", "zoomInTitle": "Zoom in (+ key)",