Merge branch 'spacebar-drawing' of https://github.com/naturalatlas/iD into naturalatlas-spacebar-drawing

This commit is contained in:
Bryan Housel
2016-05-13 17:26:54 -04:00
2 changed files with 27 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
iD.behavior.Draw = function(context) {
var event = d3.dispatch('move', 'click', 'clickWay',
'clickNode', 'undo', 'cancel', 'finish'),
'clickNode', 'undo', 'cancel', 'finish',
'spacedown', 'spacedownNode', 'spacedownWay'),
keybinding = d3.keybinding('draw'),
hover = iD.behavior.Hover(context)
.altDisables(true)
@@ -8,7 +9,8 @@ iD.behavior.Draw = function(context) {
tail = iD.behavior.Tail(),
edit = iD.behavior.Edit(context),
closeTolerance = 4,
tolerance = 12;
tolerance = 12,
lastDatum = {};
function datum() {
if (d3.event.altKey) return {};
@@ -58,7 +60,8 @@ iD.behavior.Draw = function(context) {
}
function mousemove() {
event.move(datum());
lastDatum = datum();
event.move(lastDatum);
}
function click() {
@@ -76,6 +79,21 @@ iD.behavior.Draw = function(context) {
}
}
function space() {
var d = lastDatum;
if (d.type === 'way') {
var choice = iD.geo.chooseEdge(context.childNodes(d), context.mouse(), context.projection),
edge = [d.nodes[choice.index - 1], d.nodes[choice.index]];
event.spacedownWay(choice.loc, edge);
} else if (d.type === 'node') {
event.spacedownNode(d);
} else {
event.spacedown(context.map().mouseCoordinates());
}
}
function backspace() {
d3.event.preventDefault();
event.undo();
@@ -103,7 +121,9 @@ iD.behavior.Draw = function(context) {
.on('⌫', backspace)
.on('⌦', del)
.on('⎋', ret)
.on('↩', ret);
.on('↩', ret)
.on('space', space)
.on('Alt+space', space);
selection
.on('mousedown.draw', mousedown)

View File

@@ -55,6 +55,9 @@ iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) {
.on('click', drawWay.add)
.on('clickWay', drawWay.addWay)
.on('clickNode', drawWay.addNode)
.on('spacedown', drawWay.add)
.on('spacedownWay', drawWay.addWay)
.on('spacedownNode', drawWay.addNode)
.on('undo', context.undo)
.on('cancel', drawWay.cancel)
.on('finish', drawWay.finish);