File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -29,15 +29,33 @@ class Building {
2929 type ;
3030 options ;
3131
32+ static async getRelationDataWithChildRelations ( id ) {
33+ const xmlData = new window . DOMParser ( ) . parseFromString ( await Building . getRelationData ( id ) , 'text/xml' ) ;
34+ await Promise . all ( Array . from ( xmlData . querySelectorAll ( 'member[type=relation]' ) ) . map ( async r => {
35+ const childId = r . getAttribute ( 'ref' ) ;
36+ if ( r . getAttribute ( 'id' ) === childId ) {
37+ return ;
38+ }
39+ const childData = new window . DOMParser ( ) . parseFromString ( await Building . getRelationData ( childId ) , 'text/xml' ) ;
40+ childData . querySelectorAll ( 'node, way, relation' ) . forEach ( i => {
41+ if ( xmlData . querySelector ( `${ i . tagName } [id="${ i . getAttribute ( 'id' ) } "]` ) ) {
42+ return ;
43+ }
44+ xmlData . querySelector ( 'osm' ) . appendChild ( i ) ;
45+ } ) ;
46+ } ) ) ;
47+ return new XMLSerializer ( ) . serializeToString ( xmlData ) ;
48+ }
49+
3250 /**
3351 * Create new building
3452 */
3553 static async create ( type , id ) {
36- var data ;
54+ let data ;
3755 if ( type === 'way' ) {
3856 data = await Building . getWayData ( id ) ;
3957 } else {
40- data = await Building . getRelationData ( id ) ;
58+ data = await Building . getRelationDataWithChildRelations ( id ) ;
4159 }
4260 let xmlData = new window . DOMParser ( ) . parseFromString ( data , 'text/xml' ) ;
4361 const nodelist = Building . buildNodeList ( xmlData ) ;
You can’t perform that action at this time.
0 commit comments