Skip to content

Commit

Permalink
Merged master.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Fili committed Feb 13, 2018
2 parents 0d98dab + 0e4afd3 commit 0ebeb19
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 103 deletions.
16 changes: 15 additions & 1 deletion Apps/CesiumViewer/CesiumViewer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define([
'Cesium/Core/Cartesian3',
'Cesium/Core/CesiumTerrainProvider',
'Cesium/Core/defined',
'Cesium/Core/formatError',
'Cesium/Core/Math',
Expand All @@ -15,6 +16,7 @@ define([
'domReady!'
], function(
Cartesian3,
CesiumTerrainProvider,
defined,
formatError,
CesiumMath,
Expand Down Expand Up @@ -52,12 +54,24 @@ define([
var loadingIndicator = document.getElementById('loadingIndicator');
var viewer;
try {
var hasBaseLayerPicker = !defined(imageryProvider);
viewer = new Viewer('cesiumContainer', {
imageryProvider : imageryProvider,
baseLayerPicker : !defined(imageryProvider),
baseLayerPicker : hasBaseLayerPicker,
scene3DOnly : endUserOptions.scene3DOnly,
requestRenderMode : true
});

if (hasBaseLayerPicker) {
var viewModel = viewer.baseLayerPicker.viewModel;
viewModel.selectedTerrain = viewModel.terrainProviderViewModels[1];
} else {
viewer.terrainProvider = new CesiumTerrainProvider({
url: 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
requestWaterMask: true,
requestVertexNormals: true
});
}
} catch (exception) {
loadingIndicator.style.display = 'none';
var message = formatError(exception);
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Change Log
* In the `Resource` class, `addQueryParameters` and `addTemplateValues` have been deprecated and will be removed in Cesium 1.45. Please use `setQueryParameters` and `setTemplateValues` instead.

##### Additions :tada:
* Added support for a promise to a resource for `CesiumTerrainProvider`, `createTileMapServiceImageryProvider` and `Cesium3DTileset` [#6204](https://github.com/AnalyticalGraphicsInc/cesium/pull/6204)
* `Resource` class [#6205](https://github.com/AnalyticalGraphicsInc/cesium/issues/6205)
* Added `put`, `patch`, `delete`, `options` and `head` methods, so it can be used for all XHR requests.
* Added `preserveQueryParameters` parameter to `getDerivedResource`, to allow us to append query parameters instead of always replacing them.
Expand All @@ -17,6 +18,9 @@ Change Log
* Fixed `Resource.fetch` when called with no arguments [#6206](https://github.com/AnalyticalGraphicsInc/cesium/issues/6206)
* Fixed `Resource.clone` to clone the `Request` object, so resource can be used in parallel. [#6208](https://github.com/AnalyticalGraphicsInc/cesium/issues/6208)

##### Additions :tada:
* Enable terrain in the `CesiumViewer` demo application [#6198](https://github.com/AnalyticalGraphicsInc/cesium/pull/6198)

### 1.42.1 - 2018-02-01
_This is an npm-only release to fix an issue with using Cesium in Node.js.__
* Fixed a bug where Cesium would fail to load under Node.js. [#6177](https://github.com/AnalyticalGraphicsInc/cesium/pull/6177)
Expand Down
40 changes: 24 additions & 16 deletions Source/Core/CesiumTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ define([
* @constructor
*
* @param {Object} options Object with the following properties:
* @param {Resource|String} options.url The URL of the Cesium terrain server.
* @param {Resource|String|Promise<Resource>|Promise<String>} options.url The URL of the Cesium terrain server.
* @param {Boolean} [options.requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server, in the form of per vertex normals if available.
* @param {Boolean} [options.requestWaterMask=false] Flag that indicates if the client should request per tile water masks from the server, if available.
* @param {Ellipsoid} [options.ellipsoid] The ellipsoid. If not specified, the WGS84 ellipsoid is used.
Expand Down Expand Up @@ -112,11 +112,6 @@ define([
deprecationWarning('CesiumTerrainProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.');
}

var resource = Resource.createIfNeeded(options.url, {
proxy: options.proxy
});
resource.appendForwardSlash();

this._tilingScheme = new GeographicTilingScheme({
numberOfLevelZeroTilesX : 2,
numberOfLevelZeroTilesY : 1,
Expand Down Expand Up @@ -156,20 +151,34 @@ define([

this._availability = undefined;

var deferred = when.defer();
this._ready = false;
this._readyPromise = when.defer();

var lastResource = resource;
var metadataResource = lastResource.getDerivedResource({
url: 'layer.json'
});
this._readyPromise = deferred;

var that = this;
var lastResource;
var metadataResource;
var metadataError;

var layers = this._layers = [];
var attribution = '';
var overallAvailability = [];
when(options.url)
.then(function(url) {
var resource = Resource.createIfNeeded(url, {
proxy: options.proxy
});
resource.appendForwardSlash();
lastResource = resource;
metadataResource = lastResource.getDerivedResource({
url: 'layer.json'
});

requestMetadata();
})
.otherwise(function(e) {
deferred.reject(e);
});

function parseMetadataSuccess(data) {
var message;
Expand Down Expand Up @@ -343,11 +352,10 @@ define([
}

function requestMetadata() {
var metadata = metadataResource.fetchJson();
when(metadata, metadataSuccess, metadataFailure);
when(metadataResource.fetchJson())
.then(metadataSuccess)
.otherwise(metadataFailure);
}

requestMetadata();
}

/**
Expand Down
53 changes: 30 additions & 23 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ define([
* @constructor
*
* @param {Object} options Object with the following properties:
* @param {Resource|String} options.url The url to a tileset.json file or to a directory containing a tileset.json file.
* @param {Resource|String|Promise<Resource>|Promise<String>} options.url The url to a tileset.json file or to a directory containing a tileset.json file.
* @param {Boolean} [options.show=true] Determines if the tileset will be shown.
* @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] A 4x4 transformation matrix that transforms the tileset's root tile.
* @param {ShadowMode} [options.shadows=ShadowMode.ENABLED] Determines whether the tileset casts or receives shadows from each light source.
Expand Down Expand Up @@ -165,26 +165,9 @@ define([
Check.defined('options.url', options.url);
//>>includeEnd('debug');

var resource = Resource.createIfNeeded(options.url);

var tilesetResource = resource;
var basePath;

if (resource.extension === 'json') {
basePath = resource.getBaseUri(true);
} else if (resource.isDataUri) {
basePath = '';
} else {
resource.appendForwardSlash();
tilesetResource = resource.getDerivedResource({
url: 'tileset.json'
});
basePath = resource.url;
}

this._url = resource.url;
this._tilesetUrl = tilesetResource.url;
this._basePath = basePath;
this._url = undefined;
this._tilesetUrl = undefined;
this._basePath = undefined;
this._root = undefined;
this._asset = undefined; // Metadata for the entire tileset
this._properties = undefined; // Metadata for per-model/point/etc properties
Expand Down Expand Up @@ -699,9 +682,33 @@ define([
this._brokenUrlWorkaround = false;

var that = this;
var tilesetResource;
when(options.url)
.then(function(url) {
var basePath;
var resource = Resource.createIfNeeded(url);

tilesetResource = resource;

if (resource.extension === 'json') {
basePath = resource.getBaseUri(true);
} else if (resource.isDataUri) {
basePath = '';
} else {
resource.appendForwardSlash();
tilesetResource = resource.getDerivedResource({
url: 'tileset.json'
});
basePath = resource.url;
}

// We don't know the distance of the tileset until tileset.json is loaded, so use the default distance for now
Cesium3DTileset.loadJson(tilesetResource)
that._url = resource.url;
that._tilesetUrl = tilesetResource.url;
that._basePath = basePath;

// We don't know the distance of the tileset until tileset.json is loaded, so use the default distance for now
return Cesium3DTileset.loadJson(tilesetResource);
})
.then(function(tilesetJson) {
return detectBrokenUrlWorkaround(that, tilesetResource, tilesetJson);
})
Expand Down
30 changes: 19 additions & 11 deletions Source/Scene/createTileMapServiceImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ define([
* @exports createTileMapServiceImageryProvider
*
* @param {Object} [options] Object with the following properties:
* @param {Resource|String} [options.url='.'] Path to image tiles on server.
* @param {Resource|String|Promise<Resource>|Promise<String>} [options.url='.'] Path to image tiles on server.
* @param {String} [options.fileExtension='png'] The file extension for images on the server.
* @param {Credit|String} [options.credit=''] A credit for the data source, which is displayed on the canvas.
* @param {Number} [options.minimumLevel=0] The minimum level-of-detail supported by the imagery provider. Take care when specifying
Expand Down Expand Up @@ -95,19 +95,28 @@ define([
deprecationWarning('createTileMapServiceImageryProvider.proxy', 'The options.proxy parameter has been deprecated. Specify options.url as a Resource instance and set the proxy property there.');
}

var resource = Resource.createIfNeeded(options.url, {
proxy : options.proxy
});
resource.appendForwardSlash();

var xmlResource = resource.getDerivedResource({
url: 'tilemapresource.xml'
});

var deferred = when.defer();
var imageryProvider = new UrlTemplateImageryProvider(deferred.promise);

var metadataError;
var resource;
var xmlResource;
when(options.url)
.then(function(url) {
resource = Resource.createIfNeeded(url, {
proxy : options.proxy
});
resource.appendForwardSlash();

xmlResource = resource.getDerivedResource({
url: 'tilemapresource.xml'
});

requestMetadata();
})
.otherwise(function(e) {
deferred.reject(e);
});

function metadataSuccess(xml) {
var tileFormatRegex = /tileformat/i;
Expand Down Expand Up @@ -282,7 +291,6 @@ define([
xmlResource.fetchXML().then(metadataSuccess).otherwise(metadataFailure);
}

requestMetadata();
return imageryProvider;
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Widgets/Viewer/viewerDragDropMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ define([
sourceUri : fileName,
proxy : proxy,
camera : scene.camera,
canvas : scene.canvas
canvas : scene.canvas,
clampToGround: clampToGround
});
} else {
viewer.dropError.raiseEvent(viewer, fileName, 'Unrecognized file: ' + fileName);
Expand Down
26 changes: 26 additions & 0 deletions Specs/Core/CesiumTerrainProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ defineSuite([
});
});

it('resolves readyPromise when url promise is used', function() {
var provider = new CesiumTerrainProvider({
url : when.resolve('made/up/url')
});

return provider.readyPromise.then(function (result) {
expect(result).toBe(true);
expect(provider.ready).toBe(true);
});
});

it('resolves readyPromise with Resource', function() {
var resource = new Resource({
url : 'made/up/url'
Expand All @@ -154,6 +165,21 @@ defineSuite([
});
});

it('rejects readyPromise when url rejects', function() {
var error = new Error();
var provider = new CesiumTerrainProvider({
url: when.reject(error)
});
return provider.readyPromise
.then(function() {
fail('should not resolve');
})
.otherwise(function(result) {
expect(result).toBe(error);
expect(provider.ready).toBe(false);
});
});

it('uses geographic tiling scheme by default', function() {
returnHeightmapTileJson();

Expand Down
17 changes: 17 additions & 0 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,23 @@ defineSuite([
});
});

it('Constructor works with promise to resource', function() {
var resource = new Resource({
url: 'Data/Cesium3DTiles/Tilesets/TilesetOfTilesets'
});

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

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

it('Constructor works with directory resource', function() {
var resource = new Resource({
url: 'Data/Cesium3DTiles/Tilesets/TilesetOfTilesets'
Expand Down
Loading

0 comments on commit 0ebeb19

Please sign in to comment.