@itwin/frontend-tiles 4.0.2 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,19 @@
1
1
  # Change Log - @itwin/frontend-tiles
2
2
 
3
- This log was last generated on Wed, 21 Jun 2023 22:04:43 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 12 Jul 2023 15:50:01 GMT and should not be manually modified.
4
+
5
+ ## 4.0.4
6
+ Wed, 12 Jul 2023 15:50:01 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 4.0.3
11
+ Mon, 03 Jul 2023 15:28:41 GMT
12
+
13
+ ### Updates
14
+
15
+ - Promote APIs to beta.
16
+ - Provide functions for obtaining URLs from mesh export service.
4
17
 
5
18
  ## 4.0.2
6
19
  Wed, 21 Jun 2023 22:04:43 GMT
@@ -23,6 +36,16 @@ Mon, 22 May 2023 15:34:14 GMT
23
36
  - Ensure fitting the view fits to the extents of the currently-viewed models.
24
37
  - Add new experimental package providing alternate technique for visualizing iModels.
25
38
 
39
+ ## 3.7.11
40
+ Tue, 11 Jul 2023 17:17:22 GMT
41
+
42
+ _Version update only_
43
+
44
+ ## 3.7.10
45
+ Wed, 05 Jul 2023 13:41:21 GMT
46
+
47
+ _Version update only_
48
+
26
49
  ## 3.7.9
27
50
  Tue, 20 Jun 2023 12:51:02 GMT
28
51
 
@@ -1,17 +1,95 @@
1
+ import { AccessToken } from "@itwin/core-bentley";
1
2
  import { IModelConnection, SpatialTileTreeReferences } from "@itwin/core-frontend";
2
3
  /** A function that can provide the base URL where a tileset representing all of the spatial models in a given iModel are stored.
3
4
  * The tileset is expected to reside at "baseUrl/tileset.json" and to have been produced by the [mesh export service](https://developer.bentley.com/apis/mesh-export/).
4
5
  * If no such tileset exists for the given iModel, return `undefined`.
5
6
  * @see [[FrontendTilesOptions.computeSpatialTilesetBaseUrl]].
6
- * @alpha
7
+ * @beta
7
8
  */
8
9
  export type ComputeSpatialTilesetBaseUrl = (iModel: IModelConnection) => Promise<URL | undefined>;
10
+ /** Represents the result of a [mesh export](https://developer.bentley.com/apis/mesh-export/operations/get-export/#export).
11
+ * @see [[queryCompletedMeshExports]].
12
+ * @beta
13
+ */
14
+ export interface MeshExport {
15
+ id: string;
16
+ displayName: string;
17
+ status: string;
18
+ request: {
19
+ iModelId: string;
20
+ changesetId: string;
21
+ exportType: string;
22
+ geometryOptions: any;
23
+ viewDefinitionFilter: any;
24
+ };
25
+ _links: {
26
+ mesh: {
27
+ href: string;
28
+ };
29
+ };
30
+ }
31
+ /** Exposed strictly for tests.
32
+ * @internal
33
+ */
34
+ export interface MeshExports {
35
+ exports: MeshExport[];
36
+ _links: {
37
+ next?: {
38
+ href: string;
39
+ };
40
+ };
41
+ }
42
+ /** Arguments supplied to [[queryMeshExports]].
43
+ * @beta
44
+ */
45
+ export interface QueryMeshExportsArgs {
46
+ /** The token used to access the mesh export service. */
47
+ accessToken: AccessToken;
48
+ /** The Id of the iModel for which to query exports. */
49
+ iModelId: string;
50
+ /** If defined, constrains the query to exports produced from the specified changeset. */
51
+ changesetId?: string;
52
+ /** Chiefly used in testing environments. */
53
+ urlPrefix?: string;
54
+ /** If true, exports whose status is not "Complete" (indicating the export successfully finished) will be included in the results. */
55
+ includeIncomplete?: boolean;
56
+ }
57
+ /** Query the [mesh export service](https://developer.bentley.com/apis/mesh-export/operations/get-exports/) for exports of type "IMODEL" matching
58
+ * the specified criteria.
59
+ * The exports are sorted from most-recently- to least-recently-produced.
60
+ * @beta
61
+ */
62
+ export declare function queryMeshExports(args: QueryMeshExportsArgs): AsyncIterableIterator<MeshExport>;
63
+ /** Arguments supplied to [[obtainMeshExportTilesetUrl]].
64
+ * @beta
65
+ */
66
+ export interface ObtainMeshExportTilesetUrlArgs {
67
+ /** The iModel for which to obtain a tileset URl. */
68
+ iModel: IModelConnection;
69
+ /** The token used to access the mesh export service. */
70
+ accessToken: AccessToken;
71
+ /** Chiefly used in testing environments. */
72
+ urlPrefix?: string;
73
+ /** If true, only exports produced for `iModel`'s specific changeset will be considered; otherwise, if no exports are found for the changeset,
74
+ * the most recent export for any changeset will be used.
75
+ */
76
+ requireExactChangeset?: boolean;
77
+ }
78
+ /** Obtains a URL pointing to a tileset appropriate for visualizing a specific iModel.
79
+ * [[queryCompletedMeshExports]] is used to obtain a list of available exports. By default, the list is sorted from most to least recently-exported.
80
+ * The first export matching the iModel's changeset is selected; or, if no such export exists, the first export in the list is selected.
81
+ * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.
82
+ * @beta
83
+ */
84
+ export declare function obtainMeshExportTilesetUrl(args: ObtainMeshExportTilesetUrlArgs): Promise<URL | undefined>;
9
85
  /** Options supplied to [[initializeFrontendTiles]].
10
- * @alpha
86
+ * @beta
11
87
  */
