Commit f971529d authored by Kolokolnikova's avatar Kolokolnikova
Browse files

-fixed access to local tilesetdata -added timeout for automatic local data...

-fixed access to local tilesetdata -added timeout for automatic local data fetching after 1sec -refactoring
parent 414317aa
...@@ -294,35 +294,29 @@ window.onclick = function (event) { ...@@ -294,35 +294,29 @@ window.onclick = function (event) {
var tileData = null; var tileData = null;
var tileset = null; var tileset = null;
var tilesetURL = 'http://vm24.fkc.hft-stuttgart.de:8081/CampusLOD2/CityModel/tileset.json'; var tilesetURL = 'http://vm24.fkc.hft-stuttgart.de:8081/CampusLOD2/CityModel/tileset.json';
var localTestTileset = '/3dclient4simstadtapi/public/test/tileset/gmlTileset_v1.json'; var localTestTileset = '/3dclient4simstadtapi/public/test/gmlTileset_v1.json';
const controller = new AbortController(); //used to abort the request when it takes too long function timeout(ms, promise) {
const timeoutId = setTimeout(() => controller.abort(), 3000); // 3 second timeout: return new Promise(function(resolve, reject) {
setTimeout(function() {
reject(new Error("timeout"))
}, ms)
promise.then(resolve, reject)
})
}
//fetching the tileset and handling the connection //fetching the tileset and handling the connection
async function fetchTileset(){ async function fetchTileset(){
timeout(1000, fetch(tilesetURL)).then((response)=>{
fetch(tilesetURL,{signal:controller.signal}).then((response)=>{ //fetch request with the abort controller
if(response.status >= 200 && response.status<=299){ //successful connection
//const tilesetJSON = response.json();
loadAndZoomToTileset(tilesetURL); loadAndZoomToTileset(tilesetURL);
swal({text:"",timer:100}); //used to remove the waiting alert }).catch((error)=>{ //catching the error(no connection)/ timeout and displaying an alert for the user
}else{ //var errorString = error["stack"]+"\n"+error["message"]; // formatting the error array
throw Error(response.statusText); //throwing an error when a connection is not possible swal({text:"Could not connect to Server. Using now: local data",icon:"info" } );
}
clearTimeout(timeoutId); //timeout the request
}).then((jsonResponse)=>{
console.log("Tileset"+jsonResponse);
}).catch((error)=>{ //catching the error and displaying an alert for the user
var errorString = error["stack"]+"\n"+error["message"]; // formatting the error array
swal("Could not connect to Server",errorString , "error");
console.log("Using local test data"); console.log("Using local test data");
loadAndZoomToTileset(localTestTileset); //TODO#3: fix the link so the local tileset can be loaded loadAndZoomToTileset(localTestTileset); //TODO#3: fix the link so the local tileset can be loaded
}) })
swal({text:"Connecting to Server ... Please wait !",icon:"info" ,buttons: false}); //displays waiting alert
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157183.4193600416, 671270.4825546426, 4774688.139831595, 209.53922537481412, 0, 0, 0, 127.40903120744042, 0, 0, 0, 159.76538479793817 ] "box" : [ 4157183.4193600416, 671270.4825546426, 4774688.139831595, 209.53922537481412, 0, 0, 0, 127.40903120744042, 0, 0, 0, 159.76538479793817 ]
}, },
"url" : "data/data0.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data0.b3dm"
}, },
"children" : [ "children" : [
{ {
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157259.0075245854, 671237.0161895597, 4774633.671508186, 58.3628962864168, 0, 0, 0, 60.476301041664556, 0, 0, 0, 50.82873797789216 ] "box" : [ 4157259.0075245854, 671237.0161895597, 4774633.671508186, 58.3628962864168, 0, 0, 0, 60.476301041664556, 0, 0, 0, 50.82873797789216 ]
}, },
"url" : "data/data1.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data1.b3dm"
} }
}, },
{ {
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157264.5454970878, 671264.7944576879, 4774639.053918136, 4.804305506404489, 0, 0, 0, 2.147513223113492, 0, 0, 0, 5.241957767866552 ] "box" : [ 4157264.5454970878, 671264.7944576879, 4774639.053918136, 4.804305506404489, 0, 0, 0, 2.147513223113492, 0, 0, 0, 5.241957767866552 ]
}, },
"url" : "data/data2.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data2.b3dm"
} }
}, },
{ {
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157271.7478251206, 671261.0646106068, 4774633.3457075525, 4.269025307614356, 0, 0, 0, 4.564049106091261, 0, 0, 0, 3.9737667804583907 ] "box" : [ 4157271.7478251206, 671261.0646106068, 4774633.3457075525, 4.269025307614356, 0, 0, 0, 4.564049106091261, 0, 0, 0, 3.9737667804583907 ]
}, },
"url" : "data/data3.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data3.b3dm"
} }
}, },
{ {
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157269.666790006, 671242.1711963416, 4774620.168381745, 18.48172607459128, 0, 0, 0, 15.025834774365649, 0, 0, 0, 18.37874110136181 ] "box" : [ 4157269.666790006, 671242.1711963416, 4774620.168381745, 18.48172607459128, 0, 0, 0, 15.025834774365649, 0, 0, 0, 18.37874110136181 ]
}, },
"url" : "data/data4.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data4.b3dm"
} }
}, },
{ {
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157260.68975647, 671264.3242054185, 4774624.871435814, 19.25886470079422, 0, 0, 0, 4.519255034159869, 0, 0, 0, 20.583400790579617 ] "box" : [ 4157260.68975647, 671264.3242054185, 4774624.871435814, 19.25886470079422, 0, 0, 0, 4.519255034159869, 0, 0, 0, 20.583400790579617 ]
}, },
"url" : "data/data5.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data5.b3dm"
} }
}, },
{ {
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157172.530755616, 671207.1977614365, 4774696.57353464, 138.71846980927512, 0, 0, 0, 114.54767946049105, 0, 0, 0, 116.25188143644482 ] "box" : [ 4157172.530755616, 671207.1977614365, 4774696.57353464, 138.71846980927512, 0, 0, 0, 114.54767946049105, 0, 0, 0, 116.25188143644482 ]
}, },
"url" : "data/data6.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data6.b3dm"
} }
}, },
{ {
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157214.173438959, 671345.0541383316, 4774655.342074862, 37.477705544326454, 0, 0, 0, 62.14529652846977, 0, 0, 0, 51.50954015459865 ] "box" : [ 4157214.173438959, 671345.0541383316, 4774655.342074862, 37.477705544326454, 0, 0, 0, 62.14529652846977, 0, 0, 0, 51.50954015459865 ]
}, },
"url" : "data/data7.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data7.b3dm"
} }
}, },
{ {
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157182.683947933, 671336.9473289275, 4774687.03334116, 11.211912735830992, 0, 0, 0, 12.544089487171732, 0, 0, 0, 4.31426614522934 ] "box" : [ 4157182.683947933, 671336.9473289275, 4774687.03334116, 11.211912735830992, 0, 0, 0, 12.544089487171732, 0, 0, 0, 4.31426614522934 ]
}, },
"url" : "data/data8.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data8.b3dm"
} }
}, },
{ {
...@@ -127,7 +127,7 @@ ...@@ -127,7 +127,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157181.173513483, 671326.7337885841, 4774674.725270944, 33.30119850020856, 0, 0, 0, 32.9711701736087, 0, 0, 0, 28.930406578816473 ] "box" : [ 4157181.173513483, 671326.7337885841, 4774674.725270944, 33.30119850020856, 0, 0, 0, 32.9711701736087, 0, 0, 0, 28.930406578816473 ]
}, },
"url" : "data/data9.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data9.b3dm"
} }
}, },
{ {
...@@ -139,7 +139,7 @@ ...@@ -139,7 +139,7 @@
"boundingVolume" : { "boundingVolume" : {
"box" : [ 4157193.1721887705, 671343.1874950465, 4774659.388889508, 57.298549075610936, 0, 0, 0, 65.87858309841249, 0, 0, 0, 59.603169448673725 ] "box" : [ 4157193.1721887705, 671343.1874950465, 4774659.388889508, 57.298549075610936, 0, 0, 0, 65.87858309841249, 0, 0, 0, 59.603169448673725 ]
}, },
"url" : "data/data10.b3dm" "url" : "/3dclient4simstadtapi/public/test/tileset/data/data10.b3dm"
} }
} }
] ]
......
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