Files
iD/modules/actions/delete_way.js
Bryan Housel 37534aed0e More cleanup of operations and post-paste behavior
* Support move, rotate, reflect, delete post paste on multiselection
* Improve text and error msgs for singular vs multi selections
* Move `disabled` checks from actions to operations
* Reproject center of rotation (closes #3667)
* Cleanup tests
2016-12-21 23:58:13 -05:00

44 lines
1.2 KiB
JavaScript

import _ from 'lodash';
import { actionDeleteRelation } from './delete_relation';
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
export function actionDeleteWay(wayId) {
function canDeleteNode(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 = actionDeleteRelation(parent.id)(graph);
}
});
_.uniq(way.nodes).forEach(function(nodeId) {
graph = graph.replace(way.removeNode(nodeId));
var node = graph.entity(nodeId);
if (canDeleteNode(node, graph)) {
graph = graph.remove(node);
}
});
return graph.remove(way);
};
return action;
}