diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index bfbd478217a6..cca0bd85e6f7 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -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; @@ -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.} 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. diff --git a/Specs/Scene/Cesium3DTilesetSpec.js b/Specs/Scene/Cesium3DTilesetSpec.js index fa4375b340f7..9e52dc598cd2 100644 --- a/Specs/Scene/Cesium3DTilesetSpec.js +++ b/Specs/Scene/Cesium3DTilesetSpec.js @@ -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