Files
iD/js/id/actions/remove_way_node.js
John Firebaugh 3e45afbc5e Move history annotation to History#perform/replace
Actions are too low-level for annotations.
2012-12-07 10:35:39 -05:00

18 lines
664 B
JavaScript

iD.actions.RemoveWayNode = function(wayId, nodeId) {
return function(graph) {
var way = graph.entity(wayId), nodes;
// If this is the connecting node in a closed area
if (way.nodes.length > 1 &&
_.indexOf(way.nodes, nodeId) === 0 &&
_.lastIndexOf(way.nodes, nodeId) === way.nodes.length - 1) {
// Remove the node
nodes = _.without(way.nodes, nodeId);
// And reclose the way on the new first node.
nodes.push(nodes[0]);
} else {
nodes = _.without(way.nodes, nodeId);
}
return graph.replace(way.update({nodes: nodes}));
};
};