diff --git a/js/id/actions/merge_polygon.js b/js/id/actions/merge_polygon.js index 4ffde0e4c..6dda35581 100644 --- a/js/id/actions/merge_polygon.js +++ b/js/id/actions/merge_polygon.js @@ -86,10 +86,15 @@ iD.actions.MergePolygon = function(ids, newRelationId) { graph = graph.remove(m); }); - members.forEach(function(m) { - var entity = graph.entity(m.id); - relation = relation.mergeTags(entity.tags); - graph = graph.replace(entity.update({ tags: {} })); + entities.closedWay.forEach(function(cw) { + function isThisOuter(m) { + return m.id === cw.id && m.role !== "inner"; + } + if (members.some(isThisOuter)) { + var entity = graph.entity(cw.id); + relation = relation.mergeTags(entity.tags); + graph = graph.replace(entity.update({ tags: {} })); + } }); return graph.replace(relation.update({ diff --git a/test/spec/actions/merge_polygon.js b/test/spec/actions/merge_polygon.js index 5270ce29f..85ac68f8e 100644 --- a/test/spec/actions/merge_polygon.js +++ b/test/spec/actions/merge_polygon.js @@ -85,15 +85,20 @@ describe("iD.actions.MergePolygon", function () { expect(find(r, 'w5').role).to.equal('outer'); }); - it("moves all tags to the relation", function() { + it("moves tags to the relation", function() { graph = graph.replace(graph.entity('w0').update({ tags: { 'building': 'yes' }})); + // this is a new inner member whose tags should not be moved to the relation graph = graph.replace(graph.entity('w1').update({ tags: { 'natural': 'water' }})); - graph = iD.actions.MergePolygon(['w0', 'w1'], 'r')(graph); + // this is a new outer member whose tags should be moved to the relation + graph = graph.replace(graph.entity('w5').update({ tags: { 'amenity': 'school' }})); + graph = iD.actions.MergePolygon(['w0', 'w1','w5'], 'r')(graph); var r = graph.entity('r'); expect(graph.entity('w0').tags.building).to.equal(undefined); - expect(graph.entity('w1').tags.natural).to.equal(undefined); - expect(r.tags.natural).to.equal('water'); + expect(graph.entity('w1').tags.natural).to.equal('water'); + expect(graph.entity('w5').tags.amenity).to.equal(undefined); expect(r.tags.building).to.equal('yes'); + expect(r.tags.natural).to.equal(undefined); + expect(r.tags.amenity).to.equal('school'); }); it("doesn't copy area tags from ways", function() {