12
88
  export interface FrontendTilesOptions {
13
- /** Provide the base URL for the pre-published tileset for a given iModel. */
14
- computeSpatialTilesetBaseUrl: ComputeSpatialTilesetBaseUrl;
89
+ /** Provide the base URL for the pre-published tileset for a given iModel.
90
+ * If omitted, [[obtainMeshExportTilesetUrl]] will be invoked with default arguments, using the access token provided by [[IModelApp]].
91
+ */
92
+ computeSpatialTilesetBaseUrl?: ComputeSpatialTilesetBaseUrl;
15
93
  /** The maximum number of levels in the tile tree to skip loading if they do not provide the desired level of detail for the current view.
16
94
  * Default: 4.
17
95
  * Reducing this value will load more intermediate tiles, which causes more gradual refinement: low-resolution tiles will display quickly, followed more gradually by
@@ -27,7 +105,7 @@ export declare const createFallbackSpatialTileTreeReferences: typeof SpatialTile
27
105
  /** @internal */
28
106
  export declare function getMaxLevelsToSkip(): number;
29
107
  /** Initialize the frontend-tiles package to obtain tiles for spatial views.
30
- * @alpha
108
+ * @beta
31
109
  */
32
110
  export declare function initializeFrontendTiles(options: FrontendTilesOptions): void;
33
111
  //# sourceMappingURL=FrontendTiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FrontendTiles.d.ts","sourceRoot":"","sources":["../../src/FrontendTiles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAoB,MAAM,sBAAsB,CAAC;AAGrG;;;;;GAKG;AACH,MAAM,MAAM,4BAA4B,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;AAElG;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6EAA6E;IAC7E,4BAA4B,EAAE,4BAA4B,CAAC;IAC3D;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,gBAAgB;AAChB,eAAO,MAAM,uCAAuC,yCAAmC,CAAC;AAIxF,gBAAgB;AAChB,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAK3E"}
1
+ {"version":3,"file":"FrontendTiles.d.ts","sourceRoot":"","sources":["../../src/FrontendTiles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAU,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAa,gBAAgB,EAAE,yBAAyB,EAAoB,MAAM,sBAAsB,CAAC;AAIhH;;;;;GAKG;AACH,MAAM,MAAM,4BAA4B,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;AAWlG;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,GAAG,CAAC;QACrB,oBAAoB,EAAE,GAAG,CAAC;KAC3B,CAAC;IAGF,MAAM,EAAE;QAC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IAAI,MAAM,CAE3C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAS3E"}
@@ -4,9 +4,90 @@
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.initializeFrontendTiles = exports.getMaxLevelsToSkip = exports.createFallbackSpatialTileTreeReferences = void 0;
7
+ exports.initializeFrontendTiles = exports.getMaxLevelsToSkip = exports.createFallbackSpatialTileTreeReferences = exports.obtainMeshExportTilesetUrl = exports.queryMeshExports = void 0;
8
+ const core_bentley_1 = require("@itwin/core-bentley");
8
9
  const core_frontend_1 = require("@itwin/core-frontend");
10
+ const LoggerCategory_1 = require("./LoggerCategory");
9
11
  const BatchedSpatialTileTreeRefs_1 = require("./BatchedSpatialTileTreeRefs");
12
+ function createMeshExportServiceQueryUrl(args) {
13
+ const prefix = args.urlPrefix ?? "";
14
+ let url = `https://${prefix}api.bentley.com/mesh-export/?iModelId=${args.iModelId}&$orderBy=date:desc`;
15
+ if (args.changesetId)
16
+ url = `${url}&changesetId=${args.changesetId}`;
17
+ return url;
18
+ }
19
+ /** Query the [mesh export service](https://developer.bentley.com/apis/mesh-export/operations/get-exports/) for exports of type "IMODEL" matching
20
+ * the specified criteria.
21
+ * The exports are sorted from most-recently- to least-recently-produced.
22
+ * @beta
23
+ */
24
+ async function* queryMeshExports(args) {
25
+ const headers = {
26
+ /* eslint-disable-next-line @typescript-eslint/naming-convention */
27
+ Authorization: args.accessToken ?? await core_frontend_1.IModelApp.getAccessToken(),
28
+ /* eslint-disable-next-line @typescript-eslint/naming-convention */
29
+ Accept: "application/vnd.bentley.itwin-platform.v1+json",
30
+ /* eslint-disable-next-line @typescript-eslint/naming-convention */
31
+ Prefer: "return=representation",
32
+ };
33
+ let url = createMeshExportServiceQueryUrl(args);
34
+ while (url) {
35
+ let result;
36
+ try {
37
+ const response = await fetch(url, { headers });
38
+ result = await response.json();
39
+ }
40
+ catch (err) {
41
+ core_bentley_1.Logger.logException(LoggerCategory_1.loggerCategory, err);
42
+ core_bentley_1.Logger.logError(LoggerCategory_1.loggerCategory, `Failed loading exports for iModel ${args.iModelId}`);
43
+ break;
44
+ }
45
+ const foundExports = result.exports.filter((x) => x.request.exportType === "IMODEL" && (args.includeIncomplete || x.status === "Complete"));
46
+ for (const foundExport of foundExports)
47
+ yield foundExport;
48
+ url = result._links.next?.href;
49
+ }
50
+ }
51
+ exports.queryMeshExports = queryMeshExports;
52
+ /** Obtains a URL pointing to a tileset appropriate for visualizing a specific iModel.
53
+ * [[queryCompletedMeshExports]] is used to obtain a list of available exports. By default, the list is sorted from most to least recently-exported.
54
+ * The first export matching the iModel's changeset is selected; or, if no such export exists, the first export in the list is selected.
55
+ * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.
56
+ * @beta
57
+ */
58
+ async function obtainMeshExportTilesetUrl(args) {
59
+ if (!args.iModel.iModelId) {
60
+ core_bentley_1.Logger.logInfo(LoggerCategory_1.loggerCategory, "Cannot obtain exports for an iModel with no iModelId");
61
+ return undefined;
62
+ }
63
+ const queryArgs = {
64
+ accessToken: args.accessToken,
65
+ iModelId: args.iModel.iModelId,
66
+ changesetId: args.iModel.changeset.id,
67
+ urlPrefix: args.urlPrefix,
68
+ };
69
+ let selectedExport;
70
+ for await (const exp of queryMeshExports(queryArgs)) {
71
+ selectedExport = exp;
72
+ break;
73
+ }
74
+ if (!selectedExport && !args.requireExactChangeset) {
75
+ queryArgs.changesetId = undefined;
76
+ for await (const exp of queryMeshExports(queryArgs)) {
77
+ selectedExport = exp;
78
+ core_bentley_1.Logger.logInfo(LoggerCategory_1.loggerCategory, `No exports for iModel ${args.iModel.iModelId} for changeset ${args.iModel.changeset.id}; falling back to most recent`);
79
+ break;
80
+ }
81
+ }
82
+ if (!selectedExport) {
83
+ core_bentley_1.Logger.logInfo(LoggerCategory_1.loggerCategory, `No exports available for iModel ${args.iModel.iModelId}`);
84
+ return undefined;
85
+ }
86
+ const url = new URL(selectedExport._links.mesh.href);
87
+ url.pathname = `${url.pathname}/tileset.json`;
88
+ return url;
89
+ }
90
+ exports.obtainMeshExportTilesetUrl = obtainMeshExportTilesetUrl;
10
91
  /** @internal */
11
92
  exports.createFallbackSpatialTileTreeReferences = core_frontend_1.SpatialTileTreeReferences.create;
12
93
  let maxLevelsToSkip = 4;
@@ -16,12 +97,13 @@ function getMaxLevelsToSkip() {
16
97
  }
17
98
  exports.getMaxLevelsToSkip = getMaxLevelsToSkip;
18
99
  /** Initialize the frontend-tiles package to obtain tiles for spatial views.
19
- * @alpha
100
+ * @beta
20
101
  */
21
102
  function initializeFrontendTiles(options) {
22
103
  if (undefined !== options.maxLevelsToSkip && options.maxLevelsToSkip >= 0)
23
104
  maxLevelsToSkip = options.maxLevelsToSkip;
24
- core_frontend_1.SpatialTileTreeReferences.create = (view) => (0, BatchedSpatialTileTreeRefs_1.createBatchedSpatialTileTreeReferences)(view, options.computeSpatialTilesetBaseUrl);
105
+ const computeUrl = options.computeSpatialTilesetBaseUrl ?? (async (iModel) => obtainMeshExportTilesetUrl({ iModel, accessToken: await core_frontend_1.IModelApp.getAccessToken() }));
106
+ core_frontend_1.SpatialTileTreeReferences.create = (view) => (0, BatchedSpatialTileTreeRefs_1.createBatchedSpatialTileTreeReferences)(view, computeUrl);
25
107
  }
26
108
  exports.initializeFrontendTiles = initializeFrontendTiles;
27
109
  //# sourceMappingURL=FrontendTiles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FrontendTiles.js","sourceRoot":"","sources":["../../src/FrontendTiles.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,wDAAqG;AACrG,6EAAsF;AA2BtF,gBAAgB;AACH,QAAA,uCAAuC,GAAG,yCAAyB,CAAC,MAAM,CAAC;AAExF,IAAI,eAAe,GAAG,CAAC,CAAC;AAExB,gBAAgB;AAChB,SAAgB,kBAAkB;IAChC,OAAO,eAAe,CAAC;AACzB,CAAC;AAFD,gDAEC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,OAA6B;IACnE,IAAI,SAAS,KAAK,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC,eAAe,IAAI,CAAC;QACvE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAE5C,yCAAyB,CAAC,MAAM,GAAG,CAAC,IAAsB,EAAE,EAAE,CAAC,IAAA,mEAAsC,EAAC,IAAI,EAAE,OAAO,CAAC,4BAA4B,CAAC,CAAC;AACpJ,CAAC;AALD,0DAKC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { IModelConnection, SpatialTileTreeReferences, SpatialViewState } from \"@itwin/core-frontend\";\r\nimport { createBatchedSpatialTileTreeReferences } from \"./BatchedSpatialTileTreeRefs\";\r\n\r\n/** A function that can provide the base URL where a tileset representing all of the spatial models in a given iModel are stored.\r\n * The tileset is expected to reside at \"baseUrl/tileset.json\" and to have been produced by the [mesh export service](https://developer.bentley.com/apis/mesh-export/).\r\n * If no such tileset exists for the given iModel, return `undefined`.\r\n * @see [[FrontendTilesOptions.computeSpatialTilesetBaseUrl]].\r\n * @alpha\r\n */\r\nexport type ComputeSpatialTilesetBaseUrl = (iModel: IModelConnection) => Promise<URL | undefined>;\r\n\r\n/** Options supplied to [[initializeFrontendTiles]].\r\n * @alpha\r\n */\r\nexport interface FrontendTilesOptions {\r\n /** Provide the base URL for the pre-published tileset for a given iModel. */\r\n computeSpatialTilesetBaseUrl: ComputeSpatialTilesetBaseUrl;\r\n /** The maximum number of levels in the tile tree to skip loading if they do not provide the desired level of detail for the current view.\r\n * Default: 4.\r\n * Reducing this value will load more intermediate tiles, which causes more gradual refinement: low-resolution tiles will display quickly, followed more gradually by\r\n * successively higher-resolution ones.\r\n * Increasing the value jumps more directly to tiles of the exact level of detail desired, which may load more, smaller tiles up-front, leaving some areas of the view\r\n * vacant for longer; and when zooming out some newly-exposed areas of the view may remain vacant for longer because no lower-resolution tiles are initially available to\r\n * fill them. However, tiles close to the viewer (and therefore likely of most interest to them) will refine to an appropriate level of detail more quickly.\r\n */\r\n maxLevelsToSkip?: number;\r\n}\r\n\r\n/** @internal */\r\nexport const createFallbackSpatialTileTreeReferences = SpatialTileTreeReferences.create;\r\n\r\nlet maxLevelsToSkip = 4;\r\n\r\n/** @internal */\r\nexport function getMaxLevelsToSkip(): number {\r\n return maxLevelsToSkip;\r\n}\r\n\r\n/** Initialize the frontend-tiles package to obtain tiles for spatial views.\r\n * @alpha\r\n */\r\nexport function initializeFrontendTiles(options: FrontendTilesOptions): void {\r\n if (undefined !== options.maxLevelsToSkip && options.maxLevelsToSkip >= 0)\r\n maxLevelsToSkip = options.maxLevelsToSkip;\r\n\r\n SpatialTileTreeReferences.create = (view: SpatialViewState) => createBatchedSpatialTileTreeReferences(view, options.computeSpatialTilesetBaseUrl);\r\n}\r\n"]}
1
+ {"version":3,"file":"FrontendTiles.js","sourceRoot":"","sources":["../../src/FrontendTiles.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAA0D;AAC1D,wDAAgH;AAChH,qDAAkD;AAClD,6EAAsF;AAUtF,SAAS,+BAA+B,CAAC,IAAoE;IAC3G,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;IACpC,IAAI,GAAG,GAAG,WAAW,MAAM,yCAAyC,IAAI,CAAC,QAAQ,qBAAqB,CAAC;IACvG,IAAI,IAAI,CAAC,WAAW;QAClB,GAAG,GAAG,GAAG,GAAG,gBAAgB,IAAI,CAAC,WAAW,EAAE,CAAC;IAEjD,OAAO,GAAG,CAAC;AACb,CAAC;AAwDD;;;;GAIG;AACI,KAAK,SAAU,CAAC,CAAC,gBAAgB,CAAC,IAA0B;IACjE,MAAM,OAAO,GAAG;QACd,m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AAgB;AAChB,SAAgB,kBAAkB;IAChC,OAAO,eAAe,CAAC;AACzB,CAAC;AAFD,gDAEC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,OAA6B;IACnE,IAAI,SAAS,KAAK,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC,eAAe,IAAI,CAAC;QACvE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAE5C,MAAM,UAAU,GAAG,OAAO,CAAC,4BAA4B,IAAI,CACzD,KAAK,EAAE,MAAwB,EAAE,EAAE,CAAC,0BAA0B,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,yBAAS,CAAC,cAAc,EAAE,EAAE,CAAC,CAC1H,CAAC;IAEF,yCAAyB,CAAC,MAAM,GAAG,CAAC,IAAsB,EAAE,EAAE,CAAC,IAAA,mEAAsC,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAC1H,CAAC;AATD,0DASC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { AccessToken, Logger } from \"@itwin/core-bentley\";\r\nimport { IModelApp, IModelConnection, SpatialTileTreeReferences, SpatialViewState } from \"@itwin/core-frontend\";\r\nimport { loggerCategory } from \"./LoggerCategory\";\r\nimport { createBatchedSpatialTileTreeReferences } from \"./BatchedSpatialTileTreeRefs\";\r\n\r\n/** A function that can provide the base URL where a tileset representing all of the spatial models in a given iModel are stored.\r\n * The tileset is expected to reside at \"baseUrl/tileset.json\" and to have been produced by the [mesh export service](https://developer.bentley.com/apis/mesh-export/).\r\n * If no such tileset exists for the given iModel, return `undefined`.\r\n * @see [[FrontendTilesOptions.computeSpatialTilesetBaseUrl]].\r\n * @beta\r\n */\r\nexport type ComputeSpatialTilesetBaseUrl = (iModel: IModelConnection) => Promise<URL | undefined>;\r\n\r\nfunction createMeshExportServiceQueryUrl(args: { iModelId: string, urlPrefix?: string, changesetId?: string }): string {\r\n const prefix = args.urlPrefix ?? \"\";\r\n let url = `https://${prefix}api.bentley.com/mesh-export/?iModelId=${args.iModelId}&$orderBy=date:desc`;\r\n if (args.changesetId)\r\n url = `${url}&changesetId=${args.changesetId}`;\r\n\r\n return url;\r\n}\r\n\r\n/** Represents the result of a [mesh export](https://developer.bentley.com/apis/mesh-export/operations/get-export/#export).\r\n * @see [[queryCompletedMeshExports]].\r\n * @beta\r\n */\r\nexport interface MeshExport {\r\n id: string;\r\n displayName: string;\r\n status: string;\r\n request: {\r\n iModelId: string;\r\n changesetId: string;\r\n exportType: string;\r\n geometryOptions: any;\r\n viewDefinitionFilter: any;\r\n };\r\n\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n _links: {\r\n mesh: {\r\n href: string;\r\n };\r\n };\r\n}\r\n\r\n/** Exposed strictly for tests.\r\n * @internal\r\n */\r\nexport interface MeshExports {\r\n exports: MeshExport[];\r\n\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n _links: {\r\n next?: {\r\n href: string;\r\n };\r\n };\r\n}\r\n\r\n/** Arguments supplied to [[queryMeshExports]].\r\n * @beta\r\n */\r\nexport interface QueryMeshExportsArgs {\r\n /** The token used to access the mesh export service. */\r\n accessToken: AccessToken;\r\n /** The Id of the iModel for which to query exports. */\r\n iModelId: string;\r\n /** If defined, constrains the query to exports produced from the specified changeset. */\r\n changesetId?: string;\r\n /** Chiefly used in testing environments. */\r\n urlPrefix?: string;\r\n /** If true, exports whose status is not \"Complete\" (indicating the export successfully finished) will be included in the results. */\r\n includeIncomplete?: boolean;\r\n}\r\n\r\n/** Query the [mesh export service](https://developer.bentley.com/apis/mesh-export/operations/get-exports/) for exports of type \"IMODEL\" matching\r\n * the specified criteria.\r\n * The exports are sorted from most-recently- to least-recently-produced.\r\n * @beta\r\n */\r\nexport async function * queryMeshExports(args: QueryMeshExportsArgs): AsyncIterableIterator<MeshExport> {\r\n const headers = {\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n Authorization: args.accessToken ?? await IModelApp.getAccessToken(),\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n Accept: \"application/vnd.bentley.itwin-platform.v1+json\",\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n Prefer: \"return=representation\",\r\n };\r\n\r\n let url: string | undefined = createMeshExportServiceQueryUrl(args);\r\n while (url) {\r\n let result;\r\n try {\r\n const response = await fetch(url, { headers });\r\n result = await response.json() as MeshExports;\r\n } catch (err) {\r\n Logger.logException(loggerCategory, err);\r\n Logger.logError(loggerCategory, `Failed loading exports for iModel ${args.iModelId}`);\r\n break;\r\n }\r\n\r\n const foundExports = result.exports.filter((x) => x.request.exportType === \"IMODEL\" && (args.includeIncomplete || x.status === \"Complete\"));\r\n for (const foundExport of foundExports)\r\n yield foundExport;\r\n\r\n url = result._links.next?.href;\r\n }\r\n}\r\n\r\n/** Arguments supplied to [[obtainMeshExportTilesetUrl]].\r\n * @beta\r\n */\r\nexport interface ObtainMeshExportTilesetUrlArgs {\r\n /** The iModel for which to obtain a tileset URl. */\r\n iModel: IModelConnection;\r\n /** The token used to access the mesh export service. */\r\n accessToken: AccessToken;\r\n /** Chiefly used in testing environments. */\r\n urlPrefix?: string;\r\n /** If true, only exports produced for `iModel`'s specific changeset will be considered; otherwise, if no exports are found for the changeset,\r\n * the most recent export for any changeset will be used.\r\n */\r\n requireExactChangeset?: boolean;\r\n}\r\n\r\n/** Obtains a URL pointing to a tileset appropriate for visualizing a specific iModel.\r\n * [[queryCompletedMeshExports]] is used to obtain a list of available exports. By default, the list is sorted from most to least recently-exported.\r\n * The first export matching the iModel's changeset is selected; or, if no such export exists, the first export in the list is selected.\r\n * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.\r\n * @beta\r\n */\r\nexport async function obtainMeshExportTilesetUrl(args: ObtainMeshExportTilesetUrlArgs): Promise<URL | undefined> {\r\n if (!args.iModel.iModelId) {\r\n Logger.logInfo(loggerCategory, \"Cannot obtain exports for an iModel with no iModelId\");\r\n return undefined;\r\n }\r\n\r\n const queryArgs: QueryMeshExportsArgs = {\r\n accessToken: args.accessToken,\r\n iModelId: args.iModel.iModelId,\r\n changesetId: args.iModel.changeset.id,\r\n urlPrefix: args.urlPrefix,\r\n };\r\n\r\n let selectedExport;\r\n for await (const exp of queryMeshExports(queryArgs)) {\r\n selectedExport = exp;\r\n break;\r\n }\r\n\r\n if (!selectedExport && !args.requireExactChangeset) {\r\n queryArgs.changesetId = undefined;\r\n for await (const exp of queryMeshExports(queryArgs)) {\r\n selectedExport = exp;\r\n Logger.logInfo(loggerCategory, `No exports for iModel ${args.iModel.iModelId} for changeset ${args.iModel.changeset.id}; falling back to most recent`);\r\n break;\r\n }\r\n }\r\n\r\n if (!selectedExport) {\r\n Logger.logInfo(loggerCategory, `No exports available for iModel ${args.iModel.iModelId}`);\r\n return undefined;\r\n }\r\n\r\n const url = new URL(selectedExport._links.mesh.href);\r\n url.pathname = `${url.pathname}/tileset.json`;\r\n return url;\r\n}\r\n\r\n/** Options supplied to [[initializeFrontendTiles]].\r\n * @beta\r\n */\r\nexport interface FrontendTilesOptions {\r\n /** Provide the base URL for the pre-published tileset for a given iModel.\r\n * If omitted, [[obtainMeshExportTilesetUrl]] will be invoked with default arguments, using the access token provided by [[IModelApp]].\r\n */\r\n computeSpatialTilesetBaseUrl?: ComputeSpatialTilesetBaseUrl;\r\n /** The maximum number of levels in the tile tree to skip loading if they do not provide the desired level of detail for the current view.\r\n * Default: 4.\r\n * Reducing this value will load more intermediate tiles, which causes more gradual refinement: low-resolution tiles will display quickly, followed more gradually by\r\n * successively higher-resolution ones.\r\n * Increasing the value jumps more directly to tiles of the exact level of detail desired, which may load more, smaller tiles up-front, leaving some areas of the view\r\n * vacant for longer; and when zooming out some newly-exposed areas of the view may remain vacant for longer because no lower-resolution tiles are initially available to\r\n * fill them. However, tiles close to the viewer (and therefore likely of most interest to them) will refine to an appropriate level of detail more quickly.\r\n */\r\n maxLevelsToSkip?: number;\r\n}\r\n\r\n/** @internal */\r\nexport const createFallbackSpatialTileTreeReferences = SpatialTileTreeReferences.create;\r\n\r\nlet maxLevelsToSkip = 4;\r\n\r\n/** @internal */\r\nexport function getMaxLevelsToSkip(): number {\r\n return maxLevelsToSkip;\r\n}\r\n\r\n/** Initialize the frontend-tiles package to obtain tiles for spatial views.\r\n * @beta\r\n */\r\nexport function initializeFrontendTiles(options: FrontendTilesOptions): void {\r\n if (undefined !== options.maxLevelsToSkip && options.maxLevelsToSkip >= 0)\r\n maxLevelsToSkip = options.maxLevelsToSkip;\r\n\r\n const computeUrl = options.computeSpatialTilesetBaseUrl ?? (\r\n async (iModel: IModelConnection) => obtainMeshExportTilesetUrl({ iModel, accessToken: await IModelApp.getAccessToken() })\r\n );\r\n\r\n SpatialTileTreeReferences.create = (view: SpatialViewState) => createBatchedSpatialTileTreeReferences(view, computeUrl);\r\n}\r\n"]}
@@ -1,17 +1,95 @@
1
+ import { AccessToken } from "@itwin/core-bentley";
1
2
  import { IModelConnection, SpatialTileTreeReferences } from "@itwin/core-frontend";
2
3
  /** A function that can provide the base URL where a tileset representing all of the spatial models in a given iModel are stored.
3
4
  * The tileset is expected to reside at "baseUrl/tileset.json" and to have been produced by the [mesh export service](https://developer.bentley.com/apis/mesh-export/).
4
5
  * If no such tileset exists for the given iModel, return `undefined`.
5
6
  * @see [[FrontendTilesOptions.computeSpatialTilesetBaseUrl]].
6
- * @alpha
7
+ * @beta
7
8
  */
8
9
  export type ComputeSpatialTilesetBaseUrl = (iModel: IModelConnection) => Promise<URL | undefined>;
10
+ /** Represents the result of a [mesh export](https://developer.bentley.com/apis/mesh-export/operations/get-export/#export).
11
+ * @see [[queryCompletedMeshExports]].
12
+ * @beta
13
+ */
14
+ export interface MeshExport {
15
+ id: string;
16
+ displayName: string;
17
+ status: string;
18
+ request: {
19
+ iModelId: string;
20
+ changesetId: string;
21
+ exportType: string;
22
+ geometryOptions: any;
23
+ viewDefinitionFilter: any;
24
+ };
25
+ _links: {
26
+ mesh: {
27
+ href: string;
28
+ };
29
+ };
30
+ }
31
+ /** Exposed strictly for tests.
32
+ * @internal
33
+ */
34
+ export interface MeshExports {
35
+ exports: MeshExport[];
36
+ _links: {
37
+ next?: {
38
+ href: string;
39
+ };
40
+ };
41
+ }
42
+ /** Arguments supplied to [[queryMeshExports]].
43
+ * @beta
44
+ */
45
+ export interface QueryMeshExportsArgs {
46
+ /** The token used to access the mesh export service. */
47
+ accessToken: AccessToken;
48
+ /** The Id of the iModel for which to query exports. */
49
+ iModelId: string;
50
+ /** If defined, constrains the query to exports produced from the specified changeset. */
51
+ changesetId?: string;
52
+ /** Chiefly used in testing environments. */
53
+ urlPrefix?: string;
54
+ /** If true, exports whose status is not "Complete" (indicating the export successfully finished) will be included in the results. */
55
+ includeIncomplete?: boolean;
56
+ }
57
+ /** Query the [mesh export service](https://developer.bentley.com/apis/mesh-export/operations/get-exports/) for exports of type "IMODEL" matching
58
+ * the specified criteria.
59
+ * The exports are sorted from most-recently- to least-recently-produced.
60
+ * @beta
61
+ */
62
+ export declare function queryMeshExports(args: QueryMeshExportsArgs): AsyncIterableIterator<MeshExport>;
63
+ /** Arguments supplied to [[obtainMeshExportTilesetUrl]].
64
+ * @beta
65
+ */
66
+ export interface ObtainMeshExportTilesetUrlArgs {
67
+ /** The iModel for which to obtain a tileset URl. */
68
+ iModel: IModelConnection;
69
+ /** The token used to access the mesh export service. */
70
+ accessToken: AccessToken;
71
+ /** Chiefly used in testing environments. */
72
+ urlPrefix?: string;
73
+ /** If true, only exports produced for `iModel`'s specific changeset will be considered; otherwise, if no exports are found for the changeset,
74
+ * the most recent export for any changeset will be used.
75
+ */
76
+ requireExactChangeset?: boolean;
77
+ }
78
+ /** Obtains a URL pointing to a tileset appropriate for visualizing a specific iModel.
79
+ * [[queryCompletedMeshExports]] is used to obtain a list of available exports. By default, the list is sorted from most to least recently-exported.
80
+ * The first export matching the iModel's changeset is selected; or, if no such export exists, the first export in the list is selected.
81
+ * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.
82
+ * @beta
83
+ */
84
+ export declare function obtainMeshExportTilesetUrl(args: ObtainMeshExportTilesetUrlArgs): Promise<URL | undefined>;
9
85
  /** Options supplied to [[initializeFrontendTiles]].
10
- * @alpha
86
+ * @beta
11
87
  */
12
88
  export interface FrontendTilesOptions {
13
- /** Provide the base URL for the pre-published tileset for a given iModel. */
14
- computeSpatialTilesetBaseUrl: ComputeSpatialTilesetBaseUrl;
89
+ /** Provide the base URL for the pre-published tileset for a given iModel.
90
+ * If omitted, [[obtainMeshExportTilesetUrl]] will be invoked with default arguments, using the access token provided by [[IModelApp]].
91
+ */
92
+ computeSpatialTilesetBaseUrl?: ComputeSpatialTilesetBaseUrl;
15
93
  /** The maximum number of levels in the tile tree to skip loading if they do not provide the desired level of detail for the current view.
16
94
  * Default: 4.
17
95
  * Reducing this value will load more intermediate tiles, which causes more gradual refinement: low-resolution tiles will display quickly, followed more gradually by
@@ -27,7 +105,7 @@ export declare const createFallbackSpatialTileTreeReferences: typeof SpatialTile
27
105
  /** @internal */
28
106
  export declare function getMaxLevelsToSkip(): number;
29
107
  /** Initialize the frontend-tiles package to obtain tiles for spatial views.
30
- * @alpha
108
+ * @beta
31
109
  */
32
110
  export declare function initializeFrontendTiles(options: FrontendTilesOptions): void;
33
111
  //# sourceMappingURL=FrontendTiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FrontendTiles.d.ts","sourceRoot":"","sources":["../../src/FrontendTiles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAoB,MAAM,sBAAsB,CAAC;AAGrG;;;;;GAKG;AACH,MAAM,MAAM,4BAA4B,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;AAElG;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6EAA6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C,wDAAwD;IACxD,WAAW,EAAE,WAAW,CAAC;IACzB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qIAAqI;IACrI,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAwB,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,qBAAqB,CAAC,UAAU,CAAC,CA4BtG;AAED;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,oDAAoD;IACpD,MAAM,EAAE,gBAAgB,CAAC;IACzB,wDAAwD;IACxD,WAAW,EAAE,WAAW,CAAC;IACzB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,8BAA8B,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAoC/G;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,4BAA4B,CAAC,EAAE,4BAA4B,CAAC;IAC5D;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,gBAAgB;AAChB,eAAO,MAAM,uCAAuC,yCAAmC,CAAC;AAIxF,gBAAgB;AAChB,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAS3E"}
@@ -2,8 +2,87 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { SpatialTileTreeReferences } from "@itwin/core-frontend";
5
+ import { Logger } from "@itwin/core-bentley";
6
+ import { IModelApp, SpatialTileTreeReferences } from "@itwin/core-frontend";
7
+ import { loggerCategory } from "./LoggerCategory";
6
8
  import { createBatchedSpatialTileTreeReferences } from "./BatchedSpatialTileTreeRefs";
9
+ function createMeshExportServiceQueryUrl(args) {
10
+ const prefix = args.urlPrefix ?? "";
11
+ let url = `https://${prefix}api.bentley.com/mesh-export/?iModelId=${args.iModelId}&$orderBy=date:desc`;
12
+ if (args.changesetId)
13
+ url = `${url}&changesetId=${args.changesetId}`;
14
+ return url;
15
+ }
16
+ /** Query the [mesh export service](https://developer.bentley.com/apis/mesh-export/operations/get-exports/) for exports of type "IMODEL" matching
17
+ * the specified criteria.
18
+ * The exports are sorted from most-recently- to least-recently-produced.
19
+ * @beta
20
+ */
21
+ export async function* queryMeshExports(args) {
22
+ const headers = {
23
+ /* eslint-disable-next-line @typescript-eslint/naming-convention */
24
+ Authorization: args.accessToken ?? await IModelApp.getAccessToken(),
25
+ /* eslint-disable-next-line @typescript-eslint/naming-convention */
26
+ Accept: "application/vnd.bentley.itwin-platform.v1+json",
27
+ /* eslint-disable-next-line @typescript-eslint/naming-convention */
28
+ Prefer: "return=representation",
29
+ };
30
+ let url = createMeshExportServiceQueryUrl(args);
31
+ while (url) {
32
+ let result;
33
+ try {
34
+ const response = await fetch(url, { headers });
35
+ result = await response.json();
36
+ }
37
+ catch (err) {
38
+ Logger.logException(loggerCategory, err);
39
+ Logger.logError(loggerCategory, `Failed loading exports for iModel ${args.iModelId}`);
40
+ break;
41
+ }
42
+ const foundExports = result.exports.filter((x) => x.request.exportType === "IMODEL" && (args.includeIncomplete || x.status === "Complete"));
43
+ for (const foundExport of foundExports)
44
+ yield foundExport;
45
+ url = result._links.next?.href;
46
+ }
47
+ }
48
+ /** Obtains a URL pointing to a tileset appropriate for visualizing a specific iModel.
49
+ * [[queryCompletedMeshExports]] is used to obtain a list of available exports. By default, the list is sorted from most to least recently-exported.
50
+ * The first export matching the iModel's changeset is selected; or, if no such export exists, the first export in the list is selected.
51
+ * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.
52
+ * @beta
53
+ */
54
+ export async function obtainMeshExportTilesetUrl(args) {
55
+ if (!args.iModel.iModelId) {
56
+ Logger.logInfo(loggerCategory, "Cannot obtain exports for an iModel with no iModelId");
57
+ return undefined;
58
+ }
59
+ const queryArgs = {
60
+ accessToken: args.accessToken,
61
+ iModelId: args.iModel.iModelId,
62
+ changesetId: args.iModel.changeset.id,
63
+ urlPrefix: args.urlPrefix,
64
+ };
65
+ let selectedExport;
66
+ for await (const exp of queryMeshExports(queryArgs)) {
67
+ selectedExport = exp;
68
+ break;
69
+ }
70
+ if (!selectedExport && !args.requireExactChangeset) {
71
+ queryArgs.changesetId = undefined;
72
+ for await (const exp of queryMeshExports(queryArgs)) {
73
+ selectedExport = exp;
74
+ Logger.logInfo(loggerCategory, `No exports for iModel ${args.iModel.iModelId} for changeset ${args.iModel.changeset.id}; falling back to most recent`);
75
+ break;
76
+ }
77
+ }
78
+ if (!selectedExport) {
79
+ Logger.logInfo(loggerCategory, `No exports available for iModel ${args.iModel.iModelId}`);
80
+ return undefined;
81
+ }
82
+ const url = new URL(selectedExport._links.mesh.href);
83
+ url.pathname = `${url.pathname}/tileset.json`;
84
+ return url;
85
+ }
7
86
  /** @internal */
8
87
  export const createFallbackSpatialTileTreeReferences = SpatialTileTreeReferences.create;
9
88
  let maxLevelsToSkip = 4;
@@ -12,11 +91,12 @@ export function getMaxLevelsToSkip() {
12
91
  return maxLevelsToSkip;
13
92
  }
14
93
  /** Initialize the frontend-tiles package to obtain tiles for spatial views.
15
- * @alpha
94
+ * @beta
16
95
  */
17
96
  export function initializeFrontendTiles(options) {
18
97
  if (undefined !== options.maxLevelsToSkip && options.maxLevelsToSkip >= 0)
19
98
  maxLevelsToSkip = options.maxLevelsToSkip;
20
- SpatialTileTreeReferences.create = (view) => createBatchedSpatialTileTreeReferences(view, options.computeSpatialTilesetBaseUrl);
99
+ const computeUrl = options.computeSpatialTilesetBaseUrl ?? (async (iModel) => obtainMeshExportTilesetUrl({ iModel, accessToken: await IModelApp.getAccessToken() }));
100
+ SpatialTileTreeReferences.create = (view) => createBatchedSpatialTileTreeReferences(view, computeUrl);
21
101
  }
22
102
  //# sourceMappingURL=FrontendTiles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FrontendTiles.js","sourceRoot":"","sources":["../../src/FrontendTiles.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAoB,yBAAyB,EAAoB,MAAM,sBAAsB,CAAC;AACrG,OAAO,EAAE,sCAAsC,EAAE,MAAM,8BAA8B,CAAC;AA2BtF,gBAAgB;AAChB,MAAM,CAAC,MAAM,uCAAuC,GAAG,yBAAyB,CAAC,MAAM,CAAC;AAExF,IAAI,eAAe,GAAG,CAAC,CAAC;AAExB,gBAAgB;AAChB,MAAM,UAAU,kBAAkB;IAChC,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAA6B;IACnE,IAAI,SAAS,KAAK,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC,eAAe,IAAI,CAAC;QACvE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAE5C,yBAAyB,CAAC,MAAM,GAAG,CAAC,IAAsB,EAAE,EAAE,CAAC,sCAAsC,CAAC,IAAI,EAAE,OAAO,CAAC,4BAA4B,CAAC,CAAC;AACpJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { IModelConnection, SpatialTileTreeReferences, SpatialViewState } from \"@itwin/core-frontend\";\r\nimport { createBatchedSpatialTileTreeReferences } from \"./BatchedSpatialTileTreeRefs\";\r\n\r\n/** A function that can provide the base URL where a tileset representing all of the spatial models in a given iModel are stored.\r\n * The tileset is expected to reside at \"baseUrl/tileset.json\" and to have been produced by the [mesh export service](https://developer.bentley.com/apis/mesh-export/).\r\n * If no such tileset exists for the given iModel, return `undefined`.\r\n * @see [[FrontendTilesOptions.computeSpatialTilesetBaseUrl]].\r\n * @alpha\r\n */\r\nexport type ComputeSpatialTilesetBaseUrl = (iModel: IModelConnection) => Promise<URL | undefined>;\r\n\r\n/** Options supplied to [[initializeFrontendTiles]].\r\n * @alpha\r\n */\r\nexport interface FrontendTilesOptions {\r\n /** Provide the base URL for the pre-published tileset for a given iModel. */\r\n computeSpatialTilesetBaseUrl: ComputeSpatialTilesetBaseUrl;\r\n /** The maximum number of levels in the tile tree to skip loading if they do not provide the desired level of detail for the current view.\r\n * Default: 4.\r\n * Reducing this value will load more intermediate tiles, which causes more gradual refinement: low-resolution tiles will display quickly, followed more gradually by\r\n * successively higher-resolution ones.\r\n * Increasing the value jumps more directly to tiles of the exact level of detail desired, which may load more, smaller tiles up-front, leaving some areas of the view\r\n * vacant for longer; and when zooming out some newly-exposed areas of the view may remain vacant for longer because no lower-resolution tiles are initially available to\r\n * fill them. However, tiles close to the viewer (and therefore likely of most interest to them) will refine to an appropriate level of detail more quickly.\r\n */\r\n maxLevelsToSkip?: number;\r\n}\r\n\r\n/** @internal */\r\nexport const createFallbackSpatialTileTreeReferences = SpatialTileTreeReferences.create;\r\n\r\nlet maxLevelsToSkip = 4;\r\n\r\n/** @internal */\r\nexport function getMaxLevelsToSkip(): number {\r\n return maxLevelsToSkip;\r\n}\r\n\r\n/** Initialize the frontend-tiles package to obtain tiles for spatial views.\r\n * @alpha\r\n */\r\nexport function initializeFrontendTiles(options: FrontendTilesOptions): void {\r\n if (undefined !== options.maxLevelsToSkip && options.maxLevelsToSkip >= 0)\r\n maxLevelsToSkip = options.maxLevelsToSkip;\r\n\r\n SpatialTileTreeReferences.create = (view: SpatialViewState) => createBatchedSpatialTileTreeReferences(view, options.computeSpatialTilesetBaseUrl);\r\n}\r\n"]}
1
+ {"version":3,"file":"F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AAC,CAAC;AAC1H,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { AccessToken, Logger } from \"@itwin/core-bentley\";\r\nimport { IModelApp, IModelConnection, SpatialTileTreeReferences, SpatialViewState } from \"@itwin/core-frontend\";\r\nimport { loggerCategory } from \"./LoggerCategory\";\r\nimport { createBatchedSpatialTileTreeReferences } from \"./BatchedSpatialTileTreeRefs\";\r\n\r\n/** A function that can provide the base URL where a tileset representing all of the spatial models in a given iModel are stored.\r\n * The tileset is expected to reside at \"baseUrl/tileset.json\" and to have been produced by the [mesh export service](https://developer.bentley.com/apis/mesh-export/).\r\n * If no such tileset exists for the given iModel, return `undefined`.\r\n * @see [[FrontendTilesOptions.computeSpatialTilesetBaseUrl]].\r\n * @beta\r\n */\r\nexport type ComputeSpatialTilesetBaseUrl = (iModel: IModelConnection) => Promise<URL | undefined>;\r\n\r\nfunction createMeshExportServiceQueryUrl(args: { iModelId: string, urlPrefix?: string, changesetId?: string }): string {\r\n const prefix = args.urlPrefix ?? \"\";\r\n let url = `https://${prefix}api.bentley.com/mesh-export/?iModelId=${args.iModelId}&$orderBy=date:desc`;\r\n if (args.changesetId)\r\n url = `${url}&changesetId=${args.changesetId}`;\r\n\r\n return url;\r\n}\r\n\r\n/** Represents the result of a [mesh export](https://developer.bentley.com/apis/mesh-export/operations/get-export/#export).\r\n * @see [[queryCompletedMeshExports]].\r\n * @beta\r\n */\r\nexport interface MeshExport {\r\n id: string;\r\n displayName: string;\r\n status: string;\r\n request: {\r\n iModelId: string;\r\n changesetId: string;\r\n exportType: string;\r\n geometryOptions: any;\r\n viewDefinitionFilter: any;\r\n };\r\n\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n _links: {\r\n mesh: {\r\n href: string;\r\n };\r\n };\r\n}\r\n\r\n/** Exposed strictly for tests.\r\n * @internal\r\n */\r\nexport interface MeshExports {\r\n exports: MeshExport[];\r\n\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n _links: {\r\n next?: {\r\n href: string;\r\n };\r\n };\r\n}\r\n\r\n/** Arguments supplied to [[queryMeshExports]].\r\n * @beta\r\n */\r\nexport interface QueryMeshExportsArgs {\r\n /** The token used to access the mesh export service. */\r\n accessToken: AccessToken;\r\n /** The Id of the iModel for which to query exports. */\r\n iModelId: string;\r\n /** If defined, constrains the query to exports produced from the specified changeset. */\r\n changesetId?: string;\r\n /** Chiefly used in testing environments. */\r\n urlPrefix?: string;\r\n /** If true, exports whose status is not \"Complete\" (indicating the export successfully finished) will be included in the results. */\r\n includeIncomplete?: boolean;\r\n}\r\n\r\n/** Query the [mesh export service](https://developer.bentley.com/apis/mesh-export/operations/get-exports/) for exports of type \"IMODEL\" matching\r\n * the specified criteria.\r\n * The exports are sorted from most-recently- to least-recently-produced.\r\n * @beta\r\n */\r\nexport async function * queryMeshExports(args: QueryMeshExportsArgs): AsyncIterableIterator<MeshExport> {\r\n const headers = {\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n Authorization: args.accessToken ?? await IModelApp.getAccessToken(),\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n Accept: \"application/vnd.bentley.itwin-platform.v1+json\",\r\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\r\n Prefer: \"return=representation\",\r\n };\r\n\r\n let url: string | undefined = createMeshExportServiceQueryUrl(args);\r\n while (url) {\r\n let result;\r\n try {\r\n const response = await fetch(url, { headers });\r\n result = await response.json() as MeshExports;\r\n } catch (err) {\r\n Logger.logException(loggerCategory, err);\r\n Logger.logError(loggerCategory, `Failed loading exports for iModel ${args.iModelId}`);\r\n break;\r\n }\r\n\r\n const foundExports = result.exports.filter((x) => x.request.exportType === \"IMODEL\" && (args.includeIncomplete || x.status === \"Complete\"));\r\n for (const foundExport of foundExports)\r\n yield foundExport;\r\n\r\n url = result._links.next?.href;\r\n }\r\n}\r\n\r\n/** Arguments supplied to [[obtainMeshExportTilesetUrl]].\r\n * @beta\r\n */\r\nexport interface ObtainMeshExportTilesetUrlArgs {\r\n /** The iModel for which to obtain a tileset URl. */\r\n iModel: IModelConnection;\r\n /** The token used to access the mesh export service. */\r\n accessToken: AccessToken;\r\n /** Chiefly used in testing environments. */\r\n urlPrefix?: string;\r\n /** If true, only exports produced for `iModel`'s specific changeset will be considered; otherwise, if no exports are found for the changeset,\r\n * the most recent export for any changeset will be used.\r\n */\r\n requireExactChangeset?: boolean;\r\n}\r\n\r\n/** Obtains a URL pointing to a tileset appropriate for visualizing a specific iModel.\r\n * [[queryCompletedMeshExports]] is used to obtain a list of available exports. By default, the list is sorted from most to least recently-exported.\r\n * The first export matching the iModel's changeset is selected; or, if no such export exists, the first export in the list is selected.\r\n * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.\r\n * @beta\r\n */\r\nexport async function obtainMeshExportTilesetUrl(args: ObtainMeshExportTilesetUrlArgs): Promise<URL | undefined> {\r\n if (!args.iModel.iModelId) {\r\n Logger.logInfo(loggerCategory, \"Cannot obtain exports for an iModel with no iModelId\");\r\n return undefined;\r\n }\r\n\r\n const queryArgs: QueryMeshExportsArgs = {\r\n accessToken: args.accessToken,\r\n iModelId: args.iModel.iModelId,\r\n changesetId: args.iModel.changeset.id,\r\n urlPrefix: args.urlPrefix,\r\n };\r\n\r\n let selectedExport;\r\n for await (const exp of queryMeshExports(queryArgs)) {\r\n selectedExport = exp;\r\n break;\r\n }\r\n\r\n if (!selectedExport && !args.requireExactChangeset) {\r\n queryArgs.changesetId = undefined;\r\n for await (const exp of queryMeshExports(queryArgs)) {\r\n selectedExport = exp;\r\n Logger.logInfo(loggerCategory, `No exports for iModel ${args.iModel.iModelId} for changeset ${args.iModel.changeset.id}; falling back to most recent`);\r\n break;\r\n }\r\n }\r\n\r\n if (!selectedExport) {\r\n Logger.logInfo(loggerCategory, `No exports available for iModel ${args.iModel.iModelId}`);\r\n return undefined;\r\n }\r\n\r\n const url = new URL(selectedExport._links.mesh.href);\r\n url.pathname = `${url.pathname}/tileset.json`;\r\n return url;\r\n}\r\n\r\n/** Options supplied to [[initializeFrontendTiles]].\r\n * @beta\r\n */\r\nexport interface FrontendTilesOptions {\r\n /** Provide the base URL for the pre-published tileset for a given iModel.\r\n * If omitted, [[obtainMeshExportTilesetUrl]] will be invoked with default arguments, using the access token provided by [[IModelApp]].\r\n */\r\n computeSpatialTilesetBaseUrl?: ComputeSpatialTilesetBaseUrl;\r\n /** The maximum number of levels in the tile tree to skip loading if they do not provide the desired level of detail for the current view.\r\n * Default: 4.\r\n * Reducing this value will load more intermediate tiles, which causes more gradual refinement: low-resolution tiles will display quickly, followed more gradually by\r\n * successively higher-resolution ones.\r\n * Increasing the value jumps more directly to tiles of the exact level of detail desired, which may load more, smaller tiles up-front, leaving some areas of the view\r\n * vacant for longer; and when zooming out some newly-exposed areas of the view may remain vacant for longer because no lower-resolution tiles are initially available to\r\n * fill them. However, tiles close to the viewer (and therefore likely of most interest to them) will refine to an appropriate level of detail more quickly.\r\n */\r\n maxLevelsToSkip?: number;\r\n}\r\n\r\n/** @internal */\r\nexport const createFallbackSpatialTileTreeReferences = SpatialTileTreeReferences.create;\r\n\r\nlet maxLevelsToSkip = 4;\r\n\r\n/** @internal */\r\nexport function getMaxLevelsToSkip(): number {\r\n return maxLevelsToSkip;\r\n}\r\n\r\n/** Initialize the frontend-tiles package to obtain tiles for spatial views.\r\n * @beta\r\n */\r\nexport function initializeFrontendTiles(options: FrontendTilesOptions): void {\r\n if (undefined !== options.maxLevelsToSkip && options.maxLevelsToSkip >= 0)\r\n maxLevelsToSkip = options.maxLevelsToSkip;\r\n\r\n const computeUrl = options.computeSpatialTilesetBaseUrl ?? (\r\n async (iModel: IModelConnection) => obtainMeshExportTilesetUrl({ iModel, accessToken: await IModelApp.getAccessToken() })\r\n );\r\n\r\n SpatialTileTreeReferences.create = (view: SpatialViewState) => createBatchedSpatialTileTreeReferences(view, computeUrl);\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/frontend-tiles",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Experimental alternative technique for visualizing the contents of iModels",
5
5
  "main": "lib/cjs/frontend-tiles.js",
6
6
  "module": "lib/esm/frontend-tiles.js",
@@ -23,22 +23,36 @@
23
23
  "url": "http://www.bentley.com"
24
24
  },
25
25
  "peerDependencies": {
26
- "@itwin/core-bentley": "4.0.2",
27
- "@itwin/core-frontend": "4.0.2",
28
- "@itwin/core-common": "4.0.2",
29
- "@itwin/core-geometry": "4.0.2"
26
+ "@itwin/core-bentley": "4.0.4",
27
+ "@itwin/core-common": "4.0.4",
28
+ "@itwin/core-frontend": "4.0.4",
29
+ "@itwin/core-geometry": "4.0.4"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@itwin/eslint-plugin": "^4.0.0-dev.33",
33
+ "@types/chai": "4.3.1",
34
+ "@types/chai-as-promised": "^7",
35
+ "@types/mocha": "^8.2.2",
33
36
  "@types/node": "^18.11.5",
37
+ "@types/sinon": "^9.0.0",
38
+ "babel-loader": "~8.2.5",
39
+ "babel-plugin-istanbul": "~6.1.1",
40
+ "chai": "^4.1.2",
41
+ "chai-as-promised": "^7",
34
42
  "eslint": "^8.36.0",
43
+ "glob": "^7.1.2",
44
+ "mocha": "^10.0.0",
35
45
  "rimraf": "^3.0.2",
46
+ "sinon": "^9.0.2",
47
+ "source-map-loader": "^4.0.0",
36
48
  "typescript": "~5.0.2",
37
- "@itwin/core-frontend": "4.0.2",
38
- "@itwin/build-tools": "4.0.2",
39
- "@itwin/core-bentley": "4.0.2",
40
- "@itwin/core-common": "4.0.2",
41
- "@itwin/core-geometry": "4.0.2"
49
+ "webpack": "^5.76.0",
50
+ "@itwin/core-frontend": "4.0.4",
51
+ "@itwin/build-tools": "4.0.4",
52
+ "@itwin/core-bentley": "4.0.4",
53
+ "@itwin/certa": "4.0.4",
54
+ "@itwin/core-common": "4.0.4",
55
+ "@itwin/core-geometry": "4.0.4"
42
56
  },
43
57
  "eslintConfig": {
44
58
  "plugins": [
@@ -51,10 +65,11 @@
51
65
  "build:cjs": "tsc 1>&2 --outDir lib/cjs",
52
66
  "build:esm": "tsc 1>&2 --module ES2020 --outDir lib/esm",
53
67
  "clean": "rimraf lib .rush/temp/package-deps*.json",
68
+ "cover": "npm -s test",
54
69
  "docs": "",
55
70
  "extract-api": "betools extract-api --entry=frontend-tiles",
56
71
  "lint": "eslint -f visualstudio \"./src/**/*.ts\" 1>&2",
57
- "test": "",
58
- "cover": ""
72
+ "test": "npm run -s webpackTests && certa -r chrome",
73
+ "webpackTests": "webpack --config ./src/test/utils/webpack-config.js 1>&2"
59
74
  }
60
75
  }
@@ -1,3 +0,0 @@
1
- This project was not found in the local build cache. Querying the cloud build cache.
2
- This project was not found in the build cache.
3
- Invoking: npm run -s build:cjs && npm run -s build:esm
@@ -1,3 +0,0 @@
1
- {
2
- "nonCachedDurationMs": 12306.159400001168
3
- }