-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 Cesium ion external asset handling #6140
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,34 @@ define([ | |
* }); | ||
*/ | ||
CesiumIon.createResource = function(assetId, options) { | ||
var endpointResource = CesiumIon.createEndpointResource(assetId, options); | ||
|
||
return CesiumIon._loadJson(endpointResource) | ||
.then(function (endpoint) { | ||
|
||
var externalType = endpoint.externalType; | ||
if (!defined(externalType)) { | ||
return CesiumIonResource.create(endpoint, endpointResource); | ||
} | ||
|
||
// 3D Tiles and STK Terrain Server external assets can still be represented as a resource | ||
// object, just not the CesiumIonResource object. | ||
if (externalType === '3DTILES' || externalType === 'STK_TERRAIN_SERVER') { | ||
return new Resource({ url: endpoint.options.url }); | ||
} | ||
|
||
//External imagery assets have additional configuration that can't be represented as a Resource | ||
throw new RuntimeError('CesiumIon.createResource does not support external imagery assets.'); | ||
}); | ||
}; | ||
|
||
/** | ||
* @private | ||
*/ | ||
CesiumIon.createEndpointResource = function (assetId, options) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
//>>includeStart('debug', pragmas.debug); | ||
Check.defined('assetId', assetId); | ||
//>>includeEnd('debug'); | ||
|
||
options = defaultValue(options, defaultValue.EMPTY_OBJECT); | ||
var serverUrl = defaultValue(options.serverUrl, CesiumIon.defaultServerUrl); | ||
|
@@ -105,11 +132,27 @@ define([ | |
resourceOptions.queryParameters = { access_token: accessToken }; | ||
} | ||
|
||
var endpointResource = new Resource(resourceOptions); | ||
return CesiumIon._loadJson(endpointResource) | ||
.then(function(endpoint) { | ||
return CesiumIonResource.create(endpoint, endpointResource); | ||
}); | ||
return new Resource(resourceOptions); | ||
}; | ||
|
||
function createFactory(Type) { | ||
return function(options) { | ||
return new Type(options); | ||
}; | ||
} | ||
|
||
// These values are the unofficial list of supported external imagery | ||
// assets in the Cesium ion beta. They are subject to change. | ||
var ImageryProviderMapping = { | ||
ARCGIS_MAPSERVER: createFactory(ArcGisMapServerImageryProvider), | ||
BING: createFactory(BingMapsImageryProvider), | ||
GOOGLE_EARTH: createFactory(GoogleEarthEnterpriseMapsProvider), | ||
MAPBOX: createFactory(MapboxImageryProvider), | ||
SINGLE_TILE: createFactory(SingleTileImageryProvider), | ||
TMS: createTileMapServiceImageryProvider, | ||
URL_TEMPLATE: createFactory(UrlTemplateImageryProvider), | ||
WMS: createFactory(WebMapServiceImageryProvider), | ||
WMTS: createFactory(WebMapTileServiceImageryProvider) | ||
}; | ||
|
||
/** | ||
|
@@ -130,16 +173,36 @@ define([ | |
* }); | ||
*/ | ||
CesiumIon.createImageryProvider = function(assetId, options) { | ||
return CesiumIon.createResource(assetId, options) | ||
.then(function(resource) { | ||
return resource.createImageryProvider(); | ||
var endpointResource = CesiumIon.createEndpointResource(assetId, options); | ||
|
||
return CesiumIon._loadJson(endpointResource) | ||
.then(function(endpoint) { | ||
|
||
if (endpoint.type !== 'IMAGERY') { | ||
throw new RuntimeError('Cesium ion asset ' + assetId + ' is not an imagery asset.'); | ||
} | ||
|
||
var externalType = endpoint.externalType; | ||
if (!defined(externalType)) { | ||
return createTileMapServiceImageryProvider({ | ||
url: CesiumIonResource.create(endpoint, endpointResource) | ||
}); | ||
} | ||
|
||
var factory = ImageryProviderMapping[externalType]; | ||
|
||
if (!defined(factory)) { | ||
throw new RuntimeError('Unrecognized Cesium ion imagery type: ' + externalType); | ||
} | ||
|
||
return factory(endpoint.options); | ||
}); | ||
}; | ||
|
||
/** | ||
* A {@link Resource} instance that encapsulates Cesium ion asset | ||
* creation and automatic refresh token handling. This object | ||
* should not be created directly, use CesiumIonResource.create | ||
* creation and automatic refresh token handling. This object | ||
* should not be created directly, use CesiumIonResource.create. | ||
* | ||
* @private | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved it, my main reason for keeping it off is because it ends up on the |
||
|
@@ -159,14 +222,11 @@ define([ | |
CesiumIonResource.create = function (endpoint, endpointResource) { | ||
var options = { | ||
url: endpoint.url, | ||
retryCallback: createRetryCallback(endpoint, endpointResource), | ||
retryAttempts: 1 | ||
retryAttempts: 1, | ||
queryParameters: { access_token: endpoint.accessToken }, | ||
retryCallback: createRetryCallback(endpoint, endpointResource) | ||
}; | ||
|
||
if (defined(endpoint.accessToken)) { | ||
options.queryParameters = { access_token: endpoint.accessToken }; | ||
} | ||
|
||
return new CesiumIonResource(options, endpoint, endpointResource); | ||
}; | ||
|
||
|
@@ -176,17 +236,15 @@ define([ | |
} | ||
|
||
CesiumIonResource.prototype.clone = function(result) { | ||
// We always want to use the root's information because it's the most up-to-date | ||
var ionRoot = defaultValue(this.ionRoot, this); | ||
|
||
if (!defined(result)) { | ||
// We always want to use the root's information because it's the most up-to-date | ||
result = new CesiumIonResource({ url: this._url }, ionRoot.ionEndpoint, ionRoot.ionEndpointResource); | ||
} | ||
|
||
result = Resource.prototype.clone.call(this, result); | ||
result.ionRoot = ionRoot; | ||
|
||
// Same comment as above, use the root's access_token | ||
result.queryParameters.access_token = ionRoot.queryParameters.access_token; | ||
return result; | ||
}; | ||
|
@@ -239,41 +297,6 @@ define([ | |
return retryCallback; | ||
} | ||
|
||
function createFactory(Type) { | ||
return function(options) { | ||
return new Type(options); | ||
}; | ||
} | ||
|
||
// These values are the unofficial list of supported external imagery | ||
// assets in the Cesium ion beta. They are subject to change. | ||
var ImageryProviderMapping = { | ||
ARCGIS_MAPSERVER: createFactory(ArcGisMapServerImageryProvider), | ||
BING: createFactory(BingMapsImageryProvider), | ||
GOOGLE_EARTH: createFactory(GoogleEarthEnterpriseMapsProvider), | ||
MAPBOX: createFactory(MapboxImageryProvider), | ||
SINGLE_TILE: createFactory(SingleTileImageryProvider), | ||
TMS: createTileMapServiceImageryProvider, | ||
URL_TEMPLATE: createFactory(UrlTemplateImageryProvider), | ||
WMS: createFactory(WebMapServiceImageryProvider), | ||
WMTS: createFactory(WebMapTileServiceImageryProvider) | ||
}; | ||
|
||
CesiumIonResource.prototype.createImageryProvider = function() { | ||
var type = this.ionEndpoint.type; | ||
if (type === 'IMAGERY') { | ||
return createTileMapServiceImageryProvider({ url: this }); | ||
} | ||
|
||
var factory = ImageryProviderMapping[type]; | ||
|
||
if (!defined(factory)) { | ||
throw new RuntimeError('Unrecognized Cesium ion imagery type: ' + type); | ||
} | ||
|
||
return factory(this.ionEndpoint); | ||
}; | ||
|
||
//Exposed for testing | ||
CesiumIon._CesiumIonResource = CesiumIonResource; | ||
CesiumIon._loadJson = loadJson; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment to use
CesiumIon.createImageryProvider
instead. Or can't we just make a call to that from this function instead of throwing an error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree on updating the error message, but I think just calling it from here would be confusing since it's a completely different return type. I also expect external assets to change a lot in the future, so they'll remain experimental for longer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