@@ -7,6 +7,21 @@ import {BuildingPart} from './buildingpart.js';
77 */
88class MultiBuildingPart extends BuildingPart {
99
10+ makeRings ( members ) {
11+ const ways = [ ] ;
12+ for ( let j = 0 ; j < members . length ; j ++ ) {
13+ const wayID = members [ j ] . getAttribute ( 'ref' ) ;
14+ const way = this . fullXmlData . getElementById ( wayID ) ;
15+ if ( way ) {
16+ ways . push ( way . cloneNode ( true ) ) ;
17+ } else {
18+ window . printError ( `Missing way ${ wayID } for relation ${ this . id } ` ) ;
19+ ways . push ( this . augmentedWays [ wayID ] . cloneNode ( true ) ) ;
20+ }
21+ }
22+ return BuildingShapeUtils . combineWays ( ways ) ;
23+ }
24+
1025 /**
1126 * Create the shape of the outer relation.
1227 *
@@ -16,27 +31,15 @@ class MultiBuildingPart extends BuildingPart {
1631 this . type = 'multipolygon' ;
1732 const innerMembers = this . way . querySelectorAll ( 'member[role="inner"][type="way"]' ) ;
1833 const outerMembers = this . way . querySelectorAll ( 'member[role="outer"][type="way"]' ) ;
19- const innerShapes = [ ] ;
20- var shapes = [ ] ;
21- for ( let i = 0 ; i < innerMembers . length ; i ++ ) {
22- const way = this . fullXmlData . getElementById ( innerMembers [ i ] . getAttribute ( 'ref' ) ) ;
23- innerShapes . push ( BuildingShapeUtils . createShape ( way , this . nodelist ) ) ;
24- }
25- const ways = [ ] ;
26- for ( let j = 0 ; j < outerMembers . length ; j ++ ) {
27- const way = this . fullXmlData . getElementById ( outerMembers [ j ] . getAttribute ( 'ref' ) ) ;
28- if ( way === null ) {
29- throw `Incompleted way ${ outerMembers [ j ] . getAttribute ( 'ref' ) } ` ;
30- }
31- ways . push ( way . cloneNode ( true ) ) ;
32- }
33- const closedWays = BuildingShapeUtils . combineWays ( ways ) ;
34- for ( let k = 0 ; k < closedWays . length ; k ++ ) {
35- const shape = BuildingShapeUtils . createShape ( closedWays [ k ] , this . nodelist ) ;
34+ const shapes = [ ] ;
35+ const innerShapes = this . makeRings ( innerMembers ) . map ( ring => BuildingShapeUtils . createShape ( ring , this . nodelist , this . augmentedNodelist ) ) ;
36+ const closedOuterWays = this . makeRings ( outerMembers ) ;
37+ for ( let k = 0 ; k < closedOuterWays . length ; k ++ ) {
38+ const shape = BuildingShapeUtils . createShape ( closedOuterWays [ k ] , this . nodelist , this . augmentedNodelist ) ;
3639 shape . holes . push ( ...innerShapes ) ;
3740 shapes . push ( shape ) ;
3841 }
39- if ( closedWays . length === 1 ) {
42+ if ( closedOuterWays . length === 1 ) {
4043 return shapes [ 0 ] ;
4144 }
4245 // Multiple outer members
0 commit comments