mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 06:58:32 +02:00
Added iD.actions.CopyEntity
This commit is contained in:
@@ -147,6 +147,7 @@
|
||||
<script src='js/id/actions/change_tags.js'></script>
|
||||
<script src='js/id/actions/circularize.js'></script>
|
||||
<script src='js/id/actions/connect.js'></script>
|
||||
<script src='js/id/actions/copy_entity.js'></script>
|
||||
<script src='js/id/actions/delete_member.js'></script>
|
||||
<script src='js/id/actions/delete_multiple.js'></script>
|
||||
<script src='js/id/actions/delete_node.js'></script>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
iD.actions.CopyEntity = function(entity, deep) {
|
||||
return function(graph) {
|
||||
var newEntities = entity.copy({}, deep, graph);
|
||||
|
||||
for (var i = 0, imax = newEntities.length; i !== imax; i++) {
|
||||
graph = graph.replace(newEntities[i]);
|
||||
}
|
||||
|
||||
return graph;
|
||||
};
|
||||
};
|
||||
@@ -126,6 +126,7 @@
|
||||
<script src='../js/id/actions/change_tags.js'></script>
|
||||
<script src='../js/id/actions/circularize.js'></script>
|
||||
<script src='../js/id/actions/connect.js'></script>
|
||||
<script src='../js/id/actions/copy_entity.js'></script>
|
||||
<script src='../js/id/actions/delete_member.js'></script>
|
||||
<script src='../js/id/actions/delete_multiple.js'></script>
|
||||
<script src='../js/id/actions/delete_node.js'></script>
|
||||
@@ -225,6 +226,7 @@
|
||||
<script src='spec/actions/orthogonalize.js'></script>
|
||||
<script src='spec/actions/straighten.js'></script>
|
||||
<script src='spec/actions/connect.js'></script>
|
||||
<script src="spec/actions/copy_entity.js"></script>
|
||||
<script src='spec/actions/delete_member.js'></script>
|
||||
<script src="spec/actions/delete_multiple.js"></script>
|
||||
<script src="spec/actions/delete_node.js"></script>
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<script src="spec/actions/change_tags.js"></script>
|
||||
<script src='spec/actions/circularize.js'></script>
|
||||
<script src='spec/actions/connect.js'></script>
|
||||
<script src="spec/actions/copy_entity.js"></script>
|
||||
<script src='spec/actions/delete_member.js'></script>
|
||||
<script src="spec/actions/delete_multiple.js"></script>
|
||||
<script src="spec/actions/delete_node.js"></script>
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
describe("iD.actions.CopyEntity", function () {
|
||||
it("copies a Node and adds it to the graph", function () {
|
||||
var a = iD.Node({id: 'a'}),
|
||||
base = iD.Graph([a]),
|
||||
head = iD.actions.CopyEntity(a)(base),
|
||||
diff = iD.Difference(base, head),
|
||||
created = diff.created();
|
||||
|
||||
expect(head.hasEntity('a')).to.be.ok;
|
||||
expect(created).to.have.length(1);
|
||||
expect(created[0]).to.be.an.instanceof(iD.Node);
|
||||
});
|
||||
|
||||
it("shallow copies a Way and adds it to the graph", function () {
|
||||
var a = iD.Node({id: 'a'}),
|
||||
b = iD.Node({id: 'b'}),
|
||||
w = iD.Way({id: 'w', nodes: ['a', 'b']}),
|
||||
base = iD.Graph([a, b, w]),
|
||||
head = iD.actions.CopyEntity(w)(base),
|
||||
diff = iD.Difference(base, head),
|
||||
created = diff.created();
|
||||
|
||||
expect(head.hasEntity('w')).to.be.ok;
|
||||
expect(created).to.have.length(1);
|
||||
expect(created[0]).to.be.an.instanceof(iD.Way);
|
||||
});
|
||||
|
||||
it("deep copies a Way and child Nodes and adds them to the graph", function () {
|
||||
var a = iD.Node({id: 'a'}),
|
||||
b = iD.Node({id: 'b'}),
|
||||
w = iD.Way({id: 'w', nodes: ['a', 'b']}),
|
||||
base = iD.Graph([a, b, w]),
|
||||
head = iD.actions.CopyEntity(w, true)(base),
|
||||
diff = iD.Difference(base, head),
|
||||
created = diff.created();
|
||||
|
||||
expect(head.hasEntity('w')).to.be.ok;
|
||||
expect(created).to.have.length(3);
|
||||
expect(created[0]).to.be.an.instanceof(iD.Way);
|
||||
expect(created[1]).to.be.an.instanceof(iD.Node);
|
||||
expect(created[2]).to.be.an.instanceof(iD.Node);
|
||||
});
|
||||
|
||||
it("shallow copies a Relation and adds it to the graph", function () {
|
||||
var a = iD.Node({id: 'a'}),
|
||||
b = iD.Node({id: 'b'}),
|
||||
w = iD.Way({id: 'w', nodes: ['a', 'b']}),
|
||||
r = iD.Relation({id: 'r', members: [{id: 'w'}]}),
|
||||
base = iD.Graph([a, b, w, r]),
|
||||
head = iD.actions.CopyEntity(r)(base),
|
||||
diff = iD.Difference(base, head),
|
||||
created = diff.created();
|
||||
|
||||
expect(head.hasEntity('r')).to.be.ok;
|
||||
expect(created).to.have.length(1);
|
||||
expect(created[0]).to.be.an.instanceof(iD.Relation);
|
||||
});
|
||||
|
||||
it("deep copies a Relation, member Ways, and child Nodes and adds them to the graph", function () {
|
||||
var a = iD.Node({id: 'a'}),
|
||||
b = iD.Node({id: 'b'}),
|
||||
w = iD.Way({id: 'w', nodes: ['a', 'b']}),
|
||||
r = iD.Relation({id: 'r', members: [{id: 'w'}]}),
|
||||
base = iD.Graph([a, b, w, r]),
|
||||
head = iD.actions.CopyEntity(r, true)(base),
|
||||
diff = iD.Difference(base, head),
|
||||
created = diff.created();
|
||||
|
||||
expect(head.hasEntity('r')).to.be.ok;
|
||||
expect(created).to.have.length(4);
|
||||
expect(created[0]).to.be.an.instanceof(iD.Relation);
|
||||
expect(created[1]).to.be.an.instanceof(iD.Way);
|
||||
expect(created[2]).to.be.an.instanceof(iD.Node);
|
||||
expect(created[3]).to.be.an.instanceof(iD.Node);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user