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

Fix ion asset caching #6353

Merged
merged 2 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Change Log
* `ClippingPlaneCollection` should now be used with `ClippingPlane` objects instead of `Plane`. Use of `Plane` objects has been deprecated and will be removed in Cesium 1.45.

##### Additions :tada:
* Fix Cesium ion browser caching [#6353](https://github.com/AnalyticalGraphicsInc/cesium/pull/6353).
* Added support for glTF models with [Draco geometry compression](https://github.com/fanzhanggoogle/glTF/blob/KHR_mesh_compression/extensions/Khronos/KHR_draco_mesh_compression/README.md).
* `ClippingPlaneCollection` updates [#6201](https://github.com/AnalyticalGraphicsInc/cesium/pull/6201)
* Removed the 6-clipping-plane limit.
Expand Down
28 changes: 21 additions & 7 deletions Source/Core/CesiumTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,26 +623,40 @@ define([
extensionList.push('watermask');
}

var resource = layerToUse.resource.getDerivedResource({
url: urlTemplates[(x + tmsY + level) % urlTemplates.length],
var headers;
var query;
var url = urlTemplates[(x + tmsY + level) % urlTemplates.length];
var resource = layerToUse.resource;
if (defined(resource._ionEndpoint) && !defined(resource._ionEndpoint.externalType)) {
// ion uses query paremeters to request extensions
if (extensionList.length !== 0) {
query = { extensions: extensionList.join('-') };
}
headers = getRequestHeader(undefined);
} else {
//All other terrain servers
headers = getRequestHeader(extensionList);
}

var promise = resource.getDerivedResource({
url: url,
templateValues: {
version: layerToUse.version,
z: level,
x: x,
y: tmsY
},
headers: getRequestHeader(extensionList),
queryParameters: query,
headers: headers,
request: request
});

var promise = resource.fetchArrayBuffer();
}).fetchArrayBuffer();

if (!defined(promise)) {
return undefined;
}

var that = this;
return when(promise, function(buffer) {
return promise.then(function (buffer) {
if (defined(that._heightmapStructure)) {
return createHeightmapTerrainData(that, buffer, level, x, y, tmsY);
}
Expand Down
41 changes: 33 additions & 8 deletions Source/Core/IonResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ define([
Check.defined('endpointResource', endpointResource);
//>>includeEnd('debug');

var externalType = endpoint.externalType;
var options;
var externalType = endpoint.externalType;
var isExternal = defined(externalType);

if (!defined(externalType)) {
if (!isExternal) {
options = {
url: endpoint.url,
retryAttempts: 1,
queryParameters: { access_token: endpoint.accessToken },
retryCallback: retryCallback
};
} else if (externalType === '3DTILES' || externalType === 'STK_TERRAIN_SERVER') {
Expand All @@ -74,6 +74,7 @@ define([
// Shared promise for endpooint requests amd credits (only ever set on the root request)
this._pendingPromise = undefined;
this._credits = undefined;
this._isExternal = isExternal;
}

if (defined(Object.create)) {
Expand Down Expand Up @@ -155,13 +156,39 @@ define([

result = Resource.prototype.clone.call(this, result);
result._ionRoot = ionRoot;
if (defined(ionRoot.queryParameters.access_token)) {
result.queryParameters.access_token = ionRoot.queryParameters.access_token;
}
result._isExternal = this._isExternal;

return result;
};

IonResource.prototype.fetchImage = function (preferBlob, allowCrossOrigin) {
return Resource.prototype.fetchImage.call(this, this._isExternal ? preferBlob : true, allowCrossOrigin);
};

IonResource.prototype._makeRequest = function(options) {
if (this._isExternal) {
return Resource.prototype._makeRequest.call(this, options);
}

var acceptToken = '*/*;access_token=' + this._ionEndpoint.accessToken;
var existingAccept = acceptToken;

var oldHeaders = this.headers;
if (defined(oldHeaders) && defined(oldHeaders.Accept)) {
existingAccept = oldHeaders.Accept + ',' + acceptToken;
}

if (!defined(options.headers)) {
options.headers = { Accept: existingAccept };
} else if (!defined(options.headers.Accept)) {
options.headers.Accept = existingAccept;
} else {
options.headers.Accept = options.headers.Accept + ',' + acceptToken;
}

return Resource.prototype._makeRequest.call(this, options);
};

/**
* @private
*/
Expand Down Expand Up @@ -204,7 +231,6 @@ define([
.then(function(newEndpoint) {
//Set the token for root resource so new derived resources automatically pick it up
ionRoot._ionEndpoint = newEndpoint;
ionRoot.queryParameters.access_token = newEndpoint.accessToken;
return newEndpoint;
})
.always(function(newEndpoint) {
Expand All @@ -217,7 +243,6 @@ define([
return ionRoot._pendingPromise.then(function(newEndpoint) {
// Set the new token and endpoint for this resource
that._ionEndpoint = newEndpoint;
that.queryParameters.access_token = newEndpoint.accessToken;
return true;
});
}
Expand Down
19 changes: 10 additions & 9 deletions Source/Core/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,15 +1240,16 @@ define([
/**
* @private
*/
Resource._makeRequest = function(resource, options) {
Resource.prototype._makeRequest = function(options) {
var resource = this;
checkAndResetRequest(resource.request);

var request = resource.request;
request.url = resource.url;

request.requestFunction = function() {
var responseType = options.responseType;
var headers = combine(resource.headers, options.headers);
var headers = combine(options.headers, resource.headers);
var overrideMimeType = options.overrideMimeType;
var method = options.method;
var data = options.data;
Expand Down Expand Up @@ -1369,7 +1370,7 @@ define([
options = defaultClone(options, {});
options.method = 'GET';

return Resource._makeRequest(this, options);
return this._makeRequest(options);
};

/**
Expand Down Expand Up @@ -1425,7 +1426,7 @@ define([
options = defaultClone(options, {});
options.method = 'DELETE';

return Resource._makeRequest(this, options);
return this._makeRequest(options);
};

/**
Expand Down Expand Up @@ -1481,7 +1482,7 @@ define([
options = defaultClone(options, {});
options.method = 'HEAD';

return Resource._makeRequest(this, options);
return this._makeRequest(options);
};

/**
Expand Down Expand Up @@ -1537,7 +1538,7 @@ define([
options = defaultClone(options, {});
options.method = 'OPTIONS';

return Resource._makeRequest(this, options);
return this._makeRequest(options);
};

/**
Expand Down Expand Up @@ -1597,7 +1598,7 @@ define([
options.method = 'POST';
options.data = data;

return Resource._makeRequest(this, options);
return this._makeRequest(options);
};

/**
Expand Down Expand Up @@ -1658,7 +1659,7 @@ define([
options.method = 'PUT';
options.data = data;

return Resource._makeRequest(this, options);
return this._makeRequest(options);
};

/**
Expand Down Expand Up @@ -1719,7 +1720,7 @@ define([
options.method = 'PATCH';
options.data = data;

return Resource._makeRequest(this, options);
return this._makeRequest(options);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/loadWithXhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ define([
// Take advantage that most parameters are the same
var resource = new Resource(options);

return Resource._makeRequest(resource, {
return resource._makeRequest({
responseType: options.responseType,
overrideMimeType: options.overrideMimeType,
method: defaultValue(options.method, 'GET'),
Expand Down
19 changes: 19 additions & 0 deletions Specs/Core/CesiumTerrainProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defineSuite([
'Core/GeographicTilingScheme',
'Core/getAbsoluteUri',
'Core/HeightmapTerrainData',
'Core/IonResource',
'Core/Math',
'Core/QuantizedMeshTerrainData',
'Core/Request',
Expand All @@ -20,6 +21,7 @@ defineSuite([
GeographicTilingScheme,
getAbsoluteUri,
HeightmapTerrainData,
IonResource,
CesiumMath,
QuantizedMeshTerrainData,
Request,
Expand Down Expand Up @@ -746,5 +748,22 @@ defineSuite([
expect(loadedData).toBeInstanceOf(HeightmapTerrainData);
});
});

it('Uses query parameter extensions for ion resource', function() {
var terrainProvider = new CesiumTerrainProvider({
url: IonResource.fromAssetId(1),
requestVertexNormals: true,
requestWaterMask: true
});

return pollToPromise(function() {
return terrainProvider.ready;
}).then(function() {
var getDerivedResource = spyOn(IonResource.prototype, 'getDerivedResource').and.callThrough();
terrainProvider.requestTileGeometry(0, 0, 0);
var options = getDerivedResource.calls.argsFor(0)[0];
expect(options.queryParameters.extensions).toEqual('octvertexnormals-watermask');
});
});
});
});
Loading