mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 17:52:55 +00:00
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import _ from 'lodash';
|
|
import { DeleteRelation } from './delete_relation';
|
|
|
|
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
|
|
export function DeleteWay(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 = 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(graph) {
|
|
var disabled = false;
|
|
|
|
graph.parentRelations(graph.entity(wayId)).forEach(function(parent) {
|
|
var type = parent.tags.type,
|
|
role = parent.memberById(wayId).role || 'outer';
|
|
if (type === 'route' || type === 'boundary' || (type === 'multipolygon' && role === 'outer')) {
|
|
disabled = 'part_of_relation';
|
|
}
|
|
});
|
|
|
|
return disabled;
|
|
};
|
|
|
|
return action;
|
|
}
|