From 37365f2e1026e18151f8efcdba90794adfe5800e Mon Sep 17 00:00:00 2001 From: Daria Kolokolnikova <72koda1bif@hft-stuttgart.de> Date: Wed, 12 Jan 2022 00:13:30 +0100 Subject: [PATCH] deleted unnecessary code --- public/js/connectToAPI.js | 48 +++++++++------------------------------ 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/public/js/connectToAPI.js b/public/js/connectToAPI.js index 00d6c01..6ce1202 100644 --- a/public/js/connectToAPI.js +++ b/public/js/connectToAPI.js @@ -132,32 +132,26 @@ async function getLocalShadowdata() { } async function processData() { - console.log("Waiting for data....") shadowdata = await getLocalShadowdata() - - timeout(25000, getLocalShadowdata()).then((response) => { - //console.log(response) + + //waiting 25sec for the shadowData fetch from server: catching error if no answer in 25sec + timeout(25000, fetchshadowDataJSON()).then((response) => { shadowdata = response; }).catch((error) => { //catching the error(no connection)/ timeout and displaying an alert for the user console.log(shadowdata); - //loadLocalAPIshadowData here... }) timeout(10000, fetchPvPotentialJSON()).then((response) => { - //console.log("fetchPvPotentialJSON:", response); pvPotentialSurfaces = getPvPotentialOfSurfaces(response["buildings"]); - //console.log("pvPotentialSurfaces:",pvPotentialSurfaces); }).catch((error) => { console.log(error) }) - timeout(10000, fetchDataJSON()).then((response) => { calculateData(response); }).catch((error) => { console.log(error) - fetch(localPvpotentialData) .then(response => response.text()) .then(text => calculateData(JSON.parse(text))) @@ -166,15 +160,11 @@ async function processData() { function calculateData(data) { - //console.log(data); document.getElementById("cesiumContainer").style.opacity = "1"; document.getElementById("loader").style.visibility = "hidden" console.log("....received data") - var buildingsMAP = new Map() - data.buildings.forEach(bu => { - var partsArray = [] var surefacesArray = [] @@ -196,7 +186,6 @@ function calculateData(data) { p.attributes.roofType))) buildingsMAP.set(bu.id, new Building(bu.id, partsArray)) //puts buildings with parts and surfaces in a map - }) var partHeightMAP = new Map() @@ -389,10 +378,7 @@ window.onclick = function(event) { //------------------------------------------------------------------------------- var tileData = null; var tileset = null; -//var tilesetURL = 'http://vm24.fkc.hft-stuttgart.de:8081/CampusLOD2Old/tileset.json'; var tilesetURL = 'http://vm24.fkc.hft-stuttgart.de:8081/CampusLOD2/tileset.json'; - -//var localTestTileset = '/3dclient4simstadtapi/public/test/gmlTileset_v1.json'; var localTestTileset = getAbsoulteTestPath("/test/gmlTileset_v1.json"); @@ -406,31 +392,29 @@ function timeout(ms, promise) { } //getting the pvPotential of all surfaces from the pvPotential array, which the api returns -function getPvPotentialOfSurfaces(pvPotentialarray){ - var pvPotentialArray=[]; +function getPvPotentialOfSurfaces(pvPotentialarray) { + var pvPotentialArray = []; pvPotentialarray.forEach( - building => building["parts"].forEach( + building => building["parts"].forEach( parts => parts["surfaces"].forEach( surface => pvPotentialArray.push(surface) - //console.log(surface) - ) - ) + ) + ) ); - //console.log(pvPotentialArray); return pvPotentialArray; } //fetching the tileset and handling the connection +//waiting 1sec for the tileSetData fetch from server: catching error if no answer in 1sec function fetchTileset() { timeout(1000, fetch(tilesetURL)).then((response) => { loadAndZoomToTileset(tilesetURL); }).catch((error) => { //catching the error(no connection)/ timeout and displaying an alert for the user - //var errorString = error["stack"]+"\n"+error["message"]; // formatting the error array swal({ text: "Could not connect to Server. Using now: local data", icon: "info" }); console.log("Using local test data"); - loadAndZoomToTileset(localTestTileset); + loadAndZoomToTileset(localTestTileset); }) } @@ -450,18 +434,15 @@ function loadTileset() { viewer.scene.primitives.remove(tileset); tileContent = []; modal.style.display = "block"; - fetchTileset(); - - //var userurl = document.getElementById("3Durl").value; //returns the chosen area from the dropdown } + //loads the tileset from the url into the cesium viewer and zooms to it function loadAndZoomToTileset(url) { tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ url: url })); - viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0, -0.5, 0)); modal.style.display = "none"; saveTilesetContent(tileset) @@ -476,9 +457,7 @@ function useContent(content) { element.value = cont.title element.value = cont.title element.name = "individualTileset" - document.getElementById("myList").appendChild(element); - element.onclick = function() { tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ url: cont.href @@ -504,7 +483,6 @@ function saveTilesetContent(tileset) { function deleteTilesetButtons() { var x = document.getElementsByName("individualTileset") var len = x.length - //checking if there are even tileset to delete if (x.length > 0) { parentNode = x[0].parentNode; @@ -512,7 +490,6 @@ function deleteTilesetButtons() { parentNode.removeChild(x[0]); } } - } //expects path to test data, from the 'public' folder as origin @@ -523,11 +500,8 @@ function getAbsoulteTestPath(testdataPath) { a.reverse(); a.pop(); a.reverse() - var path = ""; a.forEach(element => path += "/" + element); - var path = window.location.origin + "/" + path + testdataPath; - return path; } -- GitLab