mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-13 06:36:28 +00:00
Can't unconditionally delete the node; it may be a member of other ways. I didn't preserve the behavior of dragging a midpoint to an adjacent node being a no-op. In general we don't try to eliminate compound operations whose net result is a no-op; I don't think it's important to do so for this special case. The degenerate case of connecting the endpoints of a two-vertex line now results in a point. This is what naturally resulted from the code, and seems ok. Fixes #983.
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
// Connect the ways at the given nodes.
|
|
//
|
|
// The last node will survive. All other nodes will be replaced with
|
|
// the surviving node in parent ways, and then removed.
|
|
//
|
|
// Tags and relation memberships of of non-surviving nodes are merged
|
|
// to the survivor.
|
|
//
|
|
// This is the inverse of `iD.actions.Disconnect`.
|
|
//
|
|
// Reference:
|
|
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MergeNodesAction.as
|
|
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/actions/MergeNodesAction.java
|
|
//
|
|
iD.actions.Connect = function(nodeIds) {
|
|
var action = function(graph) {
|
|
var survivor = graph.entity(_.last(nodeIds));
|
|
|
|
for (var i = 0; i < nodeIds.length - 1; i++) {
|
|
var node = graph.entity(nodeIds[i]);
|
|
|
|
graph.parentWays(node).forEach(function(parent) {
|
|
if (!parent.areAdjacent(node.id, survivor.id)) {
|
|
graph = graph.replace(parent.replaceNode(node.id, survivor.id));
|
|
}
|
|
});
|
|
|
|
graph.parentRelations(node).forEach(function(parent) {
|
|
graph = graph.replace(parent.replaceMember(node, survivor));
|
|
});
|
|
|
|
survivor = survivor.mergeTags(node.tags);
|
|
graph = iD.actions.DeleteNode(node.id)(graph);
|
|
}
|
|
|
|
graph = graph.replace(survivor);
|
|
|
|
return graph;
|
|
};
|
|
|
|
action.enabled = function() {
|
|
return nodeIds.length > 1;
|
|
};
|
|
|
|
return action;
|
|
};
|