Files
iD/js/id/actions/delete_way.js
John Firebaugh 163c85bacb Delete relations that become empty
Fixes #465
Fixes #1454
2013-08-27 12:27:11 -07:00

40 lines
1.1 KiB
JavaScript

// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
iD.actions.DeleteWay = function(wayId) {
function deleteNode(node, graph) {
return !graph.parentWays(node).length &&
!graph.parentRelations(node).length &&
!node.hasInterestingTags();
}
var action = function(graph) {
var way = graph.entity(wayId);
graph.parentRelations(way)
.forEach(function(parent) {
parent = parent.removeMembersWithID(wayId);
graph = graph.replace(parent);
if (parent.isDegenerate()) {
graph = iD.actions.DeleteRelation(parent.id)(graph);
}
});
_.uniq(way.nodes).forEach(function(nodeId) {
graph = graph.replace(way.removeNode(nodeId));
var node = graph.entity(nodeId);
if (deleteNode(node, graph)) {
graph = graph.remove(node);
}
});
return graph.remove(way);
};
action.disabled = function() {
return false;
};
return action;
};