Files
iD/js/id/actions/add_midpoint.js
John Firebaugh b7894ceaf0 Calculate participating ways in AddMidpoint
Due to differenced redraw, midpoint.ways was getting stale,
so sometimes dragging a midpoint didn't add the new node to
all ways. Better to calculate participating ways when needed.
This also simplifies the code for adding a midpoint via double
click. It does make filtering midpoints on redraw a bit more
expensive, but a cursory profile didn't show it being a problem.

Fixes #763.
2013-02-27 20:41:38 -08:00

23 lines
819 B
JavaScript

iD.actions.AddMidpoint = function(midpoint, node) {
return function(graph) {
graph = graph.replace(node.move(midpoint.loc));
var parents = _.intersection(
graph.parentWays(graph.entity(midpoint.edge[0])),
graph.parentWays(graph.entity(midpoint.edge[1])));
parents.forEach(function(way) {
for (var i = 0; i < way.nodes.length - 1; i++) {
if ((way.nodes[i] === midpoint.edge[0] &&
way.nodes[i + 1] === midpoint.edge[1]) ||
(way.nodes[i] === midpoint.edge[1] &&
way.nodes[i + 1] === midpoint.edge[0])) {
graph = graph.replace(graph.entity(way.id).addNode(node.id, i + 1));
}
}
});
return graph;
};
};