Commit 0258c397 authored by Kolokolnikova's avatar Kolokolnikova
Browse files

-refactoring

-local api data (buildinginformation) can be loaded
parent 2c28ad89
Showing with 161 additions and 153 deletions
+161 -153
...@@ -110,174 +110,182 @@ function processData() { ...@@ -110,174 +110,182 @@ function processData() {
fetchDataJSON().then(data => { fetchDataJSON().then(data => {
console.log(data); calculateData(data);
document.getElementById("cesiumContainer").style.opacity = "1"; }).catch(() => {
document.getElementById("loader").style.visibility = "hidden" console.log("wird nix")
console.log("....received data") fetch("/3dclient4simstadtapi/public/test/APIdata/buildingInformation.json")
.then(response => response.text())
.then(text => calculateData( JSON.parse(text)))
})
}
var buildingsMAP = new Map()
data.buildings.forEach(bu => {
var partsArray = [] function calculateData(data){
var surefacesArray = [] console.log(data);
document.getElementById("cesiumContainer").style.opacity = "1";
document.getElementById("loader").style.visibility = "hidden"
console.log("....received data")
bu.parts.forEach(p => var buildingsMAP = new Map()
p.surfaces.forEach(s =>
surefacesArray.push(new Surface(s.id,
s.attributes.uValue,
s.attributes.totalSurfaceArea))))
bu.parts.forEach(p => partsArray.push(new Part(p.id, data.buildings.forEach(bu => {
surefacesArray,
p.attributes.volume,
p.attributes.height,
p.attributes.heatedVolume,
p.attributes.yearOfConstruction,
p.attributes.buildingFunction,
p.attributes.monthlyHeating,
p.attributes.monthlyCooling,
p.attributes.roofType)))
buildingsMAP.set(bu.id, new Building(bu.id, partsArray)) //puts buildings with parts and surfaces in a map var partsArray = []
var surefacesArray = []
}) bu.parts.forEach(p =>
p.surfaces.forEach(s =>
surefacesArray.push(new Surface(s.id,
s.attributes.uValue,
s.attributes.totalSurfaceArea))))
var partHeightMAP = new Map() bu.parts.forEach(p => partsArray.push(new Part(p.id,
var partVolumeMAP = new Map() surefacesArray,
var partHeatedVolumeMAP = new Map() p.attributes.volume,
var partConstructionYearMAP = new Map() p.attributes.height,
var partBuildingTypeMAP = new Map() p.attributes.heatedVolume,
var partMonthlyHeatingMAP = new Map() p.attributes.yearOfConstruction,
var partMonthlyCoolingMAP = new Map() p.attributes.buildingFunction,
var surfaceUValueMAP = new Map() p.attributes.monthlyHeating,
var partRoofTypeMAP = new Map() p.attributes.monthlyCooling,
var surfaceTotalSurfaceAreaMAP = new Map() p.attributes.roofType)))
//fill height, heated volume and construction year map buildingsMAP.set(bu.id, new Building(bu.id, partsArray)) //puts buildings with parts and surfaces in a map
buildingsMAP.forEach(b => {
b.parts.forEach(part => { })
if (part.height !== undefined) {
partHeightMAP.set(part.id, part.height) var partHeightMAP = new Map()
} var partVolumeMAP = new Map()
if (part.volume !== undefined) { var partHeatedVolumeMAP = new Map()
partVolumeMAP.set(part.id, part.volume) var partConstructionYearMAP = new Map()
} var partBuildingTypeMAP = new Map()
if (part.heatedVolume !== undefined) { var partMonthlyHeatingMAP = new Map()
partHeatedVolumeMAP.set(part.id, part.heatedVolume) var partMonthlyCoolingMAP = new Map()
} var surfaceUValueMAP = new Map()
if (part.yearOfConstruction !== undefined && part.yearOfConstruction <= "2020") { var partRoofTypeMAP = new Map()
partConstructionYearMAP.set(part.id, part.yearOfConstruction) var surfaceTotalSurfaceAreaMAP = new Map()
}
if (part.buildingFunction !== undefined) { //fill height, heated volume and construction year map
partBuildingTypeMAP.set(part.id, part.buildingFunction) buildingsMAP.forEach(b => {
} b.parts.forEach(part => {
if (part.monthlyHeating !== undefined) { if (part.height !== undefined) {
partMonthlyHeatingMAP.set(part.id, part.monthlyHeating) partHeightMAP.set(part.id, part.height)
} }
if (part.monthlyCooling !== undefined) { if (part.volume !== undefined) {
partMonthlyCoolingMAP.set(part.id, part.monthlyCooling) partVolumeMAP.set(part.id, part.volume)
} }
if (part.roofType !== undefined) { if (part.heatedVolume !== undefined) {
partRoofTypeMAP.set(part.id, part.roofType) partHeatedVolumeMAP.set(part.id, part.heatedVolume)
}
if (part.yearOfConstruction !== undefined && part.yearOfConstruction <= "2020") {
partConstructionYearMAP.set(part.id, part.yearOfConstruction)
}
if (part.buildingFunction !== undefined) {
partBuildingTypeMAP.set(part.id, part.buildingFunction)
}
if (part.monthlyHeating !== undefined) {
partMonthlyHeatingMAP.set(part.id, part.monthlyHeating)
}
if (part.monthlyCooling !== undefined) {
partMonthlyCoolingMAP.set(part.id, part.monthlyCooling)
}
if (part.roofType !== undefined) {
partRoofTypeMAP.set(part.id, part.roofType)
}
part.surfaces.forEach(s => {
if (s.uValue !== undefined) {
surfaceUValueMAP.set(s.id, s.uValue)
} }
part.surfaces.forEach(s => {
if (s.uValue !== undefined) {
surfaceUValueMAP.set(s.id, s.uValue)
}
})
//totalSurfaceArea
surfaceTotalSurfaceAreaMAP.set(part.id, part.surfaces)
}) })
//totalSurfaceArea
surfaceTotalSurfaceAreaMAP.set(part.id, part.surfaces)
}) })
})
//sort maps //sort maps
const heightSort = new Map([...partHeightMAP.entries()].sort((a, b) => b[1] - a[1])); const heightSort = new Map([...partHeightMAP.entries()].sort((a, b) => b[1] - a[1]));
const heatedVolumeSort = new Map([...partHeatedVolumeMAP.entries()].sort((a, b) => b[1] - a[1])); const heatedVolumeSort = new Map([...partHeatedVolumeMAP.entries()].sort((a, b) => b[1] - a[1]));
const constructionYearSort = new Map([...partConstructionYearMAP.entries()].sort((a, b) => a[1] - b[1])); const constructionYearSort = new Map([...partConstructionYearMAP.entries()].sort((a, b) => a[1] - b[1]));
const uValueSort = new Map([...surfaceUValueMAP.entries()].sort((a, b) => b[1] - a[1])); const uValueSort = new Map([...surfaceUValueMAP.entries()].sort((a, b) => b[1] - a[1]));
//for Properties Single Buildings //for Properties Single Buildings
buildingFunctionSortPick = new Map([...partBuildingTypeMAP.entries()].sort((a, b) => b[1] - a[1])); buildingFunctionSortPick = new Map([...partBuildingTypeMAP.entries()].sort((a, b) => b[1] - a[1]));
constructionYearSortPick = new Map([...partConstructionYearMAP.entries()].sort((a, b) => a[1] - b[1])); constructionYearSortPick = new Map([...partConstructionYearMAP.entries()].sort((a, b) => a[1] - b[1]));
heightSortPick = new Map([...partHeightMAP.entries()].sort((a, b) => b[1] - a[1])); heightSortPick = new Map([...partHeightMAP.entries()].sort((a, b) => b[1] - a[1]));
heatedVolumeSortPick = new Map([...partHeatedVolumeMAP.entries()].sort((a, b) => b[1] - a[1])); heatedVolumeSortPick = new Map([...partHeatedVolumeMAP.entries()].sort((a, b) => b[1] - a[1]));
totalSurfaceAreaSortPick = new Map([...surfaceTotalSurfaceAreaMAP.entries()].sort((a, b) => b[1] - a[1])); totalSurfaceAreaSortPick = new Map([...surfaceTotalSurfaceAreaMAP.entries()].sort((a, b) => b[1] - a[1]));
roofTypeSortPick = new Map([...partRoofTypeMAP.entries()].sort((a, b) => b[1] - a[1])); roofTypeSortPick = new Map([...partRoofTypeMAP.entries()].sort((a, b) => b[1] - a[1]));
uValueSortPick = new Map([...surfaceUValueMAP.entries()].sort((a, b) => b[1] - a[1])); uValueSortPick = new Map([...surfaceUValueMAP.entries()].sort((a, b) => b[1] - a[1]));
//fill arrays needed for charts //fill arrays needed for charts
heightSort.forEach((value, key) => addHeightInfosToArrays(key, value)) heightSort.forEach((value, key) => addHeightInfosToArrays(key, value))
heatedVolumeSort.forEach((value, key) => addHeatedVolumeInfosToArrays(key, value)) heatedVolumeSort.forEach((value, key) => addHeatedVolumeInfosToArrays(key, value))
constructionYearSort.forEach((value) => yearOfConstructionValues.push(value)) constructionYearSort.forEach((value) => yearOfConstructionValues.push(value))
partBuildingTypeMAP.forEach((value) => buildingTypeValues.push(value)) partBuildingTypeMAP.forEach((value) => buildingTypeValues.push(value))
partMonthlyHeatingMAP.forEach((valueArray, key) => yearlyHeatingDemand(key, valueArray)) partMonthlyHeatingMAP.forEach((valueArray, key) => yearlyHeatingDemand(key, valueArray))
partMonthlyCoolingMAP.forEach((valueArray, key) => yearlyCoolingDemand(key, valueArray)) partMonthlyCoolingMAP.forEach((valueArray, key) => yearlyCoolingDemand(key, valueArray))
uValueSort.forEach((value, key) => { uValueSort.forEach((value, key) => {
uValueSurfaces(key, value) uValueSurfaces(key, value)
uValuesAll.push(value) uValuesAll.push(value)
}) })
partMonthlyHeatingMAP.forEach((value, key) => addmonthlyHeatingInfosToArrays(key, value)) partMonthlyHeatingMAP.forEach((value, key) => addmonthlyHeatingInfosToArrays(key, value))
partMonthlyCoolingMAP.forEach((value, key) => addmonthlyCoolingInfosToArrays(key, value)) partMonthlyCoolingMAP.forEach((value, key) => addmonthlyCoolingInfosToArrays(key, value))
partVolumeMAP.forEach((value, key) => addVolumeValues(key, value)) partVolumeMAP.forEach((value, key) => addVolumeValues(key, value))
//calculates year of construction frequency
yearFrequency()
//calculates building type frequency
buildingTypeFrequency()
//calculates uValue frequency
uValueFrequency()
//sorts yearly heating & cooling demand for charts
sortMap()
//disables attributes in chart without values
availableAttributes()
//color buildings with heating demand
document.getElementById("checkbox2").addEventListener("change", function () {
if (this.checked) {
tileContent.forEach(t => {
let tileID = t.getProperty("gml_parent_id")
let tileColor = heatingIDColorMAP.get(tileID)
if (tileColor !== undefined) {
t.color = Cesium.Color.fromCssColorString(tileColor)
} else {
t.color = new Cesium.Color(1, 1, 1, 1)
}
})
console.log("colored")
} else {
tileContent.forEach(t => t.color = new Cesium.Color(1, 1, 1, 1))
console.log("not colored")
}
})
//color surfaces with uValue //calculates year of construction frequency
document.getElementById("checkbox1").addEventListener("change", function () { yearFrequency()
if (this.checked) {
tileContent.forEach(t => { //calculates building type frequency
let tileID = t.getProperty("gml_id") buildingTypeFrequency()
let tileColor = surfaceIDColorMAP.get(tileID)
if (tileColor !== undefined) { //calculates uValue frequency
t.color = Cesium.Color.fromCssColorString(tileColor) uValueFrequency()
} else {
t.color = new Cesium.Color(1, 1, 1, 1)
}
})
console.log("colored")
} else {
tileContent.forEach(t => t.color = new Cesium.Color(1, 1, 1, 1))
console.log("not colored")
}
})
}).catch((err) => { //sorts yearly heating & cooling demand for charts
console.log(err) sortMap()
//disables attributes in chart without values
availableAttributes()
//color buildings with heating demand
document.getElementById("checkbox2").addEventListener("change", function () {
if (this.checked) {
tileContent.forEach(t => {
let tileID = t.getProperty("gml_parent_id")
let tileColor = heatingIDColorMAP.get(tileID)
if (tileColor !== undefined) {
t.color = Cesium.Color.fromCssColorString(tileColor)
} else {
t.color = new Cesium.Color(1, 1, 1, 1)
}
})
console.log("colored")
} else {
tileContent.forEach(t => t.color = new Cesium.Color(1, 1, 1, 1))
console.log("not colored")
}
})
//color surfaces with uValue
document.getElementById("checkbox1").addEventListener("change", function () {
if (this.checked) {
tileContent.forEach(t => {
let tileID = t.getProperty("gml_id")
let tileColor = surfaceIDColorMAP.get(tileID)
if (tileColor !== undefined) {
t.color = Cesium.Color.fromCssColorString(tileColor)
} else {
t.color = new Cesium.Color(1, 1, 1, 1)
}
})
console.log("colored")
} else {
tileContent.forEach(t => t.color = new Cesium.Color(1, 1, 1, 1))
console.log("not colored")
}
}) })
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment