Files
iD/js/id/actions/move.js
2013-03-29 12:29:07 -07:00

44 lines
1.4 KiB
JavaScript

// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as
iD.actions.Move = function(ids, delta, projection) {
function addNodes(ids, nodes, graph) {
ids.forEach(function(id) {
var entity = graph.entity(id);
if (entity.type === 'node') {
nodes.push(id);
} else if (entity.type === 'way') {
nodes.push.apply(nodes, entity.nodes);
} else {
addNodes(_.pluck(entity.members, 'id'), nodes, graph);
}
});
}
var action = function(graph) {
var nodes = [];
addNodes(ids, nodes, graph);
_.uniq(nodes).forEach(function(id) {
var node = graph.entity(id),
start = projection(node.loc),
end = projection.invert([start[0] + delta[0], start[1] + delta[1]]);
graph = graph.replace(node.move(end));
});
return graph;
};
action.disabled = function(graph) {
function incompleteRelation(id) {
var entity = graph.entity(id);
return entity.type === 'relation' && !entity.isComplete(graph);
}
if (_.any(ids, incompleteRelation))
return 'incomplete_relation';
};
return action;
};