Skip to content

Commit 764f0ac

Browse files
authored
Update BuildingShapeUtils.js
1 parent 24b48e9 commit 764f0ac

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/extras/BuildingShapeUtils.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ class BuildingShapeUtils extends ShapeUtils {
178178
usedWays.add(wayID);
179179
const result = tryMakeRing([w]);
180180
if (result.length) {
181-
let ring = result[0];
182-
result.slice(1).forEach(w => {
183-
ring = this.joinWays(ring, w);
184-
});
181+
ring = this.joinAllWays(result)
185182
closedWays.push(ring);
186183
}
187184
});
@@ -203,11 +200,28 @@ class BuildingShapeUtils extends ShapeUtils {
203200
*/
204201
static joinWays(way1, way2) {
205202
const elements = way2.getElementsByTagName('nd');
203+
const newWay = way1.cloneNode(true);
206204
for (let i = 1; i < elements.length; i++) {
207205
let elem = elements[i].cloneNode();
208-
way1.appendChild(elem);
206+
newWay.appendChild(elem);
209207
}
210-
return way1;
208+
return newWay;
209+
}
210+
211+
/**
212+
* Append the nodes from one way into another.
213+
*
214+
* @param {DOM.Element} way1 - an open, non self-intersecring way
215+
* @param {DOM.Element} way2
216+
*
217+
* @return {DOM.Element} way
218+
*/
219+
static joinAllWays(ways) {
220+
let way = ways[0];
221+
ways.slice(1).forEach(w => {
222+
way = this.joinWays(way, w);
223+
});
224+
return way;
211225
}
212226

213227
/**

0 commit comments

Comments
 (0)