Fix drawing on midpoints (fixes #559)

This commit is contained in:
John Firebaugh
2013-01-30 15:59:13 -05:00
parent dbac370c71
commit 168a3b5e26
6 changed files with 56 additions and 9 deletions
+3 -2
View File
@@ -1,13 +1,14 @@
iD.behavior.AddWay = function(mode) {
var map = mode.map,
controller = mode.controller,
event = d3.dispatch('startFromNode', 'startFromWay', 'start'),
event = d3.dispatch('start', 'startFromWay', 'startFromNode', 'startFromMidpoint'),
draw = iD.behavior.Draw(map);
var addWay = function(surface) {
draw.on('click', event.start)
.on('clickNode', event.startFromNode)
.on('clickWay', event.startFromWay)
.on('clickNode', event.startFromNode)
.on('clickMidpoint', event.startFromMidpoint)
.on('cancel', addWay.cancel)
.on('finish', addWay.cancel);
+8 -6
View File
@@ -1,5 +1,5 @@
iD.behavior.Draw = function(map) {
var event = d3.dispatch('move', 'click', 'clickNode', 'clickWay', 'undo', 'cancel', 'finish'),
var event = d3.dispatch('move', 'click', 'clickWay', 'clickNode', 'clickMidpoint', 'undo', 'cancel', 'finish'),
keybinding = d3.keybinding('draw'),
down, surface, hover;
@@ -27,14 +27,16 @@ iD.behavior.Draw = function(map) {
function click() {
var d = datum();
if (d.type === 'node') {
event.clickNode(d);
} else if (d.type === 'way') {
if (d.type === 'way') {
var choice = iD.geo.chooseIndex(d, d3.mouse(map.surface.node()), map);
event.clickWay(d, choice.loc, choice.index);
} else if (d.type === 'node') {
event.clickNode(d);
} else if (d.midpoint) {
var way = history.graph().entity(d.way);
event.clickWay(way, d.loc, d.index);
event.clickMidpoint(d);
} else {
event.click(map.mouseCoordinates());
}
+15 -1
View File
@@ -33,8 +33,9 @@ iD.behavior.DrawWay = function(wayId, index, mode, baseGraph) {
var drawWay = function(surface) {
draw.on('move', move)
.on('click', drawWay.add)
.on('clickNode', drawWay.addNode)
.on('clickWay', drawWay.addWay)
.on('clickNode', drawWay.addNode)
.on('clickMidpoint', drawWay.addMidpoint)
.on('undo', history.undo)
.on('cancel', drawWay.cancel)
.on('finish', drawWay.finish);
@@ -121,6 +122,19 @@ iD.behavior.DrawWay = function(wayId, index, mode, baseGraph) {
controller.enter(mode);
};
// Add a midpoint, connect the way to it, and continue drawing.
drawWay.addMidpoint = function(midpoint) {
var node = iD.Node();
history.perform(
iD.actions.AddMidpoint(midpoint, node),
ReplaceTemporaryNode(node),
annotation);
finished = true;
controller.enter(mode);
};
// Finish the draw operation, removing the temporary node. If the way has enough
// nodes to be valid, it's selected. Otherwise, return to browse mode.
drawWay.finish = function() {
+15
View File
@@ -15,6 +15,20 @@ iD.modes.AddArea = function() {
history = mode.history,
controller = mode.controller;
function startFromMidpoint(midpoint) {
var graph = history.graph(),
node = iD.Node(),
way = iD.Way({tags: defaultTags});
history.perform(
iD.actions.AddMidpoint(midpoint, node),
iD.actions.AddWay(way),
iD.actions.AddWayNode(way.id, node.id),
iD.actions.AddWayNode(way.id, node.id));
controller.enter(iD.modes.DrawArea(way.id, graph));
}
function startFromNode(node) {
var graph = history.graph(),
way = iD.Way({tags: defaultTags});
@@ -57,6 +71,7 @@ iD.modes.AddArea = function() {
}
behavior = iD.behavior.AddWay(mode)
.on('startFromMidpoint', startFromMidpoint)
.on('startFromNode', startFromNode)
.on('startFromWay', startFromWay)
.on('start', start);
+14
View File
@@ -15,6 +15,19 @@ iD.modes.AddLine = function() {
history = mode.history,
controller = mode.controller;
function startFromMidpoint(midpoint) {
var graph = history.graph(),
node = iD.Node(),
way = iD.Way({tags: defaultTags});
history.perform(
iD.actions.AddMidpoint(midpoint, node),
iD.actions.AddWay(way),
iD.actions.AddWayNode(way.id, node.id));
controller.enter(iD.modes.DrawLine(way.id, 'forward', graph));
}
function startFromNode(node) {
var graph = history.graph(),
parent = graph.parentWays(node)[0],
@@ -65,6 +78,7 @@ iD.modes.AddLine = function() {
}
behavior = iD.behavior.AddWay(mode)
.on('startFromMidpoint', startFromMidpoint)
.on('startFromNode', startFromNode)
.on('startFromWay', startFromWay)
.on('start', start);
+1
View File
@@ -42,6 +42,7 @@ iD.modes.AddPoint = function() {
.on('click', add)
.on('clickWay', addWay)
.on('clickNode', addNode)
.on('clickMidpoint', addNode)
.on('cancel', cancel)
.on('finish', cancel)
(surface);