Add shortcut to create no-go areas
Press 'N' to initiate drawing a no-go area. 'Escape' will cancel, similar to how drawing a route works.
This commit is contained in:
parent
2848e4dd36
commit
a852acbfce
2 changed files with 42 additions and 13 deletions
|
|
@ -1,4 +1,13 @@
|
||||||
BR.NogoAreas = L.Control.extend({
|
BR.NogoAreas = L.Control.extend({
|
||||||
|
options: {
|
||||||
|
shortcut: {
|
||||||
|
draw: {
|
||||||
|
enable: 78, // char code for 'n'
|
||||||
|
disable: 27 // char code for 'ESC'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
MSG_BUTTON: 'Draw no-go area (circle)',
|
MSG_BUTTON: 'Draw no-go area (circle)',
|
||||||
MSG_BUTTON_CANCEL: 'Cancel drawing no-go area',
|
MSG_BUTTON_CANCEL: 'Cancel drawing no-go area',
|
||||||
|
|
@ -48,28 +57,32 @@ BR.NogoAreas = L.Control.extend({
|
||||||
featuresLayer: this.drawnItems
|
featuresLayer: this.drawnItems
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
this.startDrawing = function(control) {
|
||||||
|
// initial radius of 0 to detect click, see DeletableCircleEditor.onDrawingMouseUp
|
||||||
|
var opts = L.extend({ radius: 0 }, self.style);
|
||||||
|
editTools.startCircle(null, opts);
|
||||||
|
|
||||||
|
control.state('cancel-no-go-create');
|
||||||
|
};
|
||||||
|
|
||||||
|
this.stopDrawing = function(control) {
|
||||||
|
editTools.stopDrawing();
|
||||||
|
control.state('no-go-create');
|
||||||
|
};
|
||||||
|
|
||||||
this.button = L.easyButton({
|
this.button = L.easyButton({
|
||||||
states: [
|
states: [
|
||||||
{
|
{
|
||||||
stateName: BR.NogoAreas.STATE_CREATE,
|
stateName: BR.NogoAreas.STATE_CREATE,
|
||||||
icon: 'fa-ban',
|
icon: 'fa-ban',
|
||||||
title: BR.NogoAreas.MSG_BUTTON,
|
title: BR.NogoAreas.MSG_BUTTON,
|
||||||
onClick: function(control) {
|
onClick: this.startDrawing
|
||||||
// initial radius of 0 to detect click, see DeletableCircleEditor.onDrawingMouseUp
|
|
||||||
var opts = L.extend({ radius: 0 }, self.style);
|
|
||||||
editTools.startCircle(null, opts);
|
|
||||||
|
|
||||||
control.state('cancel-no-go-create');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
stateName: BR.NogoAreas.STATE_CANCEL,
|
stateName: BR.NogoAreas.STATE_CANCEL,
|
||||||
icon: 'fa-ban active',
|
icon: 'fa-ban active',
|
||||||
title: BR.NogoAreas.MSG_BUTTON_CANCEL,
|
title: BR.NogoAreas.MSG_BUTTON_CANCEL,
|
||||||
onClick: function(control) {
|
onClick: this.stopDrawing
|
||||||
editTools.stopDrawing();
|
|
||||||
control.state('no-go-create');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
@ -78,6 +91,8 @@ BR.NogoAreas = L.Control.extend({
|
||||||
// events firing in Chrome mobile while L.Map.Tap enabled for circle drawing
|
// events firing in Chrome mobile while L.Map.Tap enabled for circle drawing
|
||||||
L.DomEvent.addListener(this.button.button, 'pointerdown', L.DomEvent.stop);
|
L.DomEvent.addListener(this.button.button, 'pointerdown', L.DomEvent.stop);
|
||||||
|
|
||||||
|
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
|
||||||
|
|
||||||
this.editTools.on(
|
this.editTools.on(
|
||||||
'editable:drawing:end',
|
'editable:drawing:end',
|
||||||
function(e) {
|
function(e) {
|
||||||
|
|
@ -124,6 +139,20 @@ BR.NogoAreas = L.Control.extend({
|
||||||
return L.DomUtil.create('div');
|
return L.DomUtil.create('div');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_keydownListener: function(e) {
|
||||||
|
if (!BR.Util.keyboardShortcutsAllowed(e)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.keyCode === this.options.shortcut.draw.disable && this.button.state() === BR.NogoAreas.STATE_CANCEL) {
|
||||||
|
this.stopDrawing(this.button);
|
||||||
|
} else if (
|
||||||
|
e.keyCode === this.options.shortcut.draw.enable &&
|
||||||
|
this.button.state() === BR.NogoAreas.STATE_CREATE
|
||||||
|
) {
|
||||||
|
this.startDrawing(this.button);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
displayUploadError: function(message) {
|
displayUploadError: function(message) {
|
||||||
$('#nogoError').text(message ? message : '');
|
$('#nogoError').text(message ? message : '');
|
||||||
$('#nogoError').css('display', message ? 'block' : 'none');
|
$('#nogoError').css('display', message ? 'block' : 'none');
|
||||||
|
|
|
||||||
|
|
@ -114,9 +114,9 @@
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
"locate-me": "Show me where I am (L key)",
|
"locate-me": "Show me where I am (L key)",
|
||||||
"nogo": {
|
"nogo": {
|
||||||
"cancel": "Cancel drawing no-go area",
|
"cancel": "Cancel drawing no-go area (ESC key)",
|
||||||
"click-drag": "Click and drag to draw circle",
|
"click-drag": "Click and drag to draw circle",
|
||||||
"draw": "Draw no-go area (circle)",
|
"draw": "Draw circular no-go area (N key)",
|
||||||
"edit": "Click to edit",
|
"edit": "Click to edit",
|
||||||
"help": "□ = move / resize, <span class=\"fa fa-trash-o\"></span> = delete,<br>click circle to quit editing"
|
"help": "□ = move / resize, <span class=\"fa fa-trash-o\"></span> = delete,<br>click circle to quit editing"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue