mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
preserve disconnect for lines, improve disconnect for shared nodes in areas..
This commit is contained in:
+23
-14
@@ -17,19 +17,26 @@ iD.actions.Disconnect = function(nodeId, newNodeId) {
|
||||
|
||||
var action = function(graph) {
|
||||
var node = graph.entity(nodeId),
|
||||
replacements = action.replacements(graph);
|
||||
connections = action.connections(graph);
|
||||
|
||||
replacements.forEach(function(replacement) {
|
||||
var way = graph.entity(replacement.wayID),
|
||||
connections.forEach(function(connection) {
|
||||
var way = graph.entity(connection.wayID),
|
||||
newNode = iD.Node({id: newNodeId, loc: node.loc, tags: node.tags});
|
||||
|
||||
graph = graph.replace(newNode);
|
||||
graph = graph.replace(way.replaceNode(way.nodes[replacement.index], newNode.id));
|
||||
if (connection.index === 0 && way.isArea()) {
|
||||
// replace shared node with shared node..
|
||||
graph = graph.replace(way.replaceNode(way.nodes[0], newNode.id));
|
||||
} else {
|
||||
// replace shared node with multiple new nodes..
|
||||
graph = graph.replace(way.updateNode(newNode.id, connection.index));
|
||||
}
|
||||
});
|
||||
|
||||
return graph;
|
||||
};
|
||||
|
||||
action.replacements = function(graph) {
|
||||
action.connections = function(graph) {
|
||||
var candidates = [],
|
||||
keeping = false,
|
||||
parentWays = graph.parentWays(graph.entity(nodeId));
|
||||
@@ -39,21 +46,23 @@ iD.actions.Disconnect = function(nodeId, newNodeId) {
|
||||
keeping = true;
|
||||
return;
|
||||
}
|
||||
|
||||
way.nodes.forEach(function(waynode, index) {
|
||||
if (waynode === nodeId) {
|
||||
candidates.push({wayID: way.id, index: index});
|
||||
}
|
||||
});
|
||||
if (way.isArea() && (way.nodes[0] === nodeId)) {
|
||||
candidates.push({wayID: way.id, index: 0});
|
||||
} else {
|
||||
way.nodes.forEach(function(waynode, index) {
|
||||
if (waynode === nodeId) {
|
||||
candidates.push({wayID: way.id, index: index});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
candidates = _.uniq(candidates, function(item) { return item.wayID; } );
|
||||
return keeping ? candidates : candidates.slice(1);
|
||||
};
|
||||
|
||||
action.disabled = function(graph) {
|
||||
var replacements = action.replacements(graph);
|
||||
if (replacements.length === 0 || (wayIds && wayIds.length !== replacements.length))
|
||||
var connections = action.connections(graph);
|
||||
if (connections.length === 0 || (wayIds && wayIds.length !== connections.length))
|
||||
return 'not_connected';
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user