Add shortcut to trigger geolocation
Press 'L' to initiate the "Show me where I am" function.
This commit is contained in:
parent
8e78c858c1
commit
fd97019fdc
2 changed files with 18 additions and 2 deletions
18
js/Map.js
18
js/Map.js
|
|
@ -2,6 +2,12 @@ BR.Map = {
|
||||||
initMap: function() {
|
initMap: function() {
|
||||||
var map, layersControl;
|
var map, layersControl;
|
||||||
|
|
||||||
|
L.setOptions(this, {
|
||||||
|
shortcut: {
|
||||||
|
locate: 76 // char code for 'l'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
BR.keys = BR.keys || {};
|
BR.keys = BR.keys || {};
|
||||||
|
|
||||||
var maxZoom = 19;
|
var maxZoom = 19;
|
||||||
|
|
@ -96,7 +102,7 @@ BR.Map = {
|
||||||
|
|
||||||
var secureContext = 'isSecureContext' in window ? isSecureContext : location.protocol === 'https:';
|
var secureContext = 'isSecureContext' in window ? isSecureContext : location.protocol === 'https:';
|
||||||
if (secureContext) {
|
if (secureContext) {
|
||||||
L.control
|
var locationControl = L.control
|
||||||
.locate({
|
.locate({
|
||||||
strings: {
|
strings: {
|
||||||
title: i18next.t('map.locate-me')
|
title: i18next.t('map.locate-me')
|
||||||
|
|
@ -105,6 +111,16 @@ BR.Map = {
|
||||||
iconLoading: 'fa fa-spinner fa-pulse'
|
iconLoading: 'fa fa-spinner fa-pulse'
|
||||||
})
|
})
|
||||||
.addTo(map);
|
.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);
|
L.control.scale().addTo(map);
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
"topo": "OpenTopoMap"
|
"topo": "OpenTopoMap"
|
||||||
},
|
},
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
"locate-me": "Show me where I am",
|
"locate-me": "Show me where I am (L key)",
|
||||||
"nogo": {
|
"nogo": {
|
||||||
"cancel": "Cancel drawing no-go area",
|
"cancel": "Cancel drawing no-go area",
|
||||||
"click-drag": "Click and drag to draw circle",
|
"click-drag": "Click and drag to draw circle",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue