Files
iD/js/id/actions/delete_way.js
2013-02-27 16:32:26 -08:00

29 lines
888 B
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();
}
return function(graph) {
var way = graph.entity(wayId);
graph.parentRelations(way)
.forEach(function(parent) {
graph = graph.replace(parent.removeMember(wayId));
});
_.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);
};
};