Delete ways and areas when they are down to one and two nodes

This commit is contained in:
Tom MacWright
2012-12-12 16:56:40 -05:00
parent 3cbf3739c0
commit 14fd8e0951
2 changed files with 24 additions and 7 deletions

View File

@@ -8,7 +8,9 @@ iD.modes.DrawArea = function(wayId) {
history = mode.history,
controller = mode.controller,
way = history.graph().entity(wayId),
headId = _.last(way.nodes),
headId = (way.nodes.length == 1) ?
way.nodes[0] :
way.nodes[way.nodes.length - 2],
tailId = _.first(way.nodes),
node = iD.Node({loc: map.mouseCoordinates()});
@@ -68,7 +70,14 @@ iD.modes.DrawArea = function(wayId) {
iD.actions.DeleteNode(node.id),
iD.actions.DeleteNode(headId));
controller.enter(iD.modes.DrawArea(wayId));
if (history.graph().fetch(wayId).nodes.length === 2) {
history.replace(
iD.actions.DeleteNode(way.nodes[0]),
iD.actions.DeleteWay(wayId));
controller.enter(iD.modes.Browse());
} else {
controller.enter(iD.modes.DrawArea(wayId));
}
}
map.surface.on('mousemove.drawarea', mousemove);

View File

@@ -74,22 +74,30 @@ iD.modes.DrawRoad = function(wayId, direction) {
}
});
map.keybinding().on('⎋.drawroad', function() {
function esc() {
history.replace(
iD.actions.DeleteNode(node.id));
controller.enter(iD.modes.Browse());
});
}
map.keybinding().on('⌫.drawroad', function() {
function del() {
d3.event.preventDefault();
history.replace(
iD.actions.DeleteNode(node.id),
iD.actions.DeleteNode(headId));
controller.enter(iD.modes.DrawRoad(wayId, direction));
});
if (history.graph().fetch(wayId).nodes.length === 0) {
history.replace(iD.actions.DeleteWay(wayId));
controller.enter(iD.modes.Browse());
} else {
controller.enter(iD.modes.DrawRoad(wayId, direction));
}
}
map.keybinding().on('⎋.drawroad', esc);
map.keybinding().on('⌫.drawroad', del);
};
mode.exit = function() {