From e71a29132732b1bede919b90d38db35b2e3ea7ac Mon Sep 17 00:00:00 2001 From: Jason Crow Date: Thu, 27 Jul 2017 17:47:06 -0500 Subject: [PATCH 1/6] added loadJson hook to Cesium3DTileset --- Source/Scene/Cesium3DTileset.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 1f649a04fd32..993f9c142bb9 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -626,7 +626,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) { + this.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; @@ -1027,6 +1027,14 @@ define([ } }); + /** + * MProvides a hook to override the method used to request the tileset json + * useful when fetching tilesets from remote servers + */ + Cesium3DTileset.prototype.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. From a9008c29f7b0b087ee20d2a1ba2fe474008a8427 Mon Sep 17 00:00:00 2001 From: Jason Crow Date: Thu, 27 Jul 2017 17:49:56 -0500 Subject: [PATCH 2/6] fixed typo in comment --- Source/Scene/Cesium3DTileset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 993f9c142bb9..fdfb2334ed59 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -1028,7 +1028,7 @@ define([ }); /** - * MProvides a hook to override the method used to request the tileset json + * Provides a hook to override the method used to request the tileset json * useful when fetching tilesets from remote servers */ Cesium3DTileset.prototype.loadJson = function(tilesetUrl) { From 70af4e1c040590b894830213feb9e7503614741a Mon Sep 17 00:00:00 2001 From: Jason Crow Date: Thu, 27 Jul 2017 19:02:05 -0500 Subject: [PATCH 3/6] made loadJson a static method of Cesium3DTileset since it doesnt manipulate any prototypical assets. Added tests for Cesium3DTileset.loadJson method --- Source/Scene/Cesium3DTileset.js | 4 +-- Specs/Scene/Cesium3DTilesetSpec.js | 44 +++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index fdfb2334ed59..35e1ca2d3c89 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -626,7 +626,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 - this.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; @@ -1031,7 +1031,7 @@ define([ * Provides a hook to override the method used to request the tileset json * useful when fetching tilesets from remote servers */ - Cesium3DTileset.prototype.loadJson = function(tilesetUrl) { + Cesium3DTileset.loadJson = function(tilesetUrl) { return loadJson(tilesetUrl); }; diff --git a/Specs/Scene/Cesium3DTilesetSpec.js b/Specs/Scene/Cesium3DTilesetSpec.js index d791f597de56..7174d760ea18 100644 --- a/Specs/Scene/Cesium3DTilesetSpec.js +++ b/Specs/Scene/Cesium3DTilesetSpec.js @@ -207,7 +207,49 @@ 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 From d09ad562c56367a6342040e7907f404ac0c101f7 Mon Sep 17 00:00:00 2001 From: Jason Crow Date: Fri, 11 Aug 2017 11:05:08 -0500 Subject: [PATCH 4/6] updated for pull request changes (add @param,@returns to loadJson, reformat function in spec file) --- Source/Scene/Cesium3DTileset.js | 2 ++ Specs/Scene/Cesium3DTilesetSpec.js | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 35e1ca2d3c89..3beefb3eb066 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -1030,6 +1030,8 @@ 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); diff --git a/Specs/Scene/Cesium3DTilesetSpec.js b/Specs/Scene/Cesium3DTilesetSpec.js index 7174d760ea18..ec97414a2884 100644 --- a/Specs/Scene/Cesium3DTilesetSpec.js +++ b/Specs/Scene/Cesium3DTilesetSpec.js @@ -229,10 +229,9 @@ defineSuite([ var originalLoadJson = Cesium3DTileset.loadJson; // override loadJson and replace incorrect url with correct url - Cesium3DTileset.loadJson = function(tilesetUrl) - { + 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({ From 6fa97ae2b16aaae59794def3edf785bc4b3e2eb3 Mon Sep 17 00:00:00 2001 From: Jason Crow Date: Fri, 11 Aug 2017 11:13:03 -0500 Subject: [PATCH 5/6] Promise.{Object} versus Promise{Object} --- Source/Scene/Cesium3DTileset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 45e67b9da2fa..b38666dd9f5b 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -1052,7 +1052,7 @@ 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 + * @returns {Promise.} A promise that resolves with the fetched json data */ Cesium3DTileset.loadJson = function(tilesetUrl) { return loadJson(tilesetUrl); From c398fc28433ce4472cb83aaf4c4c5780a2381f31 Mon Sep 17 00:00:00 2001 From: Jason Crow Date: Fri, 11 Aug 2017 11:14:06 -0500 Subject: [PATCH 6/6] remvoed comma and capitalized 't' in the --- Source/Scene/Cesium3DTileset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index b38666dd9f5b..cca0bd85e6f7 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -1051,7 +1051,7 @@ 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 + * @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) {