mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
import { actionDeleteRelation } from './delete_relation';
|
|
import { actionDeleteWay } from './delete_way';
|
|
|
|
|
|
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteNodeAction.as
|
|
export function actionDeleteNode(nodeId) {
|
|
var action = function(graph) {
|
|
var node = graph.entity(nodeId);
|
|
|
|
// Prevent deletion of existing nodes (anti-vandalism)
|
|
if (node.version) {
|
|
throw new Error('Deletion of existing features is not allowed.');
|
|
}
|
|
|
|
graph.parentWays(node)
|
|
.forEach(function(parent) {
|
|
parent = parent.removeNode(nodeId);
|
|
graph = graph.replace(parent);
|
|
|
|
if (parent.isDegenerate()) {
|
|
graph = actionDeleteWay(parent.id)(graph);
|
|
}
|
|
});
|
|
|
|
graph.parentRelations(node)
|
|
.forEach(function(parent) {
|
|
parent = parent.removeMembersWithID(nodeId);
|
|
graph = graph.replace(parent);
|
|
|
|
if (parent.isDegenerate()) {
|
|
graph = actionDeleteRelation(parent.id)(graph);
|
|
}
|
|
});
|
|
|
|
return graph.remove(node);
|
|
};
|
|
|
|
|
|
return action;
|
|
}
|