Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static loadJson method to Cesium3DTileset #5685

Merged
merged 8 commits into from
Aug 11, 2017
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