Clean up modes

This commit is contained in:
John Firebaugh
2012-12-05 13:03:41 -05:00
parent b540e84ae0
commit 774d1de017
5 changed files with 35 additions and 61 deletions
+6 -15
View File
@@ -4,20 +4,13 @@ iD.modes.AddArea = function() {
title: '+ Area'
};
function way() {
return iD.Way({
tags: { building: 'yes', area: 'yes', elastic: 'true' }
});
}
mode.enter = function() {
mode.map.dblclickEnable(false);
var surface = mode.map.surface;
function click() {
mode.map.surface.on('click.addarea', function() {
var datum = d3.select(d3.event.target).datum() || {},
node, way = way();
node,
way = iD.Way({tags: { building: 'yes', area: 'yes', elastic: 'true' }});
// connect a way to an existing way
if (datum.type === 'node') {
@@ -30,11 +23,9 @@ iD.modes.AddArea = function() {
mode.history.perform(iD.actions.addWayNode(way, node));
mode.controller.enter(iD.modes.DrawArea(way.id));
}
});
surface.on('click.addarea', click);
mode.map.keybinding().on('⎋.exit', function() {
mode.map.keybinding().on('.addarea', function() {
mode.controller.exit();
});
};
@@ -44,7 +35,7 @@ iD.modes.AddArea = function() {
mode.map.dblclickEnable(true);
}, 1000);
mode.map.surface.on('click.addarea', null);
mode.map.keybinding().on('⎋.exit', null);
mode.map.keybinding().on('⎋.addarea', null);
};
return mode;
+5 -10
View File
@@ -5,25 +5,20 @@ iD.modes.AddPlace = function() {
};
mode.enter = function() {
var surface = mode.map.surface;
function click() {
mode.map.surface.on('click.addplace', function() {
var node = iD.Node({loc: mode.map.mouseCoordinates(), _poi: true});
mode.history.perform(iD.actions.addNode(node));
mode.controller.enter(iD.modes.Select(node));
}
});
surface.on('click.addplace', click);
mode.map.keybinding().on('⎋.exit', function() {
mode.map.keybinding().on('.addplace', function() {
mode.controller.exit();
});
};
mode.exit = function() {
mode.map.surface
.on('click.addplace', null);
mode.map.keybinding().on('⎋.exit', null);
mode.map.surface.on('click.addplace', null);
mode.map.keybinding().on('.addplace', null);
};
return mode;
+5 -11
View File
@@ -6,11 +6,8 @@ iD.modes.AddRoad = function() {
mode.enter = function() {
mode.map.dblclickEnable(false);
var surface = mode.map.surface;
// http://bit.ly/SwUwIL
// http://bit.ly/WxqGng
function click() {
mode.map.surface.on('click.addroad', function() {
var datum = d3.select(d3.event.target).datum() || {},
node,
direction = 'forward',
@@ -37,7 +34,7 @@ iD.modes.AddRoad = function() {
// begin a new way starting from an existing way
node = iD.Node({loc: mode.map.mouseCoordinates()});
var index = iD.util.geo.chooseIndex(datum, d3.mouse(surface.node()), mode.map);
var index = iD.util.geo.chooseIndex(datum, d3.mouse(mode.map.surface.node()), mode.map);
var connectedWay = mode.history.graph().entity(datum.id);
mode.history.perform(iD.actions.addWayNode(connectedWay, node, index));
} else {
@@ -51,11 +48,9 @@ iD.modes.AddRoad = function() {
}
mode.controller.enter(iD.modes.DrawRoad(way.id, direction));
}
});
surface.on('click.addroad', click);
mode.map.keybinding().on('⎋.exit', function() {
mode.map.keybinding().on('.addroad', function() {
mode.controller.exit();
});
};
@@ -63,8 +58,7 @@ iD.modes.AddRoad = function() {
mode.exit = function() {
mode.map.dblclickEnable(true);
mode.map.surface.on('click.addroad', null);
mode.map.keybinding().on('⎋.exit', null);
d3.selectAll('#addroad').remove();
mode.map.keybinding().on('⎋.addroad', null);
};
return mode;
+10 -13
View File
@@ -4,18 +4,17 @@ iD.modes.DrawArea = function(way_id) {
mode.enter = function() {
mode.map.dblclickEnable(false);
var surface = mode.map.surface,
way = mode.history.graph().entity(way_id),
var way = mode.history.graph().entity(way_id),
firstnode_id = _.first(way.nodes),
node = iD.Node({loc: mode.map.mouseCoordinates()});
mode.history.perform(iD.actions.addWayNode(way, node));
function mousemove() {
mode.map.surface.on('mousemove.drawarea', function() {
mode.history.replace(iD.actions.addWayNode(way, node.update({loc: mode.map.mouseCoordinates()})));
}
});
function click() {
mode.map.surface.on('click.drawarea', function() {
d3.event.stopPropagation();
var datum = d3.select(d3.event.target).datum();
@@ -40,20 +39,18 @@ iD.modes.DrawArea = function(way_id) {
}
mode.controller.enter(iD.modes.DrawArea(way_id));
}
mode.map.keybinding().on('⎋.exit', function() {
mode.controller.exit();
});
surface.on('click.drawarea', click)
.on('mousemove.drawarea', mousemove);
mode.map.keybinding().on('.drawarea', function() {
mode.controller.exit();
});
};
mode.exit = function() {
mode.map.surface.on('mousemove.drawarea', null)
mode.map.surface
.on('mousemove.drawarea', null)
.on('click.drawarea', null);
mode.map.keybinding().on('⎋.exit', null);
mode.map.keybinding().on('⎋.drawarea', null);
window.setTimeout(function() {
mode.map.dblclickEnable(true);
}, 1000);
+9 -12
View File
@@ -6,7 +6,6 @@ iD.modes.DrawRoad = function(way_id, direction) {
mode.map.dragEnable(false);
var index = (direction === 'forward') ? undefined : -1,
surface = mode.map.surface,
node = iD.Node({loc: mode.map.mouseCoordinates()}),
way = mode.history.graph().entity(way_id),
firstNode = way.nodes[0],
@@ -14,11 +13,11 @@ iD.modes.DrawRoad = function(way_id, direction) {
mode.history.perform(iD.actions.addWayNode(way, node, index));
function mousemove() {
mode.map.surface.on('mousemove.drawroad', function() {
mode.history.replace(iD.actions.addWayNode(way, node.update({loc: mode.map.mouseCoordinates()}), index));
}
});
function click() {
mode.map.surface.on('click.drawroad', function() {
d3.event.stopPropagation();
var datum = d3.select(d3.event.target).datum() || {};
@@ -49,7 +48,7 @@ iD.modes.DrawRoad = function(way_id, direction) {
mode.history.replace(iD.actions.addWayNode(way, node, index));
var connectedWay = mode.history.graph().entity(datum.id);
var connectedIndex = iD.modes.chooseIndex(datum, d3.mouse(surface.node()), mode.map);
var connectedIndex = iD.modes.chooseIndex(datum, d3.mouse(mode.map.surface.node()), mode.map);
mode.history.perform(iD.actions.addWayNode(connectedWay, node, connectedIndex));
} else {
node = node.update({loc: mode.map.mouseCoordinates()});
@@ -57,20 +56,18 @@ iD.modes.DrawRoad = function(way_id, direction) {
}
mode.controller.enter(iD.modes.DrawRoad(way_id, direction));
}
});
surface.on('mousemove.drawroad', mousemove)
.on('click.drawroad', click);
mode.map.keybinding().on('⎋.exit', function() {
mode.map.keybinding().on('⎋.drawroad', function() {
mode.controller.exit();
});
};
mode.exit = function() {
mode.map.surface.on('mousemove.drawroad', null)
mode.map.surface
.on('mousemove.drawroad', null)
.on('click.drawroad', null);
mode.map.keybinding().on('⎋.exit', null);
mode.map.keybinding().on('⎋.drawroad', null);
window.setTimeout(function() {
mode.map.dblclickEnable(true);
mode.map.dragEnable(true);