Add shortcut for geocoder search field
Press 'F', type a query and press 'Enter' to find places effortlessly. Note that the button already triggers on mousedown events, even though by convention it should react on mouseup (i.e. a regular click) only. However, that's an issue in the external dependency, and can be worked around for now.
This commit is contained in:
parent
f23e3751b5
commit
37ab05310b
3 changed files with 15 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue