From 8dbb6eb20c022a185182e31d85b34dd3d186eb14 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Sat, 13 Jan 2018 01:45:46 -0500 Subject: [PATCH] Return reversal actions performed by osmJoinWays (see #4688) --- modules/osm/multipolygon.js | 63 ++++------------------------------- test/spec/osm/multipolygon.js | 12 ++++++- 2 files changed, 17 insertions(+), 58 deletions(-) diff --git a/modules/osm/multipolygon.js b/modules/osm/multipolygon.js index 92ed38a22..2292f65f3 100644 --- a/modules/osm/multipolygon.js +++ b/modules/osm/multipolygon.js @@ -1,5 +1,6 @@ import { actionReverse } from '../actions/reverse'; import { osmIsInterestingTag } from './tags'; +import { osmWay } from './way'; // For fixing up rendering of multipolygons with tags on the outer member. @@ -87,8 +88,10 @@ export function osmJoinWays(toJoin, graph) { return graph.childNodes(graph.entity(member.id)); } - function reverse(member) { - return member.tags ? actionReverse(member.id, { reverseOneway: true })(graph).entity(member.id) : member; + function reverse(which) { + var action = actionReverse(which.id, { reverseOneway: true }); + sequences.actions.push(action); + return (which instanceof osmWay) ? action(graph).entity(which.id) : which; } @@ -98,6 +101,7 @@ export function osmJoinWays(toJoin, graph) { }); var sequences = []; + sequences.actions = []; while (toJoin.length) { // start a new sequence @@ -173,59 +177,4 @@ export function osmJoinWays(toJoin, graph) { } return sequences; - - - // var joined = []; - - // while (array.length) { - // var member = array.shift(); - // var current = [member]; - // var nodes = resolve(member).slice(); - - // current.nodes = nodes; - // joined.push(current); - - // while (array.length && nodes[0] !== nodes[nodes.length - 1]) { - // var first = nodes[0]; - // var last = nodes[nodes.length - 1]; - // var how, what, i; - - // for (i = 0; i < array.length; i++) { - // member = array[i]; - // what = resolve(member); - - // if (last === what[0]) { - // how = nodes.push; - // what = what.slice(1); - // break; - // } else if (last === what[what.length - 1]) { - // how = nodes.push; - // what = what.slice(0, -1).reverse(); - // member = reverse(member); - // break; - // } else if (first === what[what.length - 1]) { - // how = nodes.unshift; - // what = what.slice(0, -1); - // break; - // } else if (first === what[0]) { - // how = nodes.unshift; - // what = what.slice(1).reverse(); - // member = reverse(member); - // break; - // } else { - // what = how = null; - // } - // } - - // if (!what) - // break; // No more joinable ways. - - // how.apply(current, [member]); - // how.apply(nodes, what); - - // array.splice(i, 1); - // } - // } - - // return joined; } diff --git a/test/spec/osm/multipolygon.js b/test/spec/osm/multipolygon.js index 6f5211ab7..1cb467d72 100644 --- a/test/spec/osm/multipolygon.js +++ b/test/spec/osm/multipolygon.js @@ -158,6 +158,7 @@ describe('iD.osmJoinWays', function() { var result = iD.osmJoinWays([member], graph); expect(result.length).to.equal(1); + expect(result.actions).to.eql([]); expect(getIDs(result[0].nodes)).to.eql(['a']); expect(result[0].length).to.equal(1); expect(result[0][0]).to.eql(member); @@ -176,6 +177,7 @@ describe('iD.osmJoinWays', function() { var result = iD.osmJoinWays([w1, w2], graph); expect(result.length).to.equal(1); + expect(result.actions).to.eql([]); expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']); expect(result[0].length).to.equal(2); expect(result[0][0]).to.eql(w1); @@ -200,6 +202,7 @@ describe('iD.osmJoinWays', function() { var result = iD.osmJoinWays(r.members, graph); expect(result.length).to.equal(1); + expect(result.actions).to.eql([]); expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']); expect(result[0].length).to.equal(2); expect(result[0][0]).to.eql({id: '-', type: 'way'}); @@ -227,6 +230,7 @@ describe('iD.osmJoinWays', function() { var result = iD.osmJoinWays(r.members, graph); expect(result.length).to.equal(1); + expect(result.actions.length).to.equal(1); expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c', 'd']); expect(result[0].length).to.equal(3); expect(result[0][0]).to.eql({id: '=', type: 'way'}); @@ -250,6 +254,7 @@ describe('iD.osmJoinWays', function() { var result = iD.osmJoinWays([w1, w2], graph); expect(result.length).to.equal(1); + expect(result.actions.length).to.equal(1); expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']); expect(result[0].length).to.equal(2); expect(result[0][0]).to.eql(w1); @@ -274,6 +279,7 @@ describe('iD.osmJoinWays', function() { var result = iD.osmJoinWays([w1, w2], graph); expect(result.length).to.equal(1); + expect(result.actions.length).to.equal(1); expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']); expect(result[0].length).to.equal(2); expect(result[0][0]).to.be.an.instanceof(iD.osmWay); @@ -317,6 +323,7 @@ describe('iD.osmJoinWays', function() { var result = iD.osmJoinWays([w1, w2, w3, w4], graph); expect(result.length).to.equal(2); + expect(result.actions).to.eql([]); expect(result[0].length).to.equal(2); expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']); @@ -357,6 +364,7 @@ describe('iD.osmJoinWays', function() { var result = iD.osmJoinWays(r.members, graph); expect(result.length).to.equal(2); + expect(result.actions).to.eql([]); expect(result[0].length).to.equal(2); expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c']); @@ -399,7 +407,9 @@ describe('iD.osmJoinWays', function() { var graph = iD.coreGraph([a, b, c, d, e, w1, w2, w3, w4, w5, r]); var result = iD.osmJoinWays(r.members, graph); - expect(result.length).to.equal(1); + expect(result.length).to.equal(3); + expect(result.actions.length).to.equal(1); + expect(getIDs(result[0].nodes)).to.eql(['a', 'b', 'c', 'd', 'e', 'c', 'b', 'a']); expect(result[0].length).to.equal(7); expect(result[0][0]).to.eql({id: '=', type: 'way'});