UNPKG

@itwin/core-frontend

Version:
155 lines 6.6 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Tiles */ import { assert, BentleyStatus } from "@itwin/core-bentley"; import { IModelError, RealityDataFormat, RealityDataProvider } from "@itwin/core-common"; import { request } from "./request/Request"; import { ThreeDTileFormatInterpreter } from "./tile/internal"; /** This class provides access to the reality data provider services. * It encapsulates access to a reality data weiter it be from local access, http or ProjectWise Context Share. * The key provided at the creation determines if this is ProjectWise Context Share reference. * If not then it is considered local (ex: C:\temp\TileRoot.json) or plain http access (http://someserver.com/data/TileRoot.json) * There is a one to one relationship between a reality data and the instances of present class. * @internal */ export class RealityDataSourceTilesetUrlImpl { key; /** The URL that supplies the 3d tiles for displaying the reality model. */ _tilesetUrl; /** For use by all Reality Data. For RD stored on PW Context Share, represents the portion from the root of the Azure Blob Container*/ _baseUrl = ""; /** Need to be passed down to child tile requests when requesting from blob storage, e.g. a Cesium export from the Mesh Export Service*/ _searchParams = ""; /** Construct a new reality data source. * @param props JSON representation of the reality data source */ constructor(props) { assert(props.sourceKey.provider === RealityDataProvider.TilesetUrl || props.sourceKey.provider === RealityDataProvider.OrbitGtBlob); this.key = props.sourceKey; this._tilesetUrl = this.key.id; } /** * Create an instance of this class from a source key and iTwin context/ */ static async createFromKey(sourceKey, _iTwinId) { if (sourceKey.provider !== RealityDataProvider.TilesetUrl) return undefined; const rdSource = new RealityDataSourceTilesetUrlImpl({ sourceKey }); return rdSource; } get isContextShare() { return false; } /** * Returns Reality Data if available */ get realityData() { return undefined; } get realityDataId() { return undefined; } /** * Returns Reality Data type if available */ get realityDataType() { return undefined; } getTilesetUrl() { return this._tilesetUrl; } // This is to set the root url from the provided root document path. // If the root document is stored on PW Context Share then the root document property of the Reality Data is provided, // otherwise the full path to root document is given. // The base URL contains the base URL from which tile relative path are constructed. // The tile's path root will need to be reinserted for child tiles to return a 200 // If the original root tileset url includes search paramaters, they are stored in _searchParams to be reinserted into child tile requests. setBaseUrl(url) { const urlParts = url.split("/"); const newUrl = new URL(url); this._searchParams = newUrl.search; urlParts.pop(); if (urlParts.length === 0) this._baseUrl = ""; else this._baseUrl = `${urlParts.join("/")}/`; } /** * This method returns the URL to access the actual 3d tiles from the service provider. * @returns string containing the URL to reality data. */ async getServiceUrl(_iTwinId) { return this._tilesetUrl; } async getRootDocument(iTwinId) { const url = await this.getServiceUrl(iTwinId); if (!url) throw new IModelError(BentleyStatus.ERROR, "Unable to get service url"); // The following is only if the reality data is not stored on PW Context Share. this.setBaseUrl(url); return request(url, "json"); } isValidURL(url) { try { new URL(url); } catch { return false; } return true; } /** Returns the tile URL. * If the tile path is a relative URL, the base URL is prepended to it. * For both absolute and relative tile path URLs, the search parameters are checked. If the search params are empty, the base URL's search params are appended to the tile path. */ getTileUrl(tilePath) { if (this.isValidURL(tilePath)) { const url = new URL(tilePath); return url.search === "" ? `${tilePath}${this._searchParams}` : tilePath; } return tilePath.includes("?") ? `${this._baseUrl}${tilePath}` : `${this._baseUrl}${tilePath}${this._searchParams}`; } /** * Returns the tile content. The path to the tile is relative to the base url of present reality data whatever the type. */ async getTileContent(name) { return request(this.getTileUrl(name), "arraybuffer"); } /** * Returns the tile content in json format. The path to the tile is relative to the base url of present reality data whatever the type. */ async getTileJson(name) { return request(this.getTileUrl(name), "json"); } getTileContentType(url) { return new URL(url, "https://localhost/").pathname.toLowerCase().endsWith("json") ? "tileset" : "tile"; } /** * Gets spatial location and extents of this reality data source * @returns spatial location and extents * @internal */ async getSpatialLocationAndExtents() { let spatialLocation; if (this.key.format === RealityDataFormat.ThreeDTile) { const rootDocument = await this.getRootDocument(undefined); spatialLocation = ThreeDTileFormatInterpreter.getSpatialLocationAndExtents(rootDocument); } return spatialLocation; } /** * Gets information to identify the product and engine that create this reality data * Will return undefined if cannot be resolved * @returns information to identify the product and engine that create this reality data * @alpha */ async getPublisherProductInfo() { let publisherInfo; return publisherInfo; } } //# sourceMappingURL=RealityDataSourceTilesetUrlImpl.js.map