Handle multipolygon corner case when splitting (fixes #1799)

This commit is contained in:
John Firebaugh
2013-09-30 16:17:16 -07:00
parent 9b8d4771b0
commit 011dc140a3
2 changed files with 25 additions and 2 deletions
+9 -2
View File
@@ -29,7 +29,8 @@ iD.actions.Split = function(nodeId, newWayIds) {
var wayB = iD.Way({id: newWayId, tags: wayA.tags}),
nodesA,
nodesB,
isArea = wayA.isArea();
isArea = wayA.isArea(),
isOuter = iD.geo.isSimpleMultipolygonOuterMember(wayA, graph);
if (wayA.isClosed()) {
var nodes = wayA.nodes.slice(0, -1),
@@ -107,12 +108,18 @@ iD.actions.Split = function(nodeId, newWayIds) {
}
}
if (relation === isOuter) {
relation = relation.mergeTags(wayA.tags);
graph = graph.replace(wayA.update({tags: {}}));
graph = graph.replace(wayB.update({tags: {}}));
}
relation = relation.addMember({id: wayB.id, type: 'way', role: role}, i <= j ? i + 1 : i);
graph = graph.replace(relation);
}
});
if (isArea) {
if (!isOuter && isArea) {
var multipolygon = iD.Relation({
tags: _.extend({}, wayA.tags, {type: 'multipolygon'}),
members: [
+16
View File
@@ -398,6 +398,22 @@ describe("iD.actions.Split", function () {
expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['~', '-', '=']);
});
it("converts simple multipolygon to a proper multipolygon", 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'], tags: {natural: 'water'}}),
'r': iD.Relation({id: 'r', members: [{id: '-', type: 'way', role: 'outer'}], tags: {type: 'multipolygon'}})
});
graph = iD.actions.Split('b', ['='])(graph);
expect(graph.entity('-').tags).to.eql({});
expect(graph.entity('r').tags).to.eql({type: 'multipolygon', natural: 'water'});
expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['-', '=']);
});
['restriction', 'restriction:bus'].forEach(function (type) {
it("updates a restriction's 'from' role", function () {
// Situation: