Skip to content

Commit

Permalink
Refactor code that detects .gltf and .glb automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Son-HNguyen committed Mar 31, 2020
1 parent 96c4e48 commit b8694d0
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions js/CitydbKmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,30 +1625,22 @@
entity.label = '';
entity.position = position;
entity.orientation = orientation;
entity.model = {
uri: checkExists(uri) ? uri : hostAndPath.concat("/", queryStringValue(linkNode, 'href', namespaces.kml).replace(".dae", ".glb").trim()),
asynchronous: false
};

function checkExists(url) {
checkExistsAux(url, function(status) {
if (status) {
return false;
}
return true;
// automatically check if the .gltf file is available
// if not, the extension shall be changed to .glb
new Cesium.Resource({url: uri}).fetch({responseType: 'json'})
.then(function (loadedData) {
entity.model = {
uri: uri,
asynchronous: false
};
})
.otherwise(function (error) {
entity.model = {
uri: uri.replace(".gltf", ".glb"),
asynchronous: false
};
});
}

function checkExistsAux(url, callback) {
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = () => {
if (xhr.status === 404) {
callback(xhr.status);
}
};
xhr.open('GET', url, true);
xhr.send();
}
}

var geometryTypes = {
Expand Down

0 comments on commit b8694d0

Please sign in to comment.