Skip to content

Commit

Permalink
Merge pull request #5685 from jason-crow/master
Browse files Browse the repository at this point in the history
Add static loadJson method to Cesium3DTileset
  • Loading branch information
lilleyse authored Aug 11, 2017
2 parents 5c8752d + c398fc2 commit 48ff4ba
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ define([
var that = this;

// We don't know the distance of the tileset until tileset.json is loaded, so use the default distance for now
loadJson(tilesetUrl).then(function(tilesetJson) {
Cesium3DTileset.loadJson(tilesetUrl).then(function(tilesetJson) {
that._root = that.loadTileset(tilesetUrl, tilesetJson);
var gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis) ? Axis.fromName(tilesetJson.asset.gltfUpAxis) : Axis.Y;
that._asset = tilesetJson.asset;
Expand Down Expand Up @@ -1048,6 +1048,16 @@ define([
}
});

/**
* Provides a hook to override the method used to request the tileset json
* useful when fetching tilesets from remote servers
* @param {String} tilesetUrl The url of the json file to be fetched
* @returns {Promise.<Object>} A promise that resolves with the fetched json data
*/
Cesium3DTileset.loadJson = function(tilesetUrl) {
return loadJson(tilesetUrl);
};

/**
* Marks the tileset's {@link Cesium3DTileset#style} as dirty, which forces all
* features to re-evaluate the style in the next frame each is visible.
Expand Down
43 changes: 42 additions & 1 deletion Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,48 @@ defineSuite([
});
});

it('rejects readyPromise with invalid tileset version', function() {
it('loads json with static loadJson method', function() {
var tilesetJson = {
asset : {
version : 2.0
}
};

var uri = 'data:text/plain;base64,' + btoa(JSON.stringify(tilesetJson));

Cesium3DTileset.loadJson(uri).then(function(result) {
expect(result).toEqual(tilesetJson);
}).otherwise(function(error) {
fail('should not fail');
});
});

it('static method loadJson is used in Cesium3DTileset constructor', function() {
var path = './Data/Cesium3DTiles/Tilesets/TilesetOfTilesets/tileset.json';

var originalLoadJson = Cesium3DTileset.loadJson;

// override loadJson and replace incorrect url with correct url
Cesium3DTileset.loadJson = function(tilesetUrl) {
return originalLoadJson(path);
}

// setup tileset with invalid url (overridden loadJson should replace invalid url with correct url)
var tileset = new Cesium3DTileset({
url : 'invalid.json'
});

// restore original version
Cesium3DTileset.loadJson = originalLoadJson;

return tileset.readyPromise.then(function() {
expect(tileset.ready).toEqual(true);
}).otherwise(function(error) {
fail('should not fail');
});
});

it('rejects readyPromise with invalid tileset version', function() {
var tilesetJson = {
asset : {
version : 2.0
Expand Down

0 comments on commit 48ff4ba

Please sign in to comment.