Skip to content

Commit

Permalink
Attempt to fix GEE
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jun 5, 2017
1 parent 172da97 commit b2ca18b
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions Source/Core/GoogleEarthEnterpriseTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define([
'./Math',
'./Rectangle',
'./Request',
'./RequestState',
'./RequestType',
'./RuntimeError',
'./TaskProcessor',
Expand All @@ -39,6 +40,7 @@ define([
CesiumMath,
Rectangle,
Request,
RequestState,
RequestType,
RuntimeError,
TaskProcessor,
Expand Down Expand Up @@ -156,6 +158,7 @@ define([

this._terrainCache = new TerrainCache();
this._terrainPromises = {};
this._terrainRequests = {};

this._errorEvent = new Event();

Expand Down Expand Up @@ -436,10 +439,13 @@ define([

// Load that terrain
var terrainPromises = this._terrainPromises;
var terrainRequests = this._terrainRequests;
var url = buildTerrainUrl(this, q, terrainVersion);
var promise;
var sharedPromise;
var sharedRequest;
if (defined(terrainPromises[q])) { // Already being loaded possibly from another child, so return existing promise
promise = terrainPromises[q];
sharedPromise = terrainPromises[q];
sharedRequest = terrainRequests[q];
} else { // Create new request for terrain
if (typeof request === 'boolean') {
deprecationWarning('throttleRequests', 'The throttleRequest parameter for requestTileGeometry was deprecated in Cesium 1.35. It will be removed in 1.36.');
Expand All @@ -450,13 +456,14 @@ define([
});
}

var requestPromise = loadArrayBuffer(url, undefined, request);
sharedRequest = request;
var requestPromise = loadArrayBuffer(url, undefined, sharedRequest);

if (!defined(requestPromise)) {
return undefined; // Throttled
}

promise = requestPromise
sharedPromise = requestPromise
.then(function(terrain) {
if (defined(terrain)) {
return taskProcessor.scheduleTask({
Expand Down Expand Up @@ -490,20 +497,27 @@ define([
return when.reject(new RuntimeError('Failed to load terrain.'));
})
.otherwise(function(error) {
if (sharedRequest.state === RequestState.CANCELLED) {
request.state = sharedRequest.state;
info.terrainState = TerrainState.UNKNOWN;
return when.reject('test');
}
info.terrainState = TerrainState.NONE;
return when.reject(error);
});

terrainPromises[q] = promise; // Store promise without delete from terrainPromises
terrainPromises[q] = sharedPromise; // Store promise without delete from terrainPromises
terrainRequests[q] = sharedRequest;

// Set promise so we remove from terrainPromises just one time
promise = promise
sharedPromise = sharedPromise
.always(function() {
delete terrainPromises[q];
delete terrainRequests[q];
});
}

return promise
return sharedPromise
.then(function() {
var buffer = terrainCache.get(quadKey);
if (defined(buffer)) {
Expand All @@ -516,9 +530,23 @@ define([
negativeElevationThreshold: metadata.negativeAltitudeThreshold
});
} else {
if (sharedRequest.state === RequestState.CANCELLED) {
request.state = sharedRequest.state;
info.terrainState = TerrainState.UNKNOWN;
return when.reject();
}
info.terrainState = TerrainState.NONE;
return when.reject(new RuntimeError('Failed to load terrain.'));
}
})
.otherwise(function() {
if (sharedRequest.state === RequestState.CANCELLED) {
request.state = sharedRequest.state;
info.terrainState = TerrainState.UNKNOWN;
return when.reject();
}
info.terrainState = TerrainState.NONE;
return when.reject(new RuntimeError('Failed to load terrain.'));
});
};

Expand Down

0 comments on commit b2ca18b

Please sign in to comment.