mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 23:14:47 +02:00
Extract AddMidpoint action
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
<script src='js/id/ui/key_reference.js'></script>
|
||||
|
||||
<script src='js/id/actions.js'></script>
|
||||
<script src="js/id/actions/add_midpoint.js"></script>
|
||||
<script src='js/id/actions/add_node.js'></script>
|
||||
<script src='js/id/actions/add_way.js'></script>
|
||||
<script src='js/id/actions/add_way_node.js'></script>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
iD.actions.AddMidpoint = function(midpoint, node) {
|
||||
return function(graph) {
|
||||
graph = graph.replace(node.move(midpoint.loc));
|
||||
|
||||
midpoint.ways.forEach(function(way) {
|
||||
graph = graph.replace(graph.entity(way.id).addNode(node.id, way.index));
|
||||
});
|
||||
|
||||
return graph;
|
||||
};
|
||||
};
|
||||
@@ -8,14 +8,9 @@ iD.behavior.DragMidpoint = function(mode) {
|
||||
return projection(d.loc);
|
||||
})
|
||||
.on('start', function(d) {
|
||||
var node = iD.Node({loc: d.loc});
|
||||
var node = iD.Node();
|
||||
|
||||
var args = [iD.actions.AddNode(node)];
|
||||
for (var i = 0; i < d.ways.length; i++) {
|
||||
args.push(iD.actions.AddWayNode(d.ways[i].id, node.id, d.ways[i].index));
|
||||
}
|
||||
|
||||
history.perform.apply(history, args);
|
||||
history.perform(iD.actions.AddMidpoint(d, node));
|
||||
|
||||
var vertex = d3.selectAll('.vertex')
|
||||
.filter(function(data) { return data.id === node.id; });
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<script src='../js/id/ui/confirm.js'></script>
|
||||
|
||||
<script src='../js/id/actions.js'></script>
|
||||
<script src="../js/id/actions/add_midpoint.js"></script>
|
||||
<script src='../js/id/actions/add_node.js'></script>
|
||||
<script src='../js/id/actions/add_way.js'></script>
|
||||
<script src='../js/id/actions/add_way_node.js'></script>
|
||||
@@ -137,6 +138,7 @@
|
||||
<!-- include spec files here... -->
|
||||
<script src="spec/lib/d3.keybinding.js"></script>
|
||||
|
||||
<script src="spec/actions/add_midpoint.js"></script>
|
||||
<script src="spec/actions/add_node.js"></script>
|
||||
<script src="spec/actions/add_way.js"></script>
|
||||
<script src="spec/actions/change_entity_tags.js"></script>
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<!-- include spec files here... -->
|
||||
<script src="spec/lib/d3.keybinding.js"></script>
|
||||
|
||||
<script src="spec/actions/add_midpoint.js"></script>
|
||||
<script src="spec/actions/add_node.js"></script>
|
||||
<script src="spec/actions/add_way.js"></script>
|
||||
<script src="spec/actions/change_entity_tags.js"></script>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
describe("iD.actions.AddMidpoint", function () {
|
||||
it("adds the node at the midpoint location", function () {
|
||||
var node = iD.Node(),
|
||||
midpoint = {loc: [1, 2], ways: []},
|
||||
graph = iD.actions.AddMidpoint(midpoint, node)(iD.Graph());
|
||||
|
||||
expect(graph.entity(node.id).loc).to.eql([1, 2]);
|
||||
});
|
||||
|
||||
it("adds the node to all ways at the respective indexes", function () {
|
||||
var node = iD.Node(),
|
||||
a = iD.Node(),
|
||||
b = iD.Node(),
|
||||
w1 = iD.Way(),
|
||||
w2 = iD.Way({nodes: [a.id, b.id]}),
|
||||
midpoint = {loc: [1, 2], ways: [{id: w1.id, index: 0}, {id: w2.id, index: 1}]},
|
||||
graph = iD.actions.AddMidpoint(midpoint, node)(iD.Graph([a, b, w1, w2]));
|
||||
|
||||
expect(graph.entity(w1.id).nodes).to.eql([node.id]);
|
||||
expect(graph.entity(w2.id).nodes).to.eql([a.id, node.id, b.id]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user