From fd97019fdc0e75843c3eb9da2d4238b7c87eeb4d Mon Sep 17 00:00:00 2001 From: Henrik Fehlauer Date: Sun, 31 May 2020 18:00:00 +0000 Subject: [PATCH] Add shortcut to trigger geolocation Press 'L' to initiate the "Show me where I am" function. --- js/Map.js | 18 +++++++++++++++++- locales/en.json | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/js/Map.js b/js/Map.js index 7defdc1..2e26771 100644 --- a/js/Map.js +++ b/js/Map.js @@ -2,6 +2,12 @@ BR.Map = { initMap: function() { var map, layersControl; + L.setOptions(this, { + shortcut: { + locate: 76 // char code for 'l' + } + }); + BR.keys = BR.keys || {}; var maxZoom = 19; @@ -96,7 +102,7 @@ BR.Map = { var secureContext = 'isSecureContext' in window ? isSecureContext : location.protocol === 'https:'; if (secureContext) { - L.control + var locationControl = L.control .locate({ strings: { title: i18next.t('map.locate-me') @@ -105,6 +111,16 @@ BR.Map = { iconLoading: 'fa fa-spinner fa-pulse' }) .addTo(map); + L.DomEvent.addListener( + document, + 'keydown', + function(e) { + if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.shortcut.locate) { + locationControl.start(); + } + }, + this + ); } L.control.scale().addTo(map); diff --git a/locales/en.json b/locales/en.json index e5b1a67..7208818 100644 --- a/locales/en.json +++ b/locales/en.json @@ -110,7 +110,7 @@ "topo": "OpenTopoMap" }, "loading": "Loading…", - "locate-me": "Show me where I am", + "locate-me": "Show me where I am (L key)", "nogo": { "cancel": "Cancel drawing no-go area", "click-drag": "Click and drag to draw circle",