-
Notifications
You must be signed in to change notification settings - Fork 195
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
feat(tiles): 3DTile services #2635
Open
ibgreen
wants to merge
4
commits into
master
Choose a base branch
from
3dtiles-services
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// loaders.gl, MIT license | ||
|
||
import {Tiles3DService} from '@loaders.gl/tiles'; | ||
import {CesiumIonLoader} from '../cesium-ion-loader'; | ||
import {fetchFile} from '@loaders.gl/core'; | ||
|
||
const CESIUM_ION_URL = 'https://api.cesium.com/v1/assets'; | ||
|
||
export type IONAsset = { | ||
type: '3DTILES' | 'GLTF' | 'IMAGERY' | 'TERRAIN' | 'KML' | 'GEOJSON'; | ||
id: string; | ||
name: string; | ||
description: string; | ||
attribution: string; | ||
}; | ||
|
||
export type IONAssetMetadata = { | ||
type: '3DTILES' | 'GLTF' | 'IMAGERY' | 'TERRAIN' | 'KML' | 'GEOJSON'; | ||
|
||
// Asset info | ||
id: string; | ||
name: string; | ||
description: string; | ||
attribution: string; | ||
|
||
// Endpoint info | ||
url: string; | ||
/** Resource specific access token valid for ~1 hour. Re-request metadata to refresh */ | ||
accessToken: string; | ||
attributions: { | ||
html: string; | ||
collapsible?: boolean; | ||
}[]; | ||
}; | ||
|
||
/** | ||
* Attribution for Cesium ion. | ||
* @see https://cesium.com/legal/terms-of-service/ | ||
*/ | ||
export class CesiumIONService extends Tiles3DService { | ||
readonly id = 'cesium'; | ||
readonly name = 'Cesium ion'; | ||
readonly urlKey = 'ion.cesium'; | ||
readonly attribution = { | ||
title: 'Cesium.', | ||
url: 'https://cesium.com/' | ||
}; | ||
|
||
/** @todo remove CesiumIONLoader, integrate into service? */ | ||
readonly loader = CesiumIonLoader; | ||
|
||
async getAssetCatalog(): Promise<IONAsset[]> { | ||
if (!this.accessToken) { | ||
throw new Error(`No access token for ${this.name}`); | ||
} | ||
|
||
const url = CESIUM_ION_URL; | ||
const response = await fetchFile(url, {headers: {Authorization: `Bearer ${this.accessToken}`}}); | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
const assetJson = await response.json(); | ||
|
||
const assets = assetJson.items; | ||
// Remove any pending or errored assets | ||
return assets.filter((asset) => asset.status === 'COMPLETE') as IONAsset[]; | ||
} | ||
|
||
/** | ||
* Retrieves metadata information about a specific ION asset. | ||
* @param assetId | ||
* @returns {url, headers, type, attributions} for an ion tileset | ||
*/ | ||
async getAssetMetadata(assetId: string): Promise<IONAssetMetadata> { | ||
if (!this.accessToken) { | ||
throw new Error(`No access token for ${this.name}`); | ||
} | ||
|
||
// Retrieves metadata information about a specific asset. | ||
// @see https://cesium.com/docs/rest-api/#operation/getAsset | ||
const url = `${CESIUM_ION_URL}/${assetId}`; | ||
let response = await fetchFile(`${url}`, { | ||
headers: {Authorization: `Bearer ${this.accessToken}`} | ||
}); | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
let metadata = await response.json(); | ||
if (metadata.status !== 'COMPLETE') { | ||
throw new Error(`Incomplete ION asset ${assetId}`); | ||
} | ||
|
||
// Retrieves information and credentials that allow you to access the tiled asset data for visualization and analysis. | ||
// https://cesium.com/docs/rest-api/#operation/getAssetEndpoint | ||
response = await fetchFile(`${url}/endpoint`, { | ||
headers: {Authorization: `Bearer ${this.accessToken}`} | ||
}); | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
const tilesetInfo = await response.json(); | ||
|
||
// extract dataset description | ||
metadata = { | ||
...metadata, | ||
...tilesetInfo, | ||
headers: { | ||
Authorization: `Bearer ${tilesetInfo.accessToken}` | ||
} | ||
}; | ||
|
||
return metadata as IONAssetMetadata; | ||
} | ||
|
||
async getMetadataForUrl(url: string): Promise<any> { | ||
const parsedUrl = this.parseUrl(url); | ||
if (!parsedUrl) { | ||
throw new Error(`Invalid url ${url}`); | ||
} | ||
const assetMetadata = await this.getAssetMetadata(parsedUrl.assetId); | ||
// return {name: this.name, ...assetMetadata}; | ||
return assetMetadata; | ||
} | ||
|
||
parseUrl(url: string): {assetId: string; resource: string} | null { | ||
const matched = /\/([0-9]+)\/tileset.json/.exec(this.url); | ||
const assetId = matched && matched[1]; | ||
return assetId ? {assetId, resource: 'tileset.json'} : null; | ||
} | ||
|
||
getUrl(tileUrl: string): string { | ||
return `${tileUrl}?key=${this.accessToken}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// loaders.gl, MIT license | ||
|
||
import {Tiles3DService} from '@loaders.gl/tiles'; | ||
import {Tiles3DLoader} from '../tiles-3d-loader'; | ||
|
||
export type GoogleAsset = { | ||
id: string; | ||
url: string; | ||
name: string; | ||
}; | ||
|
||
const ASSET_CATALOG: GoogleAsset[] = [ | ||
{ | ||
id: '1', | ||
url: 'https://tile.googleapis.com/v1/3dtiles/root.json', | ||
name: 'Google 3D Tiles' | ||
} | ||
]; | ||
|
||
/** | ||
* @see https://developers.google.com/maps/documentation/tile/policies | ||
* attribution shouldn't be hidden (right now dataset attribution is only partly shown and expanded on hover). | ||
* attribution should be visible (right now displayed with a grayish color, unnoticeable with Google 3d tiles) | ||
* Google logo should be displayed on the bottom left side (where FSQ watermark is located). | ||
*/ | ||
export class Google3DTilesService extends Tiles3DService { | ||
readonly id = 'google'; | ||
readonly name = 'Google 3D Tiles'; | ||
readonly urlKey = 'google'; | ||
// Also, attribution for Google 3D tiles is collected from visible tiles. | ||
readonly attribution = { | ||
title: 'Built with Google Maps.', | ||
url: '', | ||
logoUrl: | ||
'https://developers.google.com/static/maps/documentation/images/google_on_non_white.png' | ||
}; | ||
|
||
readonly loader = Tiles3DLoader; | ||
readonly minZoom = 8; | ||
|
||
getLoadOptions() { | ||
return {fetch: {headers: {'X-GOOG-API-KEY': this.accessToken}}}; | ||
} | ||
|
||
async getAssetCatalog(): Promise<GoogleAsset[]> { | ||
return ASSET_CATALOG; | ||
} | ||
|
||
async getAssetMetadata(assetId: string): Promise<any> { | ||
if (!this.accessToken) { | ||
throw new Error(`No access token for ${this.name}`); | ||
} | ||
const response = await fetch(`${this.url}?key=${this.accessToken}`); | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch ${this.name} ${response.status}`); | ||
} | ||
const json = await response.json(); | ||
return {name: this.name, ...json}; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// loaders.gl, MIT license | ||
|
||
import {Tiles3DService} from '@loaders.gl/tiles'; | ||
import {I3SLoader} from '../i3s-loader'; | ||
|
||
/** | ||
* Layout guidelines for ArcGIS attribution. | ||
* @see https://developers.arcgis.com/documentation/mapping-apis-and-services/deployment/basemap-attribution/ | ||
* Custom layout guidelines for ArcGIS attribution. | ||
* @see https://developers.arcgis.com/documentation/mapping-apis-and-services/deployment/basemap-attribution/#layout-and-design-guidelines | ||
*/ | ||
export class ArcGISI3SService extends Tiles3DService { | ||
id = 'arcgis'; | ||
name = 'ArcGIS'; | ||
urlKey = 'arcgis'; | ||
attribution = { | ||
title: 'Powered by Esri.', | ||
url: 'https://arcgis.com/' | ||
}; | ||
|
||
loader = I3SLoader; | ||
|
||
async getAssetCatalog(): Promise<unknown[]> { | ||
return []; | ||
} | ||
|
||
async getMetadata(): Promise<any> { | ||
const response = await fetch(this.url); | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch ${this.name} ${response.status}`); | ||
} | ||
return {name: this.name, ...(await response.json())}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// loaders.gl, MIT license | ||
|
||
import type {Loader} from '@loaders.gl/loader-utils'; | ||
|
||
export type Tiles3DAttribution = { | ||
title: string; | ||
url: string; | ||
logoUrl?: string; | ||
}; | ||
|
||
/** | ||
* Handles access token, metadata and attribution for a 3D tileset service. | ||
*/ | ||
export abstract class Tiles3DService { | ||
static getServiceFromUrl(url: string, services: Tiles3DService[]): Tiles3DService | null { | ||
return services.find((service) => url.includes(service.urlKey)) || null; | ||
} | ||
|
||
/** id string */ | ||
abstract readonly id: string; | ||
/** Human readable name */ | ||
abstract readonly name: string; | ||
/** Identifies this service by matching a user supplied URL against this key */ | ||
abstract readonly urlKey: string; | ||
/** Default attribution per supported tileset provider. */ | ||
abstract readonly attribution: Tiles3DAttribution; | ||
|
||
/** Loader required by this particular service */ | ||
abstract readonly loader: Loader; | ||
|
||
/** Base URL of this service */ | ||
url: string; | ||
/** Access token for this service */ | ||
accessToken: string; | ||
|
||
/** | ||
* | ||
* @param url Base url to the service | ||
* @param accessToken Access token for the service | ||
*/ | ||
constructor(url: string, accessToken: string) { | ||
this.url = url; | ||
this.accessToken = accessToken; | ||
} | ||
|
||
/** Queries metadata from a 3D tileset service. | ||
* @param url Url of a 3D tileset. | ||
* @param this.accessToken Optional access token. | ||
* @returns Downloaded metadata. | ||
*/ | ||
abstract getAssetCatalog(): Promise<unknown[]>; | ||
|
||
/** Test against map state - @todo outside of loaders.gl scope... */ | ||
isSupported(mapState: any): boolean { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need getLoadOptions here?
loadOptions: {'cesium-ion': {accessToken, worker: true}}