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({
|
||||
options: {
|
||||
shortcut: {
|
||||
draw: {
|
||||
enable: 78, // char code for 'n'
|
||||
disable: 27 // char code for 'ESC'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
statics: {
|
||||
MSG_BUTTON: 'Draw no-go area (circle)',
|
||||
MSG_BUTTON_CANCEL: 'Cancel drawing no-go area',
|
||||
|
|
@ -48,28 +57,32 @@ BR.NogoAreas = L.Control.extend({
|
|||
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({
|
||||
states: [
|
||||
{
|
||||
stateName: BR.NogoAreas.STATE_CREATE,
|
||||
icon: 'fa-ban',
|
||||
title: BR.NogoAreas.MSG_BUTTON,
|
||||
onClick: 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');
|
||||
}
|
||||
onClick: this.startDrawing
|
||||
},
|
||||
{
|
||||
stateName: BR.NogoAreas.STATE_CANCEL,
|
||||
icon: 'fa-ban active',
|
||||
title: BR.NogoAreas.MSG_BUTTON_CANCEL,
|
||||
onClick: function(control) {
|
||||
editTools.stopDrawing();
|
||||
control.state('no-go-create');
|
||||
}
|
||||
onClick: this.stopDrawing
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
@ -78,6 +91,8 @@ BR.NogoAreas = L.Control.extend({
|
|||
// 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(document, 'keydown', this._keydownListener, this);
|
||||
|
||||
this.editTools.on(
|
||||
'editable:drawing:end',
|
||||
function(e) {
|
||||
|
|
@ -124,6 +139,20 @@ BR.NogoAreas = L.Control.extend({
|
|||
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) {
|
||||
$('#nogoError').text(message ? message : '');
|
||||
$('#nogoError').css('display', message ? 'block' : 'none');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue