Skip to content

Commit

Permalink
Create buildingfactory.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Beakerboy authored May 16, 2024
1 parent b87b26c commit ab03489
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/buildingfactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {BuildingShapeUtils} from './extras/BuildingShapeUtils.js';
import {Building} from './building.js';
import {MultiBuildingPart} from './multibuildingpart.js';
/**
* A class representing an OSM building
*
* The static factory is responsible for pulling all required
* XML data from the API.
*/
class BuildingFactory {

/**
* Create new building
*/
static async createWay(id) {
var data = await Building.getRelationData(id);
let xmlData = new window.DOMParser().parseFromString(data, 'text/xml');
const nodelist = Building.buildNodeList(xmlData);
const extents = Building.getExtents(id, xmlData, nodelist);
const innerData = await Building.getInnerData(...extents);
return new MultiBuilding(id, innerData);
}

static async createRelation(id) {
var data = await Building.getRelationData(id);
let xmlData = new window.DOMParser().parseFromString(data, 'text/xml');
const nodelist = Building.buildNodeList(xmlData);
const extents = Building.getExtents(id, xmlData, nodelist);
const innerData = await Building.getInnerData(...extents);
const fullXmlData = new window.DOMParser().parseFromString(innerData, 'text/xml');
const outerElementXml = this.fullXmlData.getElementById(id);
if (outerElementXml.querySelector('[k="type"]').getAttribute('v') === 'multipolygon') {
return new MultiBuilding(id, innerData);
}
return new RelationBuilding(id, innerData);
}
}

0 comments on commit ab03489

Please sign in to comment.