From 011dc140a31faccb9f5a6ac2c7fab43de9553322 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 30 Sep 2013 16:17:16 -0700 Subject: [PATCH] Handle multipolygon corner case when splitting (fixes #1799) --- js/id/actions/split.js | 11 +++++++++-- test/spec/actions/split.js | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/js/id/actions/split.js b/js/id/actions/split.js index be1a9153f..b34395b9e 100644 --- a/js/id/actions/split.js +++ b/js/id/actions/split.js @@ -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: [ diff --git a/test/spec/actions/split.js b/test/spec/actions/split.js index 1f24dc8a1..39f326b4c 100644 --- a/test/spec/actions/split.js +++ b/test/spec/actions/split.js @@ -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: