Toggle beeline mode and style beeline

Restore removed key listeners of super class to avoid duplicate calls (36d8a20)
This commit is contained in:
Norbert Renner 2021-04-29 20:41:38 +02:00
parent acf9c59888
commit b4368c1f51
2 changed files with 28 additions and 4 deletions

View file

@ -100,6 +100,18 @@
nodata: { nodata: {
color: 'darkred', color: 'darkred',
}, },
beeline: {
weight: 5,
dashArray: [1, 10],
color: 'magenta',
opacity: BR.conf.defaultOpacity,
},
beelineTrailer: {
weight: 5,
dashArray: [1, 10],
opacity: 0.6,
color: 'magenta',
},
}; };
BR.conf.markerColors = { BR.conf.markerColors = {

View file

@ -28,6 +28,11 @@ BR.Routing = L.Routing.extend({
draw: { draw: {
enable: 68, // char code for 'd' enable: 68, // char code for 'd'
disable: 27, // char code for 'ESC' disable: 27, // char code for 'ESC'
beelineMode: 66, // char code for 'b'
// char code for 'Shift', same key as `beelineModifierName`
beelineModifier: 16,
// modifier key to draw straight line on click [shiftKey|null] (others don't work everywhere)
beelineModifierName: 'shiftKey',
}, },
reverse: 82, // char code for 'r' reverse: 82, // char code for 'r'
deleteLastPoint: 90, // char code for 'z' deleteLastPoint: 90, // char code for 'z'
@ -175,6 +180,11 @@ BR.Routing = L.Routing.extend({
this._draw this._draw
); );
// remove listeners registered in super.onAdd, keys not working when map container lost focus
// (by navbar/sidebar interaction), use document instead
L.DomEvent.removeListener(this._container, 'keydown', this._keydownListener, this);
L.DomEvent.removeListener(this._container, 'keyup', this._keyupListener, this);
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this); L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
L.DomEvent.addListener(document, 'keyup', this._keyupListener, this); L.DomEvent.addListener(document, 'keyup', this._keyupListener, this);
@ -376,14 +386,16 @@ BR.Routing = L.Routing.extend({
this.reverse(); this.reverse();
} else if (e.keyCode === this.options.shortcut.deleteLastPoint) { } else if (e.keyCode === this.options.shortcut.deleteLastPoint) {
this.deleteLastPoint(); this.deleteLastPoint();
} else if (e.keyCode === this.options.shortcut.draw.beelineMode) {
this.toggleBeelineDrawing();
} else if (e.keyCode === this.options.shortcut.draw.beelineModifier) {
this._draw._setTrailerStyle(true);
} }
}, },
_keyupListener: function (e) { _keyupListener: function (e) {
// Prevent Leaflet from triggering drawing a second time on keyup, if (e.keyCode === this.options.shortcut.draw.beelineModifier) {
// since this is already done in _keydownListener this._draw._setTrailerStyle(false);
if (e.keyCode === this.options.shortcut.draw.enable) {
return;
} }
}, },