From d6c648d3ebe9f7f1dcc4aa7488736399ab5082c9 Mon Sep 17 00:00:00 2001 From: Henrik Fehlauer Date: Fri, 29 May 2020 18:00:00 +0000 Subject: [PATCH] Fix mute shortcut not working for color coded routes The mute shortcut would only work for regular routes before. Note that no-go areas, POIs and tracks continue to be unaffected by muting, so e.g. peeking at a track below the route is still possible. --- js/plugin/RoutingPathQuality.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/js/plugin/RoutingPathQuality.js b/js/plugin/RoutingPathQuality.js index 64b4872..1ed5e11 100644 --- a/js/plugin/RoutingPathQuality.js +++ b/js/plugin/RoutingPathQuality.js @@ -1,4 +1,10 @@ BR.RoutingPathQuality = L.Control.extend({ + options: { + shortcut: { + muteKeyCode: 77 // char code for 'm' + } + }, + initialize: function(map, layersControl, options) { L.setOptions(this, options); @@ -78,6 +84,7 @@ BR.RoutingPathQuality = L.Control.extend({ this.selectedProvider = this._initialProvider; this._active = false; + this._muted = false; }, onAdd: function(map) { @@ -133,6 +140,11 @@ BR.RoutingPathQuality = L.Control.extend({ }); } + if (this.options.shortcut.muteKeyCode) { + L.DomEvent.addListener(document, 'keydown', this._keydownListener, this); + L.DomEvent.addListener(document, 'keyup', this._keyupListener, this); + } + this.routingPathButton = new L.easyButton({ states: states }).addTo(map); @@ -177,6 +189,20 @@ BR.RoutingPathQuality = L.Control.extend({ this._routingSegments.addLayer(layers[i]); } } + }, + + _keydownListener: function(e) { + if (BR.Util.keyboardShortcutsAllowed(e) && this._active && e.keyCode === this.options.shortcut.muteKeyCode) { + this._muted = true; + this._deactivate(this.routingPathButton); + } + }, + + _keyupListener: function(e) { + if (BR.Util.keyboardShortcutsAllowed(e) && this._muted && e.keyCode === this.options.shortcut.muteKeyCode) { + this._muted = false; + this._activate(this.routingPathButton); + } } });