diff --git a/js/index.js b/js/index.js index 59fcc22..14432d2 100644 --- a/js/index.js +++ b/js/index.js @@ -46,6 +46,7 @@ search = new BR.Search(); map.addControl(search); + $('#map .leaflet-control-geocoder > button')[0].title = i18next.t('map.geocoder'); router = L.bRouter(); //brouterCgi dummyRouter diff --git a/js/plugin/Search.js b/js/plugin/Search.js index 7e0cabb..4985caa 100644 --- a/js/plugin/Search.js +++ b/js/plugin/Search.js @@ -6,7 +6,10 @@ BR.Search = L.Control.Geocoder.extend({ }), sizeInMeters: 800 }), - position: 'topleft' + position: 'topleft', + shortcut: { + search: 70 // char code for 'f' + } }, initialize: function(options) { @@ -16,6 +19,8 @@ BR.Search = L.Control.Geocoder.extend({ // (e.g. when added directly to "options:" above), so we have to call it here placeholder: i18next.t('map.geocoder-placeholder') }); + + L.DomEvent.addListener(document, 'keydown', this._keydownListener, this); }, markGeocode: function(result) { @@ -38,5 +43,12 @@ BR.Search = L.Control.Geocoder.extend({ if (this._geocodeMarker) { this._map.removeLayer(this._geocodeMarker); } + }, + + _keydownListener: function(e) { + if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.shortcut.search) { + $('#map .leaflet-control-geocoder')[0].dispatchEvent(new MouseEvent('mousedown')); + e.preventDefault(); + } } }); diff --git a/locales/en.json b/locales/en.json index 1399b44..eb9c6ef 100644 --- a/locales/en.json +++ b/locales/en.json @@ -91,6 +91,7 @@ "draw-route-start": "Draw route (D key)", "draw-route-stop": "Stop drawing route (ESC key)", "enter-poi-name": "Enter Point of Interest name", + "geocoder": "Search (F key)", "geocoder-placeholder": "Search…", "hikebike-hillshading": "Hillshading", "hiking": "Hiking",