|
@@ -8,8 +8,6 @@ import { UNLOADED, LOADING, PARSING, LOADED, FAILED } from './constants.js';
|
|
|
// Function for sorting the evicted LRU items. We should evict the shallowest depth first.
|
|
|
const priorityCallback = tile => 1 / ( tile.__depthFromRenderedParent + 1 );
|
|
|
|
|
|
-const defaultIonToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlNzMyOGZjZC1jMWUzLTQxNDctOGQxYi03YTYyZDQ1OTIxMjkiLCJpZCI6MjU5LCJpYXQiOjE2MDE1Njk1NDN9.X1a0DCM6F539g9MDSs_ldZ0gwgruxLAZiBl60JwG1ck';
|
|
|
-
|
|
|
export class TilesRendererBase {
|
|
|
|
|
|
get rootTileSet() {
|
|
@@ -34,17 +32,16 @@ export class TilesRendererBase {
|
|
|
|
|
|
}
|
|
|
|
|
|
- //The url can be:
|
|
|
- //A plain url to the tileset json file
|
|
|
- //A Cesium Ion asset number with access token
|
|
|
- //A url to the Cesium Ion json file with bearer token as the ionAccessToken. This needs to be fetched from the Ion endpoint separately
|
|
|
- constructor( url, ionAccessToken = defaultIonToken ) {
|
|
|
+ constructor( url ) {
|
|
|
|
|
|
// state
|
|
|
this.tileSets = {};
|
|
|
+ this.rootURL = url;
|
|
|
this.fetchOptions = {};
|
|
|
|
|
|
- this.setupUrlTokens( url, ionAccessToken );
|
|
|
+ this.isGeoReferenced = undefined;
|
|
|
+
|
|
|
+ this.onPreprocessURL = null;
|
|
|
|
|
|
const lruCache = new LRUCache();
|
|
|
lruCache.unloadPriorityCallback = priorityCallback;
|
|
@@ -81,73 +78,6 @@ export class TilesRendererBase {
|
|
|
|
|
|
}
|
|
|
|
|
|
- setupUrlTokens( url, ionToken ) {
|
|
|
-
|
|
|
- this.ionAssetId = this.isInt( url ) ? url : null;
|
|
|
- this.ionAccessToken = ionToken;
|
|
|
- this.fetchOptions.headers = {};
|
|
|
-
|
|
|
- if ( ! this.ionAssetId ) {
|
|
|
-
|
|
|
- this.rootURL = url;
|
|
|
- if ( this.isIonJsonUrl( url ) ) {
|
|
|
-
|
|
|
- this.ionAssetId = url.split( "/" )[ 3 ];
|
|
|
- this.ionJsonUrl = new URL( url );
|
|
|
- this.ionVersion = this.ionJsonUrl.searchParams.get( 'v' );
|
|
|
- this.fetchOptions.headers.Authorization = `Bearer ${ionToken}`;
|
|
|
- this.rootURL = this.ionJsonUrl;
|
|
|
-
|
|
|
- }
|
|
|
- return;
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- this.ionEndpointUrl = new URL( `https://api.cesium.com/v1/assets/${this.ionAssetId}/endpoint` );
|
|
|
- this.ionEndpointUrl.searchParams.append( 'access_token', ionToken );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- isInt( input ) {
|
|
|
-
|
|
|
- return ( typeof input === 'string' ) ? ! isNaN( input ) && ! isNaN( parseFloat( input, 10 ) ) && Number.isInteger( parseFloat( input, 10 ) ) : Number.isInteger( input );
|
|
|
-
|
|
|
- }
|
|
|
- isIonJsonUrl( input ) {
|
|
|
-
|
|
|
- return input.includes( '://assets.cesium.com/' ) && input.includes( '/tileset.json' );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- getIonAssetJson( url ) {
|
|
|
-
|
|
|
- return fetch( url, this.fetchOptions )
|
|
|
- .then( res => {
|
|
|
-
|
|
|
- if ( res.ok ) {
|
|
|
-
|
|
|
- return res.json();
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- return Promise.reject( `${res.status} : ${res.statusText}` );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } )
|
|
|
- .then( json => {
|
|
|
-
|
|
|
- this.ionJsonUrl = new URL( json.url );
|
|
|
- this.ionVersion = this.ionJsonUrl.searchParams.get( 'v' );
|
|
|
- this.fetchOptions.headers.Authorization = `Bearer ${json.accessToken}`;
|
|
|
- this.rootURL = this.ionJsonUrl;
|
|
|
-
|
|
|
- } );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
traverse( beforecb, aftercb ) {
|
|
|
|
|
|
const tileSets = this.tileSets;
|
|
@@ -167,18 +97,6 @@ export class TilesRendererBase {
|
|
|
const rootTileSet = tileSets[ this.rootURL ];
|
|
|
if ( ! ( this.rootURL in tileSets ) ) {
|
|
|
|
|
|
- if ( this.ionAssetId && ! this.ionJsonUrl ) {
|
|
|
-
|
|
|
- if ( this.ionJsonUrl == undefined ) {
|
|
|
-
|
|
|
- this.ionJsonUrl = false; // Can't use promise to block update loop, hence this hack
|
|
|
- this.getIonAssetJson( this.ionEndpointUrl ).catch( err => console.error( `TilesRenderer: Failed to load ION endpoint "${this.ionEndpointUrl}" with error: ${err}` ) );
|
|
|
-
|
|
|
- }
|
|
|
- return;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
this.loadRootTileSet( this.rootURL );
|
|
|
return;
|
|
|
|
|
@@ -513,13 +431,7 @@ export class TilesRendererBase {
|
|
|
|
|
|
}
|
|
|
|
|
|
- let uri = tile.content.uri;
|
|
|
- if ( this.ionAssetId ) {
|
|
|
-
|
|
|
- uri = new URL( tile.content.uri );
|
|
|
- uri.searchParams.append( 'v', this.ionVersion );
|
|
|
-
|
|
|
- }
|
|
|
+ const uri = this.onPreprocessURL ? this.onPreprocessURL( tile.content.uri ) : tile.content.uri;
|
|
|
return this.fetchTileSet( uri, Object.assign( { signal }, this.fetchOptions ), tile );
|
|
|
|
|
|
} )
|
|
@@ -550,14 +462,8 @@ export class TilesRendererBase {
|
|
|
return Promise.resolve();
|
|
|
|
|
|
}
|
|
|
- let uri = tile.content.uri;
|
|
|
- if ( this.ionAssetId ) {
|
|
|
-
|
|
|
- uri = new URL( tile.content.uri );
|
|
|
- uri.searchParams.append( 'v', this.ionVersion );
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
+ const uri = this.onPreprocessURL ? this.onPreprocessURL( tile.content.uri ) : tile.content.uri;
|
|
|
return fetch( uri, Object.assign( { signal }, this.fetchOptions ) );
|
|
|
|
|
|
} )
|