mirror of
https://github.com/FoggedLens/iD.git
synced 2026-06-04 22:18:06 +02:00
Merge branch 'master' of github.com:systemed/iD
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteNodeAction.as
|
||||
iD.actions.DeleteNode = function(nodeId) {
|
||||
return function(graph) {
|
||||
var action = function(graph) {
|
||||
var node = graph.entity(nodeId);
|
||||
|
||||
graph.parentWays(node)
|
||||
@@ -20,4 +20,10 @@ iD.actions.DeleteNode = function(nodeId) {
|
||||
|
||||
return graph.remove(node);
|
||||
};
|
||||
|
||||
action.enabled = function(graph) {
|
||||
return true;
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
|
||||
iD.actions.DeleteWay = function(wayId) {
|
||||
return function(graph) {
|
||||
var action = function(graph) {
|
||||
var way = graph.entity(wayId);
|
||||
|
||||
graph.parentRelations(way)
|
||||
@@ -29,4 +29,10 @@ iD.actions.DeleteWay = function(wayId) {
|
||||
|
||||
return graph.remove(way);
|
||||
};
|
||||
|
||||
action.enabled = function(graph) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -53,7 +53,7 @@ iD.actions.ReverseWay = function(wayId) {
|
||||
}
|
||||
}
|
||||
|
||||
return function(graph) {
|
||||
var action = function(graph) {
|
||||
var way = graph.entity(wayId),
|
||||
nodes = way.nodes.slice().reverse(),
|
||||
tags = {}, key, role;
|
||||
@@ -73,4 +73,10 @@ iD.actions.ReverseWay = function(wayId) {
|
||||
|
||||
return graph.replace(way.update({nodes: nodes, tags: tags}));
|
||||
};
|
||||
|
||||
action.enabled = function(graph) {
|
||||
return true;
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ iD.actions.SplitWay = function(nodeId, newWayId) {
|
||||
}
|
||||
|
||||
var action = function(graph) {
|
||||
if (!action.permitted(graph))
|
||||
if (!action.enabled(graph))
|
||||
return graph;
|
||||
|
||||
var way = candidateWays(graph)[0],
|
||||
@@ -47,7 +47,8 @@ iD.actions.SplitWay = function(nodeId, newWayId) {
|
||||
j;
|
||||
|
||||
for (j = 0; j < relation.members.length; j++) {
|
||||
if (relation.members[j].type === 'way' && graph.entity(relation.members[j].id).contains(last)) {
|
||||
var entity = graph.entity(relation.members[j].id);
|
||||
if (entity && entity.type === 'way' && entity.contains(last)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -60,7 +61,7 @@ iD.actions.SplitWay = function(nodeId, newWayId) {
|
||||
return graph;
|
||||
};
|
||||
|
||||
action.permitted = function(graph) {
|
||||
action.enabled = function(graph) {
|
||||
return candidateWays(graph).length === 1;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//
|
||||
iD.actions.UnjoinNode = function(nodeId, newNodeId) {
|
||||
var action = function(graph) {
|
||||
if (!action.permitted(graph))
|
||||
if (!action.enabled(graph))
|
||||
return graph;
|
||||
|
||||
var node = graph.entity(nodeId);
|
||||
@@ -29,7 +29,7 @@ iD.actions.UnjoinNode = function(nodeId, newNodeId) {
|
||||
return graph;
|
||||
};
|
||||
|
||||
action.permitted = function(graph) {
|
||||
action.enabled = function(graph) {
|
||||
return graph.parentWays(graph.entity(nodeId)).length >= 2;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe("iD.actions.SplitWay", function () {
|
||||
describe("#permitted", function () {
|
||||
describe("#enabled", function () {
|
||||
it("returns true for a non-end node of a single way", function () {
|
||||
var graph = iD.Graph({
|
||||
'a': iD.Node({id: 'a'}),
|
||||
@@ -8,7 +8,7 @@ describe("iD.actions.SplitWay", function () {
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c']})
|
||||
});
|
||||
|
||||
expect(iD.actions.SplitWay('b').permitted(graph)).to.be.true;
|
||||
expect(iD.actions.SplitWay('b').enabled(graph)).to.be.true;
|
||||
});
|
||||
|
||||
it("returns false for the first node of a single way", function () {
|
||||
@@ -18,7 +18,7 @@ describe("iD.actions.SplitWay", function () {
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b']})
|
||||
});
|
||||
|
||||
expect(iD.actions.SplitWay('a').permitted(graph)).to.be.false;
|
||||
expect(iD.actions.SplitWay('a').enabled(graph)).to.be.false;
|
||||
});
|
||||
|
||||
it("returns false for the last node of a single way", function () {
|
||||
@@ -28,7 +28,7 @@ describe("iD.actions.SplitWay", function () {
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b']})
|
||||
});
|
||||
|
||||
expect(iD.actions.SplitWay('b').permitted(graph)).to.be.false;
|
||||
expect(iD.actions.SplitWay('b').enabled(graph)).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -175,6 +175,20 @@ describe("iD.actions.SplitWay", function () {
|
||||
expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['~', '=', '-']);
|
||||
});
|
||||
|
||||
it("handles incomplete relations", function () {
|
||||
var graph = iD.Graph({
|
||||
'a': iD.Node({id: 'a'}),
|
||||
'b': iD.Node({id: 'b'}),
|
||||
'c': iD.Node({id: 'c'}),
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
|
||||
'r': iD.Relation({id: 'r', members: [{id: '~', type: 'way'}, {id: '-', type: 'way'}]})
|
||||
});
|
||||
|
||||
graph = iD.actions.SplitWay('b', '=')(graph);
|
||||
|
||||
expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['~', '-', '=']);
|
||||
});
|
||||
|
||||
['restriction', 'restriction:bus'].forEach(function (type) {
|
||||
it("updates a restriction's 'from' role", function () {
|
||||
// Situation:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
describe("iD.actions.UnjoinNode", function () {
|
||||
describe("#permitted", function () {
|
||||
describe("#enabled", function () {
|
||||
it("returns false for a node shared by less than two ways", function () {
|
||||
var graph = iD.Graph({'a': iD.Node()});
|
||||
|
||||
expect(iD.actions.UnjoinNode('a').permitted(graph)).to.equal(false);
|
||||
expect(iD.actions.UnjoinNode('a').enabled(graph)).to.equal(false);
|
||||
});
|
||||
|
||||
it("returns true for a node shared by two or more ways", function () {
|
||||
@@ -19,7 +19,7 @@ describe("iD.actions.UnjoinNode", function () {
|
||||
'|': iD.Way({id: '|', nodes: ['d', 'b']})
|
||||
});
|
||||
|
||||
expect(iD.actions.UnjoinNode('b').permitted(graph)).to.equal(true);
|
||||
expect(iD.actions.UnjoinNode('b').enabled(graph)).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user