@itwin/core-frontend 5.14.0-dev.12 → 5.14.0-dev.15
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 +6 -1
- package/lib/cjs/GeoServices.d.ts +3 -0
- package/lib/cjs/GeoServices.d.ts.map +1 -1
- package/lib/cjs/GeoServices.js +8 -1
- package/lib/cjs/GeoServices.js.map +1 -1
- package/lib/cjs/extension/ExtensionAdmin.d.ts +0 -2
- package/lib/cjs/extension/ExtensionAdmin.d.ts.map +1 -1
- package/lib/cjs/extension/ExtensionAdmin.js +44 -22
- package/lib/cjs/extension/ExtensionAdmin.js.map +1 -1
- package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts +1 -1
- package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts.map +1 -1
- package/lib/cjs/extension/providers/RemoteExtensionProvider.js +2 -2
- package/lib/cjs/extension/providers/RemoteExtensionProvider.js.map +1 -1
- package/lib/cjs/internal/render/webgl/SceneCompositor.d.ts.map +1 -1
- package/lib/cjs/internal/render/webgl/SceneCompositor.js +16 -19
- package/lib/cjs/internal/render/webgl/SceneCompositor.js.map +1 -1
- package/lib/cjs/internal/render/webgl/Target.d.ts +2 -0
- package/lib/cjs/internal/render/webgl/Target.d.ts.map +1 -1
- package/lib/cjs/internal/render/webgl/Target.js +1 -0
- package/lib/cjs/internal/render/webgl/Target.js.map +1 -1
- package/lib/esm/GeoServices.d.ts +3 -0
- package/lib/esm/GeoServices.d.ts.map +1 -1
- package/lib/esm/GeoServices.js +8 -1
- package/lib/esm/GeoServices.js.map +1 -1
- package/lib/esm/extension/ExtensionAdmin.d.ts +0 -2
- package/lib/esm/extension/ExtensionAdmin.d.ts.map +1 -1
- package/lib/esm/extension/ExtensionAdmin.js +44 -22
- package/lib/esm/extension/ExtensionAdmin.js.map +1 -1
- package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts +1 -1
- package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts.map +1 -1
- package/lib/esm/extension/providers/RemoteExtensionProvider.js +2 -2
- package/lib/esm/extension/providers/RemoteExtensionProvider.js.map +1 -1
- package/lib/esm/internal/render/webgl/SceneCompositor.d.ts.map +1 -1
- package/lib/esm/internal/render/webgl/SceneCompositor.js +16 -19
- package/lib/esm/internal/render/webgl/SceneCompositor.js.map +1 -1
- package/lib/esm/internal/render/webgl/Target.d.ts +2 -0
- package/lib/esm/internal/render/webgl/Target.d.ts.map +1 -1
- package/lib/esm/internal/render/webgl/Target.js +1 -0
- package/lib/esm/internal/render/webgl/Target.js.map +1 -1
- package/package.json +20 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Change Log - @itwin/core-frontend
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 18 Sep 2026 15:12:40 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.13.4
|
|
6
|
+
Fri, 18 Sep 2026 15:11:19 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
4
9
|
|
|
5
10
|
## 5.13.3
|
|
6
11
|
Tue, 15 Sep 2026 20:25:28 GMT
|
package/lib/cjs/GeoServices.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { IModelConnection } from "./IModelConnection";
|
|
|
9
9
|
* @internal exported strictly for tests.
|
|
10
10
|
*/
|
|
11
11
|
export interface CoordinateConverterOptions {
|
|
12
|
+
/** Conversion direction included in error diagnostics. */
|
|
13
|
+
direction: "geoToIModel" | "iModelToGeo";
|
|
12
14
|
isIModelClosed: () => boolean;
|
|
13
15
|
/** Asynchronously convert each point. The resultant array should have the same number and order of points as the input. */
|
|
14
16
|
requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;
|
|
@@ -43,6 +45,7 @@ export declare class CoordinateConverter {
|
|
|
43
45
|
protected readonly _maxPointsPerRequest: number;
|
|
44
46
|
protected readonly _isIModelClosed: () => boolean;
|
|
45
47
|
protected readonly _requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;
|
|
48
|
+
private readonly _direction;
|
|
46
49
|
protected _redispatchOnCompletion: boolean;
|
|
47
50
|
get isIdle(): boolean;
|
|
48
51
|
protected toXYAndZ(input: XYZProps, output: WritableXYAndZ): XYAndZ;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeoServices.d.ts","sourceRoot":"","sources":["../../src/GeoServices.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EACG,OAAO,EAAE,UAAU,EAAU,WAAW,EACjD,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,0BAA0B,EAAE,2BAA2B,EAAkB,kBAAkB,EAAE,6BAA6B,EAAE,8BAA8B,EAClI,eAAe,EACxC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,MAAM,OAAO,CAAC;IAC9B,2HAA2H;IAC3H,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAChE,yEAAyE;IACzE,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAUD,KAAK,wBAAwB,GAE3B,MAAM,GAEN,WAAW,GAEX,WAAW,CAAC;AAEd;;;;;;;;;;;;GAYG;AACH,qBAAa,mBAAmB;IAC9B,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC/D,SAAS,CAAC,MAAM,EAAE,wBAAwB,CAAU;IAEpD,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAExC,SAAS,CAAC,SAAS,EAAE,WAAW,CAA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OAAO,CAAC,CAAC;AAEpE;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAE1D,gBAAgB;gBACG,OAAO,EAAE,kBAAkB;IAI9C,gBAAgB;WACF,eAAe,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW;IAgBpE;;;;OAIG;IACI,YAAY,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,YAAY,GAAG,SAAS;CAmBzF"}
|
package/lib/cjs/GeoServices.js
CHANGED
|
@@ -45,6 +45,7 @@ class CoordinateConverter {
|
|
|
45
45
|
_maxPointsPerRequest;
|
|
46
46
|
_isIModelClosed;
|
|
47
47
|
_requestPoints;
|
|
48
|
+
_direction;
|
|
48
49
|
// If true, [[dispatch]] will schedule another dispatch after it receives a response.
|
|
49
50
|
// This is needed when all the points requested after the most recent dispatch were included in the currently-in-flight request -
|
|
50
51
|
// _pending will be empty but new callers will be awaiting the results of the in-flight request.
|
|
@@ -69,6 +70,7 @@ class CoordinateConverter {
|
|
|
69
70
|
this._maxPointsPerRequest = Math.max(1, opts.maxPointsPerRequest ?? 300);
|
|
70
71
|
this._isIModelClosed = opts.isIModelClosed;
|
|
71
72
|
this._requestPoints = opts.requestPoints;
|
|
73
|
+
this._direction = opts.direction;
|
|
72
74
|
this._cache = new core_bentley_1.Dictionary(compareXYAndZ, cloneXYAndZ);
|
|
73
75
|
this._pending = new core_bentley_1.SortedArray(compareXYAndZ, false, cloneXYAndZ);
|
|
74
76
|
this._inflight = new core_bentley_1.SortedArray(compareXYAndZ, false, cloneXYAndZ);
|
|
@@ -103,7 +105,10 @@ class CoordinateConverter {
|
|
|
103
105
|
this._cache.set(requests[j], results[j]);
|
|
104
106
|
}
|
|
105
107
|
}).catch((err) => {
|
|
106
|
-
core_bentley_1.Logger.logError(`${FrontendLoggerCategory_1.FrontendLoggerCategory.Package}.geoservices`, err)
|
|
108
|
+
core_bentley_1.Logger.logError(`${FrontendLoggerCategory_1.FrontendLoggerCategory.Package}.geoservices`, err, () => ({
|
|
109
|
+
direction: this._direction,
|
|
110
|
+
pointCount: requests.length,
|
|
111
|
+
}));
|
|
107
112
|
});
|
|
108
113
|
promises.push(promise);
|
|
109
114
|
}
|
|
@@ -200,10 +205,12 @@ class GeoConverter {
|
|
|
200
205
|
constructor(opts) {
|
|
201
206
|
const isIModelClosed = opts.isIModelClosed;
|
|
202
207
|
this._geoToIModel = new CoordinateConverter({
|
|
208
|
+
direction: "geoToIModel",
|
|
203
209
|
isIModelClosed,
|
|
204
210
|
requestPoints: async (geoCoords) => opts.toIModelCoords({ source: opts.datum, geoCoords }),
|
|
205
211
|
});
|
|
206
212
|
this._iModelToGeo = new CoordinateConverter({
|
|
213
|
+
direction: "iModelToGeo",
|
|
207
214
|
isIModelClosed,
|
|
208
215
|
requestPoints: async (iModelCoords) => opts.fromIModelCoords({ target: opts.datum, iModelCoords }),
|
|
209
216
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeoServices.js","sourceRoot":"","sources":["../../src/GeoServices.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,qBAAqB;AACrB,sDAE6B;AAE7B,oDAG4B;AAE5B,4EAAyE;AAazE,SAAS,aAAa,CAAC,GAAW,EAAE,GAAW;IAC7C,OAAO,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;AAC1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EAAE,CAAC;YACf,SAAS,GAAG,IAAI,YAAY,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAElC,SAAS,CAAC,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE;gBAC5C,IAAI,SAAS,KAAK,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;oBACtC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5DD,kCA4DC","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/** @packageDocumentation\r\n * @module IModelConnection\r\n */\r\n\r\n// cspell:ignore GCRS\r\nimport {\r\n assert, BeEvent, Dictionary, Logger, SortedArray,\r\n} from \"@itwin/core-bentley\";\r\nimport { WritableXYAndZ, XYAndZ, XYZProps } from \"@itwin/core-geometry\";\r\nimport {\r\n GeoCoordinatesRequestProps, GeoCoordinatesResponseProps, GeoCoordStatus, GeographicCRSProps, IModelCoordinatesRequestProps, IModelCoordinatesResponseProps,\r\n IModelReadRpcInterface, PointWithStatus,\r\n} from \"@itwin/core-common\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { FrontendLoggerCategory } from \"./common/FrontendLoggerCategory\";\r\n\r\n/** Options used to create a [[CoordinateConverter]].\r\n * @internal exported strictly for tests.\r\n */\r\nexport interface CoordinateConverterOptions {\r\n isIModelClosed: () => boolean;\r\n /** Asynchronously convert each point. The resultant array should have the same number and order of points as the input. */\r\n requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;\r\n /** Maximum number of points to include in each request. Default: 300. */\r\n maxPointsPerRequest?: number;\r\n}\r\n\r\nfunction compareXYAndZ(lhs: XYAndZ, rhs: XYAndZ): number {\r\n return lhs.x - rhs.x || lhs.y - rhs.y || lhs.z - rhs.z;\r\n}\r\n\r\nfunction cloneXYAndZ(xyz: XYAndZ): XYAndZ {\r\n return { x: xyz.x, y: xyz.y, z: xyz.z };\r\n}\r\n\r\ntype CoordinateConverterState =\r\n // No pending requests.\r\n \"idle\" |\r\n // We have scheduled a requestAnimationFrame to dispatch all pending requests.\r\n \"scheduled\" |\r\n // We have dispatched all requests that were pending at the most recent requestAnimationFrame callback.\r\n \"in-flight\";\r\n\r\n/** Performs conversion of coordinates from one coordinate system to another.\r\n * A [[GeoConverter]] has a pair of these for converting between iModel coordinates and geographic coordinates.\r\n * Uses a cache to avoid repeatedly requesting the same points, and a batching strategy to avoid making frequent small requests.\r\n * The cache stores every point that was ever converted by [[convert]]. It is currently permitted to grow to unbounded size.\r\n * The batching works as follows:\r\n * When a conversion is requested via [[convert]], if all the requested points are in the cache, they are returned immediately.\r\n * Otherwise, any points not in the cache and not in the current in-flight request (if any) are placed onto the queue of pending requests.\r\n * A pending request is scheduled if one hasn't already been scheduled, via requestAnimationFrame.\r\n * In the animation frame callback, the pending requests are split into batches of no more than options.maxPointsPerRequest and dispatched to the backend.\r\n * Once the response is received, the results are loaded into and returned from the cache.\r\n * If more calls to convert occurred while the request was in flight, another request is dispatched.\r\n * @internal exported strictly for tests.\r\n */\r\nexport class CoordinateConverter {\r\n protected readonly _cache: Dictionary<XYAndZ, PointWithStatus>;\r\n protected _state: CoordinateConverterState = \"idle\";\r\n // The accumulated set of points to be converted by the next request.\r\n protected _pending: SortedArray<XYAndZ>;\r\n // The set of points that were included in the current in-flight request, if any.\r\n protected _inflight: SortedArray<XYAndZ>;\r\n // An event fired when the next request completes.\r\n protected _onCompleted = new BeEvent<() => void>();\r\n // Used for creating cache keys (XYAndZ) from XYZProps without having to allocate temporary objects.\r\n protected readonly _scratchXYZ = { x: 0, y: 0, z: 0 };\r\n protected readonly _maxPointsPerRequest: number;\r\n protected readonly _isIModelClosed: () => boolean;\r\n protected readonly _requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;\r\n // If true, [[dispatch]] will schedule another dispatch after it receives a response.\r\n // This is needed when all the points requested after the most recent dispatch were included in the currently-in-flight request -\r\n // _pending will be empty but new callers will be awaiting the results of the in-flight request.\r\n protected _redispatchOnCompletion = false;\r\n\r\n public get isIdle(): boolean {\r\n return \"idle\" === this._state;\r\n }\r\n\r\n protected toXYAndZ(input: XYZProps, output: WritableXYAndZ): XYAndZ {\r\n if (Array.isArray(input)) {\r\n output.x = input[0] ?? 0;\r\n output.y = input[1] ?? 0;\r\n output.z = input[2] ?? 0;\r\n } else {\r\n output.x = input.x ?? 0;\r\n output.y = input.y ?? 0;\r\n output.z = input.z ?? 0;\r\n }\r\n\r\n return output;\r\n }\r\n\r\n public constructor(opts: CoordinateConverterOptions) {\r\n this._maxPointsPerRequest = Math.max(1, opts.maxPointsPerRequest ?? 300);\r\n this._isIModelClosed = opts.isIModelClosed;\r\n this._requestPoints = opts.requestPoints;\r\n\r\n this._cache = new Dictionary<XYAndZ, PointWithStatus>(compareXYAndZ, cloneXYAndZ);\r\n this._pending = new SortedArray<XYAndZ>(compareXYAndZ, false, cloneXYAndZ);\r\n this._inflight = new SortedArray<XYAndZ>(compareXYAndZ, false, cloneXYAndZ);\r\n }\r\n\r\n protected async dispatch(): Promise<void> {\r\n assert(this._state === \"scheduled\");\r\n if (this._isIModelClosed() || this._pending.isEmpty) {\r\n this._state = \"idle\";\r\n this._onCompleted.raiseEvent();\r\n return;\r\n }\r\n\r\n this._state = \"in-flight\";\r\n\r\n // Ensure subsequently-enqueued requests listen for the *next* response to be received.\r\n const onCompleted = this._onCompleted;\r\n this._onCompleted = new BeEvent<() => void>();\r\n\r\n // Pending requests are now in flight. Start a new list of pending requests. It's cheaper to swap than to allocate new objects.\r\n const inflight = this._pending;\r\n this._pending = this._inflight;\r\n assert(this._pending.isEmpty);\r\n this._inflight = inflight;\r\n\r\n // Split requests if necessary to avoid requesting more than the maximum allowed number of points.\r\n const promises: Array<Promise<void>> = [];\r\n for (let i = 0; i < inflight.length; i += this._maxPointsPerRequest) {\r\n const requests = inflight.slice(i, i + this._maxPointsPerRequest).extractArray();\r\n const promise = this._requestPoints(requests).then((results) => {\r\n if (this._isIModelClosed())\r\n return;\r\n\r\n if (results.length !== requests.length)\r\n Logger.logError(`${FrontendLoggerCategory.Package}.geoservices`, `requested conversion of ${requests.length} points, but received ${results.length} points`);\r\n\r\n for (let j = 0; j < results.length; j++) {\r\n if (j < requests.length)\r\n this._cache.set(requests[j], results[j]);\r\n }\r\n }).catch((err) => {\r\n Logger.logError(`${FrontendLoggerCategory.Package}.geoservices`, err);\r\n });\r\n\r\n promises.push(promise);\r\n }\r\n\r\n await Promise.all(promises);\r\n\r\n assert(this._state === \"in-flight\");\r\n this._state = \"idle\";\r\n this._inflight.clear();\r\n\r\n // If any more pending conversions arrived while awaiting this request, schedule another request.\r\n if (!this._pending.isEmpty || this._redispatchOnCompletion) {\r\n this._redispatchOnCompletion = false;\r\n this.scheduleDispatch(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n // Resolve promises of all callers who were awaiting this request.\r\n onCompleted.raiseEvent();\r\n }\r\n\r\n // Add any points not present in cache to pending request list.\r\n // Return the number of points present in cache.\r\n protected enqueue(points: XYZProps[]): number {\r\n let numInCache = 0;\r\n for (const point of points) {\r\n const xyz = this.toXYAndZ(point, this._scratchXYZ);\r\n if (this._cache.get(xyz))\r\n ++numInCache;\r\n else if (this._inflight.contains(xyz))\r\n this._redispatchOnCompletion = true;\r\n else\r\n this._pending.insert(xyz);\r\n }\r\n\r\n return numInCache;\r\n }\r\n\r\n // Obtain converted points from the cache. The assumption is that every point in `inputs` is already present in the cache.\r\n // Any point not present will be returned unconverted with an error status.\r\n protected getFromCache(inputs: XYZProps[]): PointWithStatus[] {\r\n const outputs: PointWithStatus[] = [];\r\n for (const input of inputs) {\r\n const xyz = this.toXYAndZ(input, this._scratchXYZ);\r\n let output = this._cache.get(xyz);\r\n if (!output)\r\n output = { p: { ...xyz }, s: GeoCoordStatus.CSMapError };\r\n\r\n outputs.push(output);\r\n }\r\n\r\n return outputs;\r\n }\r\n\r\n protected async scheduleDispatch(): Promise<void> {\r\n if (\"idle\" === this._state) {\r\n this._state = \"scheduled\";\r\n requestAnimationFrame(() => {\r\n this.dispatch(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n });\r\n }\r\n\r\n return new Promise((resolve) => {\r\n this._onCompleted.addOnce(() => resolve());\r\n });\r\n }\r\n\r\n public async convert(inputs: XYZProps[]): Promise<{ points: PointWithStatus[], fromCache: number }> {\r\n const fromCache = this.enqueue(inputs);\r\n assert(fromCache >= 0);\r\n assert(fromCache <= inputs.length);\r\n\r\n if (fromCache === inputs.length)\r\n return { points: this.getFromCache(inputs), fromCache };\r\n\r\n await this.scheduleDispatch();\r\n\r\n return { points: this.getFromCache(inputs), fromCache };\r\n }\r\n\r\n public findCached(inputs: XYZProps[]): CachedIModelCoordinatesResponseProps {\r\n const result: Array<PointWithStatus | undefined> = [];\r\n let missing: XYZProps[] | undefined;\r\n for (const input of inputs) {\r\n const key = this.toXYAndZ(input, this._scratchXYZ);\r\n const output = this._cache.get(key);\r\n result.push(output);\r\n if (!output) {\r\n if (!missing)\r\n missing = [];\r\n\r\n missing.push(input);\r\n }\r\n }\r\n\r\n return { result, missing };\r\n }\r\n}\r\n\r\n/** Response to a request to obtain imodel coordinates from cache.\r\n * @internal\r\n */\r\nexport interface CachedIModelCoordinatesResponseProps {\r\n /** An array of the same length as the input array, with undefined entries at indices corresponding to points not found in cache. */\r\n result: Array<PointWithStatus | undefined>;\r\n /** An array of points in the input array which were not found in the cache, or undefined if all points were found in the cache. */\r\n missing?: XYZProps[];\r\n}\r\n\r\n/** Options used to create a [[GeoConverter]].\r\n * @internal exported strictly for tests.\r\n */\r\nexport interface GeoConverterOptions {\r\n readonly datum: string;\r\n isIModelClosed: () => boolean;\r\n toIModelCoords: (request: IModelCoordinatesRequestProps) => Promise<PointWithStatus[]>;\r\n fromIModelCoords: (request: GeoCoordinatesRequestProps) => Promise<PointWithStatus[]>;\r\n}\r\n\r\n/** An object capable of communicating with the backend to convert between coordinates in a geographic coordinate system and coordinates in an [[IModelConnection]]'s own coordinate system.\r\n * @see [[GeoServices.getConverter]] to obtain a converter.\r\n * @see [GeographicCRS]($common) for more information about geographic coordinate reference systems.\r\n * @public\r\n */\r\nexport class GeoConverter {\r\n private readonly _geoToIModel: CoordinateConverter;\r\n private readonly _iModelToGeo: CoordinateConverter;\r\n /** Used for removing this converter from GeoServices' cache after all requests are completed.\r\n * @internal\r\n */\r\n public readonly onAllRequestsCompleted = new BeEvent<() => void>();\r\n\r\n /** @internal */\r\n constructor(opts: GeoConverterOptions) {\r\n const isIModelClosed = opts.isIModelClosed;\r\n this._geoToIModel = new CoordinateConverter({\r\n isIModelClosed,\r\n requestPoints: async (geoCoords: XYAndZ[]) => opts.toIModelCoords({ source: opts.datum, geoCoords }),\r\n });\r\n\r\n this._iModelToGeo = new CoordinateConverter({\r\n isIModelClosed,\r\n requestPoints: async (iModelCoords: XYAndZ[]) => opts.fromIModelCoords({ target: opts.datum, iModelCoords }),\r\n });\r\n }\r\n\r\n /** Convert the specified geographic coordinates into iModel coordinates. */\r\n public async convertToIModelCoords(geoPoints: XYZProps[]): Promise<PointWithStatus[]> {\r\n const result = await this.getIModelCoordinatesFromGeoCoordinates(geoPoints);\r\n return result.iModelCoords;\r\n }\r\n\r\n /** Convert the specified iModel coordinates into geographic coordinates. */\r\n public async convertFromIModelCoords(iModelCoords: XYZProps[]): Promise<PointWithStatus[]> {\r\n const result = await this.getGeoCoordinatesFromIModelCoordinates(iModelCoords);\r\n return result.geoCoords;\r\n }\r\n\r\n /** @internal */\r\n public async getIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): Promise<IModelCoordinatesResponseProps> {\r\n const result = await this._geoToIModel.convert(geoPoints);\r\n this.checkCompletion();\r\n return {\r\n iModelCoords: result.points,\r\n fromCache: result.fromCache,\r\n };\r\n }\r\n\r\n /** @internal */\r\n public async getGeoCoordinatesFromIModelCoordinates(iModelPoints: XYZProps[]): Promise<GeoCoordinatesResponseProps> {\r\n const result = await this._iModelToGeo.convert(iModelPoints);\r\n this.checkCompletion();\r\n return {\r\n geoCoords: result.points,\r\n fromCache: result.fromCache,\r\n };\r\n }\r\n\r\n private checkCompletion(): void {\r\n if (this._geoToIModel.isIdle && this._iModelToGeo.isIdle)\r\n this.onAllRequestsCompleted.raiseEvent();\r\n }\r\n\r\n /** @internal */\r\n public getCachedIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): CachedIModelCoordinatesResponseProps {\r\n return this._geoToIModel.findCached(geoPoints);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport type GeoServicesOptions = Omit<GeoConverterOptions, \"datum\">;\r\n\r\n/** The Geographic Services available for an [[IModelConnection]].\r\n * @see [[IModelConnection.geoServices]] to obtain the GeoServices for a specific iModel.\r\n * @public\r\n */\r\nexport class GeoServices {\r\n private readonly _options: GeoServicesOptions;\r\n /** Each GeoConverter has its own independent request queue and cache of previously-converted points.\r\n * Some callers like RealityTileTree obtain a single GeoConverter and reuse it throughout their own lifetime. Therefore they benefit from both batching and caching, and\r\n * the cache gets deleted once the RealityTileTree becomes disused.\r\n *\r\n * Other callers like IModelConnection.spatialToCartographic obtain a new GeoConverter every time they need one, use it to convert a single point(!), and then discard the converter.\r\n * This entirely prevents batching - e.g., calling spatialToCartographic 20 times in one frame results in 20 http requests.\r\n * To address that, we cache each GeoConverter returned by getConverter until it has converted at least one point and has no further outstanding conversion requests.\r\n * In this way, the converter lives for as long as (and no longer than) any caller is awaiting conversion to/from its datum - it and its cache are deleted once it becomes disused.\r\n * This makes the coordinate caching generally less useful, but at least bounded - and maximizes batching of requests.\r\n */\r\n private readonly _cache = new Map<string, GeoConverter>();\r\n\r\n /** @internal */\r\n public constructor(options: GeoServicesOptions) {\r\n this._options = options;\r\n }\r\n\r\n /** @internal */\r\n public static createForIModel(iModel: IModelConnection): GeoServices {\r\n return new GeoServices({\r\n isIModelClosed: () => iModel.isClosed,\r\n toIModelCoords: async (request) => {\r\n const rpc = IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);\r\n const response = await rpc.getIModelCoordinatesFromGeoCoordinates(iModel.getRpcProps(), request);\r\n return response.iModelCoords;\r\n },\r\n fromIModelCoords: async (request) => {\r\n const rpc = IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);\r\n const response = await rpc.getGeoCoordinatesFromIModelCoordinates(iModel.getRpcProps(), request);\r\n return response.geoCoords;\r\n },\r\n });\r\n }\r\n\r\n /** Obtain a converter that can convert between a geographic coordinate system and the iModel's own coordinate system.\r\n * @param datumOrGCRS The name or JSON representation of the geographic coordinate system datum - for example, \"WGS84\".\r\n * @returns a converter, or `undefined` if the iModel is not open.\r\n * @note A [[BlankConnection]] has no connection to a backend, so it is never \"open\"; therefore it always returns `undefined`.\r\n */\r\n public getConverter(datumOrGCRS?: string | GeographicCRSProps): GeoConverter | undefined {\r\n if (this._options.isIModelClosed())\r\n return undefined;\r\n\r\n const datum = (typeof datumOrGCRS === \"object\" ? JSON.stringify(datumOrGCRS) : datumOrGCRS) ?? \"\";\r\n\r\n let converter = this._cache.get(datum);\r\n if (!converter) {\r\n converter = new GeoConverter({ ...this._options, datum });\r\n this._cache.set(datum, converter);\r\n\r\n converter.onAllRequestsCompleted.addOnce(() => {\r\n if (converter === this._cache.get(datum))\r\n this._cache.delete(datum);\r\n });\r\n }\r\n\r\n return converter;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"GeoServices.js","sourceRoot":"","sources":["../../src/GeoServices.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,qBAAqB;AACrB,sDAE6B;AAE7B,oDAG4B;AAE5B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oCAAsB,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;gBACpF,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,sCAAsC,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;gBACjG,OAAO,QAAQ,CAAC,SAAS,CAAC;YAC5B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,WAAyC;QAC3D,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE;YAChC,OAAO,SAAS,CAAC;QAEnB,MAAM,KAAK,GAAG,CAAC,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAElG,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS,GAAG,IAAI,YAAY,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAElC,SAAS,CAAC,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE;gBAC5C,IAAI,SAAS,KAAK,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;oBACtC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5DD,kCA4DC","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/** @packageDocumentation\r\n * @module IModelConnection\r\n */\r\n\r\n// cspell:ignore GCRS\r\nimport {\r\n assert, BeEvent, Dictionary, Logger, SortedArray,\r\n} from \"@itwin/core-bentley\";\r\nimport { WritableXYAndZ, XYAndZ, XYZProps } from \"@itwin/core-geometry\";\r\nimport {\r\n GeoCoordinatesRequestProps, GeoCoordinatesResponseProps, GeoCoordStatus, GeographicCRSProps, IModelCoordinatesRequestProps, IModelCoordinatesResponseProps,\r\n IModelReadRpcInterface, PointWithStatus,\r\n} from \"@itwin/core-common\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { FrontendLoggerCategory } from \"./common/FrontendLoggerCategory\";\r\n\r\n/** Options used to create a [[CoordinateConverter]].\r\n * @internal exported strictly for tests.\r\n */\r\nexport interface CoordinateConverterOptions {\r\n /** Conversion direction included in error diagnostics. */\r\n direction: \"geoToIModel\" | \"iModelToGeo\";\r\n isIModelClosed: () => boolean;\r\n /** Asynchronously convert each point. The resultant array should have the same number and order of points as the input. */\r\n requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;\r\n /** Maximum number of points to include in each request. Default: 300. */\r\n maxPointsPerRequest?: number;\r\n}\r\n\r\nfunction compareXYAndZ(lhs: XYAndZ, rhs: XYAndZ): number {\r\n return lhs.x - rhs.x || lhs.y - rhs.y || lhs.z - rhs.z;\r\n}\r\n\r\nfunction cloneXYAndZ(xyz: XYAndZ): XYAndZ {\r\n return { x: xyz.x, y: xyz.y, z: xyz.z };\r\n}\r\n\r\ntype CoordinateConverterState =\r\n // No pending requests.\r\n \"idle\" |\r\n // We have scheduled a requestAnimationFrame to dispatch all pending requests.\r\n \"scheduled\" |\r\n // We have dispatched all requests that were pending at the most recent requestAnimationFrame callback.\r\n \"in-flight\";\r\n\r\n/** Performs conversion of coordinates from one coordinate system to another.\r\n * A [[GeoConverter]] has a pair of these for converting between iModel coordinates and geographic coordinates.\r\n * Uses a cache to avoid repeatedly requesting the same points, and a batching strategy to avoid making frequent small requests.\r\n * The cache stores every point that was ever converted by [[convert]]. It is currently permitted to grow to unbounded size.\r\n * The batching works as follows:\r\n * When a conversion is requested via [[convert]], if all the requested points are in the cache, they are returned immediately.\r\n * Otherwise, any points not in the cache and not in the current in-flight request (if any) are placed onto the queue of pending requests.\r\n * A pending request is scheduled if one hasn't already been scheduled, via requestAnimationFrame.\r\n * In the animation frame callback, the pending requests are split into batches of no more than options.maxPointsPerRequest and dispatched to the backend.\r\n * Once the response is received, the results are loaded into and returned from the cache.\r\n * If more calls to convert occurred while the request was in flight, another request is dispatched.\r\n * @internal exported strictly for tests.\r\n */\r\nexport class CoordinateConverter {\r\n protected readonly _cache: Dictionary<XYAndZ, PointWithStatus>;\r\n protected _state: CoordinateConverterState = \"idle\";\r\n // The accumulated set of points to be converted by the next request.\r\n protected _pending: SortedArray<XYAndZ>;\r\n // The set of points that were included in the current in-flight request, if any.\r\n protected _inflight: SortedArray<XYAndZ>;\r\n // An event fired when the next request completes.\r\n protected _onCompleted = new BeEvent<() => void>();\r\n // Used for creating cache keys (XYAndZ) from XYZProps without having to allocate temporary objects.\r\n protected readonly _scratchXYZ = { x: 0, y: 0, z: 0 };\r\n protected readonly _maxPointsPerRequest: number;\r\n protected readonly _isIModelClosed: () => boolean;\r\n protected readonly _requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;\r\n private readonly _direction: CoordinateConverterOptions[\"direction\"];\r\n // If true, [[dispatch]] will schedule another dispatch after it receives a response.\r\n // This is needed when all the points requested after the most recent dispatch were included in the currently-in-flight request -\r\n // _pending will be empty but new callers will be awaiting the results of the in-flight request.\r\n protected _redispatchOnCompletion = false;\r\n\r\n public get isIdle(): boolean {\r\n return \"idle\" === this._state;\r\n }\r\n\r\n protected toXYAndZ(input: XYZProps, output: WritableXYAndZ): XYAndZ {\r\n if (Array.isArray(input)) {\r\n output.x = input[0] ?? 0;\r\n output.y = input[1] ?? 0;\r\n output.z = input[2] ?? 0;\r\n } else {\r\n output.x = input.x ?? 0;\r\n output.y = input.y ?? 0;\r\n output.z = input.z ?? 0;\r\n }\r\n\r\n return output;\r\n }\r\n\r\n public constructor(opts: CoordinateConverterOptions) {\r\n this._maxPointsPerRequest = Math.max(1, opts.maxPointsPerRequest ?? 300);\r\n this._isIModelClosed = opts.isIModelClosed;\r\n this._requestPoints = opts.requestPoints;\r\n this._direction = opts.direction;\r\n\r\n this._cache = new Dictionary<XYAndZ, PointWithStatus>(compareXYAndZ, cloneXYAndZ);\r\n this._pending = new SortedArray<XYAndZ>(compareXYAndZ, false, cloneXYAndZ);\r\n this._inflight = new SortedArray<XYAndZ>(compareXYAndZ, false, cloneXYAndZ);\r\n }\r\n\r\n protected async dispatch(): Promise<void> {\r\n assert(this._state === \"scheduled\");\r\n if (this._isIModelClosed() || this._pending.isEmpty) {\r\n this._state = \"idle\";\r\n this._onCompleted.raiseEvent();\r\n return;\r\n }\r\n\r\n this._state = \"in-flight\";\r\n\r\n // Ensure subsequently-enqueued requests listen for the *next* response to be received.\r\n const onCompleted = this._onCompleted;\r\n this._onCompleted = new BeEvent<() => void>();\r\n\r\n // Pending requests are now in flight. Start a new list of pending requests. It's cheaper to swap than to allocate new objects.\r\n const inflight = this._pending;\r\n this._pending = this._inflight;\r\n assert(this._pending.isEmpty);\r\n this._inflight = inflight;\r\n\r\n // Split requests if necessary to avoid requesting more than the maximum allowed number of points.\r\n const promises: Array<Promise<void>> = [];\r\n for (let i = 0; i < inflight.length; i += this._maxPointsPerRequest) {\r\n const requests = inflight.slice(i, i + this._maxPointsPerRequest).extractArray();\r\n const promise = this._requestPoints(requests).then((results) => {\r\n if (this._isIModelClosed())\r\n return;\r\n\r\n if (results.length !== requests.length)\r\n Logger.logError(`${FrontendLoggerCategory.Package}.geoservices`, `requested conversion of ${requests.length} points, but received ${results.length} points`);\r\n\r\n for (let j = 0; j < results.length; j++) {\r\n if (j < requests.length)\r\n this._cache.set(requests[j], results[j]);\r\n }\r\n }).catch((err) => {\r\n Logger.logError(`${FrontendLoggerCategory.Package}.geoservices`, err, () => ({\r\n direction: this._direction,\r\n pointCount: requests.length,\r\n }));\r\n });\r\n\r\n promises.push(promise);\r\n }\r\n\r\n await Promise.all(promises);\r\n\r\n assert(this._state === \"in-flight\");\r\n this._state = \"idle\";\r\n this._inflight.clear();\r\n\r\n // If any more pending conversions arrived while awaiting this request, schedule another request.\r\n if (!this._pending.isEmpty || this._redispatchOnCompletion) {\r\n this._redispatchOnCompletion = false;\r\n this.scheduleDispatch(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n // Resolve promises of all callers who were awaiting this request.\r\n onCompleted.raiseEvent();\r\n }\r\n\r\n // Add any points not present in cache to pending request list.\r\n // Return the number of points present in cache.\r\n protected enqueue(points: XYZProps[]): number {\r\n let numInCache = 0;\r\n for (const point of points) {\r\n const xyz = this.toXYAndZ(point, this._scratchXYZ);\r\n if (this._cache.get(xyz))\r\n ++numInCache;\r\n else if (this._inflight.contains(xyz))\r\n this._redispatchOnCompletion = true;\r\n else\r\n this._pending.insert(xyz);\r\n }\r\n\r\n return numInCache;\r\n }\r\n\r\n // Obtain converted points from the cache. The assumption is that every point in `inputs` is already present in the cache.\r\n // Any point not present will be returned unconverted with an error status.\r\n protected getFromCache(inputs: XYZProps[]): PointWithStatus[] {\r\n const outputs: PointWithStatus[] = [];\r\n for (const input of inputs) {\r\n const xyz = this.toXYAndZ(input, this._scratchXYZ);\r\n let output = this._cache.get(xyz);\r\n if (!output)\r\n output = { p: { ...xyz }, s: GeoCoordStatus.CSMapError };\r\n\r\n outputs.push(output);\r\n }\r\n\r\n return outputs;\r\n }\r\n\r\n protected async scheduleDispatch(): Promise<void> {\r\n if (\"idle\" === this._state) {\r\n this._state = \"scheduled\";\r\n requestAnimationFrame(() => {\r\n this.dispatch(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n });\r\n }\r\n\r\n return new Promise((resolve) => {\r\n this._onCompleted.addOnce(() => resolve());\r\n });\r\n }\r\n\r\n public async convert(inputs: XYZProps[]): Promise<{ points: PointWithStatus[], fromCache: number }> {\r\n const fromCache = this.enqueue(inputs);\r\n assert(fromCache >= 0);\r\n assert(fromCache <= inputs.length);\r\n\r\n if (fromCache === inputs.length)\r\n return { points: this.getFromCache(inputs), fromCache };\r\n\r\n await this.scheduleDispatch();\r\n\r\n return { points: this.getFromCache(inputs), fromCache };\r\n }\r\n\r\n public findCached(inputs: XYZProps[]): CachedIModelCoordinatesResponseProps {\r\n const result: Array<PointWithStatus | undefined> = [];\r\n let missing: XYZProps[] | undefined;\r\n for (const input of inputs) {\r\n const key = this.toXYAndZ(input, this._scratchXYZ);\r\n const output = this._cache.get(key);\r\n result.push(output);\r\n if (!output) {\r\n if (!missing)\r\n missing = [];\r\n\r\n missing.push(input);\r\n }\r\n }\r\n\r\n return { result, missing };\r\n }\r\n}\r\n\r\n/** Response to a request to obtain imodel coordinates from cache.\r\n * @internal\r\n */\r\nexport interface CachedIModelCoordinatesResponseProps {\r\n /** An array of the same length as the input array, with undefined entries at indices corresponding to points not found in cache. */\r\n result: Array<PointWithStatus | undefined>;\r\n /** An array of points in the input array which were not found in the cache, or undefined if all points were found in the cache. */\r\n missing?: XYZProps[];\r\n}\r\n\r\n/** Options used to create a [[GeoConverter]].\r\n * @internal exported strictly for tests.\r\n */\r\nexport interface GeoConverterOptions {\r\n readonly datum: string;\r\n isIModelClosed: () => boolean;\r\n toIModelCoords: (request: IModelCoordinatesRequestProps) => Promise<PointWithStatus[]>;\r\n fromIModelCoords: (request: GeoCoordinatesRequestProps) => Promise<PointWithStatus[]>;\r\n}\r\n\r\n/** An object capable of communicating with the backend to convert between coordinates in a geographic coordinate system and coordinates in an [[IModelConnection]]'s own coordinate system.\r\n * @see [[GeoServices.getConverter]] to obtain a converter.\r\n * @see [GeographicCRS]($common) for more information about geographic coordinate reference systems.\r\n * @public\r\n */\r\nexport class GeoConverter {\r\n private readonly _geoToIModel: CoordinateConverter;\r\n private readonly _iModelToGeo: CoordinateConverter;\r\n /** Used for removing this converter from GeoServices' cache after all requests are completed.\r\n * @internal\r\n */\r\n public readonly onAllRequestsCompleted = new BeEvent<() => void>();\r\n\r\n /** @internal */\r\n constructor(opts: GeoConverterOptions) {\r\n const isIModelClosed = opts.isIModelClosed;\r\n this._geoToIModel = new CoordinateConverter({\r\n direction: \"geoToIModel\",\r\n isIModelClosed,\r\n requestPoints: async (geoCoords: XYAndZ[]) => opts.toIModelCoords({ source: opts.datum, geoCoords }),\r\n });\r\n\r\n this._iModelToGeo = new CoordinateConverter({\r\n direction: \"iModelToGeo\",\r\n isIModelClosed,\r\n requestPoints: async (iModelCoords: XYAndZ[]) => opts.fromIModelCoords({ target: opts.datum, iModelCoords }),\r\n });\r\n }\r\n\r\n /** Convert the specified geographic coordinates into iModel coordinates. */\r\n public async convertToIModelCoords(geoPoints: XYZProps[]): Promise<PointWithStatus[]> {\r\n const result = await this.getIModelCoordinatesFromGeoCoordinates(geoPoints);\r\n return result.iModelCoords;\r\n }\r\n\r\n /** Convert the specified iModel coordinates into geographic coordinates. */\r\n public async convertFromIModelCoords(iModelCoords: XYZProps[]): Promise<PointWithStatus[]> {\r\n const result = await this.getGeoCoordinatesFromIModelCoordinates(iModelCoords);\r\n return result.geoCoords;\r\n }\r\n\r\n /** @internal */\r\n public async getIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): Promise<IModelCoordinatesResponseProps> {\r\n const result = await this._geoToIModel.convert(geoPoints);\r\n this.checkCompletion();\r\n return {\r\n iModelCoords: result.points,\r\n fromCache: result.fromCache,\r\n };\r\n }\r\n\r\n /** @internal */\r\n public async getGeoCoordinatesFromIModelCoordinates(iModelPoints: XYZProps[]): Promise<GeoCoordinatesResponseProps> {\r\n const result = await this._iModelToGeo.convert(iModelPoints);\r\n this.checkCompletion();\r\n return {\r\n geoCoords: result.points,\r\n fromCache: result.fromCache,\r\n };\r\n }\r\n\r\n private checkCompletion(): void {\r\n if (this._geoToIModel.isIdle && this._iModelToGeo.isIdle)\r\n this.onAllRequestsCompleted.raiseEvent();\r\n }\r\n\r\n /** @internal */\r\n public getCachedIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): CachedIModelCoordinatesResponseProps {\r\n return this._geoToIModel.findCached(geoPoints);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport type GeoServicesOptions = Omit<GeoConverterOptions, \"datum\">;\r\n\r\n/** The Geographic Services available for an [[IModelConnection]].\r\n * @see [[IModelConnection.geoServices]] to obtain the GeoServices for a specific iModel.\r\n * @public\r\n */\r\nexport class GeoServices {\r\n private readonly _options: GeoServicesOptions;\r\n /** Each GeoConverter has its own independent request queue and cache of previously-converted points.\r\n * Some callers like RealityTileTree obtain a single GeoConverter and reuse it throughout their own lifetime. Therefore they benefit from both batching and caching, and\r\n * the cache gets deleted once the RealityTileTree becomes disused.\r\n *\r\n * Other callers like IModelConnection.spatialToCartographic obtain a new GeoConverter every time they need one, use it to convert a single point(!), and then discard the converter.\r\n * This entirely prevents batching - e.g., calling spatialToCartographic 20 times in one frame results in 20 http requests.\r\n * To address that, we cache each GeoConverter returned by getConverter until it has converted at least one point and has no further outstanding conversion requests.\r\n * In this way, the converter lives for as long as (and no longer than) any caller is awaiting conversion to/from its datum - it and its cache are deleted once it becomes disused.\r\n * This makes the coordinate caching generally less useful, but at least bounded - and maximizes batching of requests.\r\n */\r\n private readonly _cache = new Map<string, GeoConverter>();\r\n\r\n /** @internal */\r\n public constructor(options: GeoServicesOptions) {\r\n this._options = options;\r\n }\r\n\r\n /** @internal */\r\n public static createForIModel(iModel: IModelConnection): GeoServices {\r\n return new GeoServices({\r\n isIModelClosed: () => iModel.isClosed,\r\n toIModelCoords: async (request) => {\r\n const rpc = IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);\r\n const response = await rpc.getIModelCoordinatesFromGeoCoordinates(iModel.getRpcProps(), request);\r\n return response.iModelCoords;\r\n },\r\n fromIModelCoords: async (request) => {\r\n const rpc = IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);\r\n const response = await rpc.getGeoCoordinatesFromIModelCoordinates(iModel.getRpcProps(), request);\r\n return response.geoCoords;\r\n },\r\n });\r\n }\r\n\r\n /** Obtain a converter that can convert between a geographic coordinate system and the iModel's own coordinate system.\r\n * @param datumOrGCRS The name or JSON representation of the geographic coordinate system datum - for example, \"WGS84\".\r\n * @returns a converter, or `undefined` if the iModel is not open.\r\n * @note A [[BlankConnection]] has no connection to a backend, so it is never \"open\"; therefore it always returns `undefined`.\r\n */\r\n public getConverter(datumOrGCRS?: string | GeographicCRSProps): GeoConverter | undefined {\r\n if (this._options.isIModelClosed())\r\n return undefined;\r\n\r\n const datum = (typeof datumOrGCRS === \"object\" ? JSON.stringify(datumOrGCRS) : datumOrGCRS) ?? \"\";\r\n\r\n let converter = this._cache.get(datum);\r\n if (!converter) {\r\n converter = new GeoConverter({ ...this._options, datum });\r\n this._cache.set(datum, converter);\r\n\r\n converter.onAllRequestsCompleted.addOnce(() => {\r\n if (converter === this._cache.get(datum))\r\n this._cache.delete(datum);\r\n });\r\n }\r\n\r\n return converter;\r\n }\r\n}\r\n"]}
|
|
@@ -34,8 +34,6 @@ export declare class ExtensionAdmin {
|
|
|
34
34
|
* @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).
|
|
35
35
|
*/
|
|
36
36
|
registerHost(hostUrl: string): void;
|
|
37
|
-
/** Returns the hostname of an input string. Throws an error if input is not a valid hostname (or URL). */
|
|
38
|
-
private getHostName;
|
|
39
37
|
/** Loops over all enabled Extensions and triggers each one if the provided event is defined. */
|
|
40
38
|
private activateExtensionEvents;
|
|
41
39
|
/** Executes the extension. Catches and logs any errors (so that an extension will not crash the main application). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionAdmin.d.ts","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ExtensionAdmin.d.ts","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA0DxE;;;GAGG;AACH,qBAAa,cAAc;IACzB,2GAA2G;IAC3G,OAAO,CAAC,WAAW,CAA0E;IAC7F,OAAO,CAAC,MAAM,CAAW;IAEzB;;OAEG;IACI,SAAS,sBAEd;;IAMF;;;;;OAKG;IACU,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrE;;;;OAIG;IACU,aAAa,CAAC,SAAS,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAM3E;;;;OAIG;IACI,YAAY,CAAC,OAAO,EAAE,MAAM;IAOnC,gGAAgG;YAClF,uBAAuB;IAarC,sHAAsH;YACxG,QAAQ;CAOvB"}
|
|
@@ -10,6 +10,45 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.ExtensionAdmin = void 0;
|
|
11
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
12
|
const FrontendLoggerCategory_1 = require("../common/FrontendLoggerCategory");
|
|
13
|
+
/** The Extensions loading system has the following goals:
|
|
14
|
+
* 1. Only fetch what is needed when it is required
|
|
15
|
+
* 1. Load a manifest file
|
|
16
|
+
* 2. Load the the main module when necessary (usually at an activation event)
|
|
17
|
+
* 2. Download the extension's files
|
|
18
|
+
*
|
|
19
|
+
* 3 ways to load an Extension into the system:
|
|
20
|
+
*
|
|
21
|
+
* 1. Load both the Extension Manifest and import the main module of the extension from a local file/package.
|
|
22
|
+
* 2. A minimum set of properties to get the manifest and javascript from a remote server.
|
|
23
|
+
* 3. A minimum set of properties to get the manifest and javascript from Bentley's Extension Service.
|
|
24
|
+
*
|
|
25
|
+
* An Extension must be added to ExtensionAdmin before it can be executed during activation events.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Normalizes hostnames for comparison.
|
|
29
|
+
* @returns The normalized hostname of a URL or bare hostname.
|
|
30
|
+
* @throws Error if the input cannot be parsed, or does not contain a hostname.
|
|
31
|
+
*/
|
|
32
|
+
function normalizeHostname(input) {
|
|
33
|
+
const invalid = () => new Error(`"${input}" is not a valid URL or hostname (i.e. http://localhost:3000, yourdomain.com, etc.).`);
|
|
34
|
+
// inputs without a scheme (e.g., https://) will throw an error in the URL constructor
|
|
35
|
+
const inputWithScheme = /^[a-z][a-z0-9+\-.]*:\/\//i.test(input) ? input : `https://${input}`;
|
|
36
|
+
let hostname;
|
|
37
|
+
try {
|
|
38
|
+
hostname = new URL(inputWithScheme).hostname.toLowerCase();
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw invalid();
|
|
42
|
+
}
|
|
43
|
+
// strip only a leading "www." label - removing "www" anywhere would make unrelated
|
|
44
|
+
// hosts like "wwwexample.com" compare equal to "example.com"
|
|
45
|
+
const normalized = hostname.startsWith("www.") ? hostname.substring("www.".length) : hostname;
|
|
46
|
+
// schemes with an optional or opaque host (e.g. file:///, data:) parse successfully but carry no
|
|
47
|
+
// hostname, and an input of just "www." normalizes to nothing. Neither can identify a host.
|
|
48
|
+
if (normalized.length === 0)
|
|
49
|
+
throw invalid();
|
|
50
|
+
return normalized;
|
|
51
|
+
}
|
|
13
52
|
/** The Extension Admin controls the list of currently loaded Extensions.
|
|
14
53
|
*
|
|
15
54
|
* @alpha
|
|
@@ -34,10 +73,10 @@ class ExtensionAdmin {
|
|
|
34
73
|
* @alpha
|
|
35
74
|
*/
|
|
36
75
|
async addExtension(provider) {
|
|
37
|
-
if (provider.hostname) {
|
|
38
|
-
const
|
|
39
|
-
if (this._hosts.
|
|
40
|
-
throw new Error(`Error loading extension: ${
|
|
76
|
+
if (provider.hostname !== undefined && this._hosts.length > 0) {
|
|
77
|
+
const hostname = normalizeHostname(provider.hostname);
|
|
78
|
+
if (this._hosts.indexOf(hostname) < 0) {
|
|
79
|
+
throw new Error(`Error loading extension: ${provider.hostname} was not registered.`);
|
|
41
80
|
}
|
|
42
81
|
}
|
|
43
82
|
try {
|
|
@@ -68,28 +107,11 @@ class ExtensionAdmin {
|
|
|
68
107
|
* @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).
|
|
69
108
|
*/
|
|
70
109
|
registerHost(hostUrl) {
|
|
71
|
-
const hostname =
|
|
110
|
+
const hostname = normalizeHostname(hostUrl);
|
|
72
111
|
if (this._hosts.indexOf(hostname) < 0) {
|
|
73
112
|
this._hosts.push(hostname);
|
|
74
113
|
}
|
|
75
114
|
}
|
|
76
|
-
/** Returns the hostname of an input string. Throws an error if input is not a valid hostname (or URL). */
|
|
77
|
-
getHostName(inputUrl) {
|
|
78
|
-
// inputs without a protocol (e.g., http://) will throw an error in URL constructor
|
|
79
|
-
const inputWithProtocol = /(http|https):\/\//.test(inputUrl) ?
|
|
80
|
-
inputUrl :
|
|
81
|
-
`https://${inputUrl}`;
|
|
82
|
-
try {
|
|
83
|
-
const hostname = new URL(inputWithProtocol).hostname.replace("www.", "");
|
|
84
|
-
return hostname;
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
if (e instanceof TypeError) {
|
|
88
|
-
throw new Error("Argument hostUrl should be a valid URL or hostname (i.e. http://localhost:3000, yourdomain.com, etc.).");
|
|
89
|
-
}
|
|
90
|
-
throw e;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
115
|
/** Loops over all enabled Extensions and triggers each one if the provided event is defined. */
|
|
94
116
|
async activateExtensionEvents(event) {
|
|
95
117
|
for (const extension of this._extensions.values()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionAdmin.js","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;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AAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAC/D,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,OAAe;QACjC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,gGAAgG;IACxF,KAAK,CAAC,uBAAuB,CAAC,KAAa;QACjD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;YAClD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB;gBACtC,SAAS;YAEX,KAAK,MAAM,eAAe,IAAI,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;gBAClE,IAAI,eAAe,KAAK,KAAK,EAAE,CAAC;oBAC9B,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,8DAA8D;gBAC1F,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,sHAAsH;IAC9G,KAAK,CAAC,QAAQ,CAAC,SAA6B;QAClD,IAAI,CAAC;YACH,MAAM,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,qBAAM,CAAC,QAAQ,CAAC,+CAAsB,CAAC,UAAU,EAAE,6BAA6B,SAAS,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC3H,CAAC;IACH,CAAC;CACF;AAxFD,wCAwFC","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/** @packageDocumentation\r\n * @module Extensions\r\n */\r\n\r\nimport { Logger } from \"@itwin/core-bentley\";\r\n\r\nimport { FrontendLoggerCategory } from \"../common/FrontendLoggerCategory\";\r\nimport type { ExtensionManifest, ExtensionProvider } from \"./Extension\";\r\n\r\n/** The Extensions loading system has the following goals:\r\n * 1. Only fetch what is needed when it is required\r\n * 1. Load a manifest file\r\n * 2. Load the the main module when necessary (usually at an activation event)\r\n * 2. Download the extension's files\r\n *\r\n * 3 ways to load an Extension into the system:\r\n *\r\n * 1. Load both the Extension Manifest and import the main module of the extension from a local file/package.\r\n * 2. A minimum set of properties to get the manifest and javascript from a remote server.\r\n * 3. A minimum set of properties to get the manifest and javascript from Bentley's Extension Service.\r\n *\r\n * An Extension must be added to ExtensionAdmin before it can be executed during activation events.\r\n */\r\n\r\n/**\r\n * Normalizes hostnames for comparison.\r\n * @returns The normalized hostname of a URL or bare hostname.\r\n * @throws Error if the input cannot be parsed, or does not contain a hostname.\r\n */\r\nfunction normalizeHostname(input: string): string {\r\n const invalid = () => new Error(`\"${input}\" is not a valid URL or hostname (i.e. http://localhost:3000, yourdomain.com, etc.).`);\r\n\r\n // inputs without a scheme (e.g., https://) will throw an error in the URL constructor\r\n const inputWithScheme = /^[a-z][a-z0-9+\\-.]*:\\/\\//i.test(input) ? input : `https://${input}`;\r\n\r\n let hostname;\r\n try {\r\n hostname = new URL(inputWithScheme).hostname.toLowerCase();\r\n } catch {\r\n throw invalid();\r\n }\r\n\r\n // strip only a leading \"www.\" label - removing \"www\" anywhere would make unrelated\r\n // hosts like \"wwwexample.com\" compare equal to \"example.com\"\r\n const normalized = hostname.startsWith(\"www.\") ? hostname.substring(\"www.\".length) : hostname;\r\n\r\n // schemes with an optional or opaque host (e.g. file:///, data:) parse successfully but carry no\r\n // hostname, and an input of just \"www.\" normalizes to nothing. Neither can identify a host.\r\n if (normalized.length === 0)\r\n throw invalid();\r\n\r\n return normalized;\r\n}\r\n\r\n/**\r\n * A \"ready to use\" Extension (contains a manifest object and an extension provider to help execute).\r\n * Will be used as the type for in-memory extensions in the ExtensionAdmin\r\n */\r\ninterface InstalledExtension {\r\n /** An extension provider that has been added to ExtensionAdmin */\r\n provider: ExtensionProvider;\r\n /** The manifest (package.json) of the extension */\r\n manifest: ExtensionManifest;\r\n}\r\n\r\n/** The Extension Admin controls the list of currently loaded Extensions.\r\n *\r\n * @alpha\r\n */\r\nexport class ExtensionAdmin {\r\n /** Defines the set of extensions that are currently known and can be invoked during activation events. */\r\n private _extensions: Map<string, InstalledExtension> = new Map<string, InstalledExtension>();\r\n private _hosts: string[];\r\n\r\n /** Fired when an Extension has been added or removed.\r\n * @internal\r\n */\r\n public onStartup = async () => {\r\n await this.activateExtensionEvents(\"onStartup\");\r\n };\r\n\r\n public constructor() {\r\n this._hosts = [];\r\n }\r\n\r\n /**\r\n * Adds an extension.\r\n * The manifest will be fetched and the extension will be activated on an activation event.\r\n * @param provider\r\n * @alpha\r\n */\r\n public async addExtension(provider: ExtensionProvider): Promise<void> {\r\n if (provider.hostname !== undefined && this._hosts.length > 0) {\r\n const hostname = normalizeHostname(provider.hostname);\r\n if (this._hosts.indexOf(hostname) < 0) {\r\n throw new Error(`Error loading extension: ${provider.hostname} was not registered.`);\r\n }\r\n }\r\n try {\r\n const manifest = await provider.getManifest();\r\n this._extensions.set(manifest.name, {\r\n manifest,\r\n provider,\r\n });\r\n // TODO - temporary fix to execute the missed startup event\r\n if (manifest.activationEvents.includes(\"onStartup\"))\r\n provider.execute(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n } catch (e) {\r\n throw new Error(`Failed to get extension manifest ${provider.hostname ? `at ${provider.hostname}` : \"\"}: ${String(e)}`);\r\n }\r\n }\r\n\r\n /**\r\n * Adds a list of extensions\r\n * @param providers\r\n * @alpha\r\n */\r\n public async addExtensions(providers: ExtensionProvider[]): Promise<void[]> {\r\n return Promise.all(\r\n providers.map(async (provider) => this.addExtension(provider)),\r\n );\r\n }\r\n\r\n /**\r\n * Registers a hostname for an extension.\r\n * Once a hostname has been registered, only remote extensions from registered hosts are permitted to be added.\r\n * @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).\r\n */\r\n public registerHost(hostUrl: string) {\r\n const hostname = normalizeHostname(hostUrl);\r\n if (this._hosts.indexOf(hostname) < 0) {\r\n this._hosts.push(hostname);\r\n }\r\n }\r\n\r\n /** Loops over all enabled Extensions and triggers each one if the provided event is defined. */\r\n private async activateExtensionEvents(event: string) {\r\n for (const extension of this._extensions.values()) {\r\n if (!extension.manifest.activationEvents)\r\n continue;\r\n\r\n for (const activationEvent of extension.manifest.activationEvents) {\r\n if (activationEvent === event) {\r\n this._execute(extension); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** Executes the extension. Catches and logs any errors (so that an extension will not crash the main application). */\r\n private async _execute(extension: InstalledExtension) {\r\n try {\r\n await extension.provider.execute();\r\n } catch (e) {\r\n Logger.logError(FrontendLoggerCategory.Extensions, `Error executing extension ${extension.manifest.name}: ${String(e)}`);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -17,7 +17,7 @@ export interface RemoteExtensionProviderProps {
|
|
|
17
17
|
*/
|
|
18
18
|
export declare class RemoteExtensionProvider implements ExtensionProvider {
|
|
19
19
|
private readonly _props;
|
|
20
|
-
/** The
|
|
20
|
+
/** The hostname of the server where the extension is hosted. */
|
|
21
21
|
readonly hostname: string;
|
|
22
22
|
constructor(_props: RemoteExtensionProviderProps);
|
|
23
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAItB;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,iBAAiB;IAInD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,
|
|
1
|
+
{"version":3,"file":"RemoteExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAItB;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,iBAAiB;IAInD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,gEAAgE;IAChE,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAEJ,MAAM,EAAE,4BAA4B;IAIjE;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAIvD"}
|
|
@@ -11,11 +11,11 @@ const ExtensionLoadScript_1 = require("./ExtensionLoadScript");
|
|
|
11
11
|
*/
|
|
12
12
|
class RemoteExtensionProvider {
|
|
13
13
|
_props;
|
|
14
|
-
/** The
|
|
14
|
+
/** The hostname of the server where the extension is hosted. */
|
|
15
15
|
hostname;
|
|
16
16
|
constructor(_props) {
|
|
17
17
|
this._props = _props;
|
|
18
|
-
this.hostname = new URL(this._props.jsUrl).hostname
|
|
18
|
+
this.hostname = new URL(this._props.jsUrl).hostname;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Attempts to execute an extension.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":";;;AAQA,mDAAgD;AAChD,+DAAmD;AAanD;;;;;GAKG;AACH,MAAa,uBAAuB;IAIL;IAH7B,
|
|
1
|
+
{"version":3,"file":"RemoteExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":";;;AAQA,mDAAgD;AAChD,+DAAmD;AAanD;;;;;GAKG;AACH,MAAa,uBAAuB;IAIL;IAH7B,gEAAgE;IAChD,QAAQ,CAAS;IAEjC,YAA6B,MAAoC;QAApC,WAAM,GAAN,MAAM,CAA8B;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC;IACtD,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,OAAO,IAAA,gCAAU,EAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,WAAW;QACtB,OAAO,IAAA,iBAAO,EAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;CAEF;AAxBD,0DAwBC","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\nimport type {\r\n ExtensionManifest,\r\n ExtensionProvider,\r\n} from \"../Extension\";\r\nimport { request } from \"../../request/Request\";\r\nimport { loadScript } from \"./ExtensionLoadScript\";\r\n\r\n/**\r\n * Required props for a remote extension provider\r\n * @alpha\r\n */\r\nexport interface RemoteExtensionProviderProps {\r\n /** URL where the extension entry point can be loaded from */\r\n jsUrl: string;\r\n /** URL where the manifest (package.json) can be loaded from */\r\n manifestUrl: string;\r\n}\r\n\r\n/**\r\n * Implements a \"remote\" extension.\r\n * Remote extensions are hosted on an external server.\r\n * The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.\r\n * @alpha\r\n */\r\nexport class RemoteExtensionProvider implements ExtensionProvider {\r\n /** The hostname of the server where the extension is hosted. */\r\n public readonly hostname: string;\r\n\r\n constructor(private readonly _props: RemoteExtensionProviderProps) {\r\n this.hostname = new URL(this._props.jsUrl).hostname;\r\n }\r\n\r\n /**\r\n * Attempts to execute an extension.\r\n * Throws an error if the provided jsUrl is not accessible.\r\n */\r\n public async execute(): Promise<string> {\r\n return loadScript(this._props.jsUrl);\r\n }\r\n\r\n /**\r\n * Attempts to fetch an extension's manifest (package.json) file.\r\n * Throws an error if the provided manifestUrl is not accessible.\r\n */\r\n public async getManifest(): Promise<ExtensionManifest> {\r\n return request(this._props.manifestUrl, \"json\");\r\n }\r\n\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneCompositor.d.ts","sourceRoot":"","sources":["../../../../../src/internal/render/webgl/SceneCompositor.ts"],"names":[],"mappings":"AAIA;;GAEG;AASH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAC2D,cAAc,EAE/E,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AAIzD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,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oBAAoB,IAAI,WAAW,CAAC;IAExD,aAAoB,UAAU,IAAI,aAAa,CAAC;IAChD,aAAoB,aAAa,IAAI,aAAa,CAAC;IACnD,aAAoB,gBAAgB,IAAI,MAAM,CAAC;IAE/C,IAAW,eAAe,IAAI,OAAO,CAAkC;IAEvE,SAAS,aAAa,MAAM,EAAE,MAAM;WAOtB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe;aAIrC,iBAAiB,CAAC,KAAK,EAAE,YAAY,CAAC,UAAU,GAAG,IAAI;CACxE"}
|
|
@@ -232,8 +232,8 @@ class FrameBuffers {
|
|
|
232
232
|
idsAndZComposite;
|
|
233
233
|
idsAndAltZComposite;
|
|
234
234
|
edlDrawCol;
|
|
235
|
-
init(textures, depth, depthMS) {
|
|
236
|
-
if (!this.initPotentialMSFbos(textures, depth, depthMS))
|
|
235
|
+
init(textures, depth, depthMS, boundColor) {
|
|
236
|
+
if (!this.initPotentialMSFbos(textures, depth, depthMS, boundColor))
|
|
237
237
|
return false;
|
|
238
238
|
this.depthAndOrder = FrameBuffer_1.FrameBuffer.create([(0, core_bentley_1.expectDefined)(textures.depthAndOrder)], depth);
|
|
239
239
|
this.hilite = FrameBuffer_1.FrameBuffer.create([(0, core_bentley_1.expectDefined)(textures.hilite)], depth);
|
|
@@ -241,7 +241,7 @@ class FrameBuffers {
|
|
|
241
241
|
if (!this.depthAndOrder || !this.hilite || !this.hiliteUsingStencil)
|
|
242
242
|
return false;
|
|
243
243
|
(0, core_bentley_1.assert)(undefined === this.opaqueAll);
|
|
244
|
-
if (!this.initPotentialMSMRTFbos(textures, depth, depthMS))
|
|
244
|
+
if (!this.initPotentialMSMRTFbos(textures, depth, depthMS, boundColor))
|
|
245
245
|
return false;
|
|
246
246
|
(0, core_bentley_1.assert)(undefined !== textures.accumulation && undefined !== textures.revealage);
|
|
247
247
|
const colors = [textures.accumulation, textures.revealage];
|
|
@@ -258,9 +258,8 @@ class FrameBuffers {
|
|
|
258
258
|
&& undefined !== this.clearTranslucent
|
|
259
259
|
&& undefined !== this.pingPong;
|
|
260
260
|
}
|
|
261
|
-
initPotentialMSFbos(textures, depth, depthMS) {
|
|
262
|
-
|
|
263
|
-
(0, core_bentley_1.assert)(undefined !== boundColor && undefined !== textures.color);
|
|
261
|
+
initPotentialMSFbos(textures, depth, depthMS, boundColor) {
|
|
262
|
+
(0, core_bentley_1.assert)(undefined !== textures.color);
|
|
264
263
|
if (undefined === depthMS) {
|
|
265
264
|
this.opaqueColor = FrameBuffer_1.FrameBuffer.create([boundColor], depth);
|
|
266
265
|
this.opaqueAndCompositeColor = FrameBuffer_1.FrameBuffer.create([textures.color], depth);
|
|
@@ -273,10 +272,8 @@ class FrameBuffers {
|
|
|
273
272
|
return undefined !== this.opaqueColor
|
|
274
273
|
&& undefined !== this.opaqueAndCompositeColor;
|
|
275
274
|
}
|
|
276
|
-
initPotentialMSMRTFbos(textures, depth, depthMs) {
|
|
277
|
-
|
|
278
|
-
(0, core_bentley_1.assert)(undefined !== boundColor &&
|
|
279
|
-
undefined !== textures.color &&
|
|
275
|
+
initPotentialMSMRTFbos(textures, depth, depthMs, boundColor) {
|
|
276
|
+
(0, core_bentley_1.assert)(undefined !== textures.color &&
|
|
280
277
|
undefined !== textures.featureId &&
|
|
281
278
|
undefined !== textures.depthAndOrder &&
|
|
282
279
|
undefined !== textures.accumulation &&
|
|
@@ -390,23 +387,23 @@ class FrameBuffers {
|
|
|
390
387
|
this.idsAndAltZComposite = (0, core_bentley_1.dispose)(this.idsAndAltZComposite);
|
|
391
388
|
}
|
|
392
389
|
}
|
|
393
|
-
enableMultiSampling(textures, depth, depthMS) {
|
|
390
|
+
enableMultiSampling(textures, depth, depthMS, boundColor) {
|
|
394
391
|
this.opaqueColor = (0, core_bentley_1.dispose)(this.opaqueColor);
|
|
395
392
|
this.opaqueAndCompositeColor = (0, core_bentley_1.dispose)(this.opaqueAndCompositeColor);
|
|
396
|
-
let rVal = this.initPotentialMSFbos(textures, depth, depthMS);
|
|
393
|
+
let rVal = this.initPotentialMSFbos(textures, depth, depthMS, boundColor);
|
|
397
394
|
this.opaqueAll = (0, core_bentley_1.dispose)(this.opaqueAll);
|
|
398
395
|
this.opaqueAndCompositeAll = (0, core_bentley_1.dispose)(this.opaqueAndCompositeAll);
|
|
399
|
-
rVal = this.initPotentialMSMRTFbos(textures, depth, depthMS);
|
|
396
|
+
rVal = this.initPotentialMSMRTFbos(textures, depth, depthMS, boundColor);
|
|
400
397
|
return rVal;
|
|
401
398
|
}
|
|
402
|
-
disableMultiSampling(textures, depth) {
|
|
399
|
+
disableMultiSampling(textures, depth, boundColor) {
|
|
403
400
|
this.opaqueAll = (0, core_bentley_1.dispose)(this.opaqueAll);
|
|
404
401
|
this.opaqueAndCompositeAll = (0, core_bentley_1.dispose)(this.opaqueAndCompositeAll);
|
|
405
|
-
if (!this.initPotentialMSMRTFbos(textures, depth, undefined))
|
|
402
|
+
if (!this.initPotentialMSMRTFbos(textures, depth, undefined, boundColor))
|
|
406
403
|
return false;
|
|
407
404
|
this.opaqueColor = (0, core_bentley_1.dispose)(this.opaqueColor);
|
|
408
405
|
this.opaqueAndCompositeColor = (0, core_bentley_1.dispose)(this.opaqueAndCompositeColor);
|
|
409
|
-
return this.initPotentialMSFbos(textures, depth, undefined);
|
|
406
|
+
return this.initPotentialMSFbos(textures, depth, undefined, boundColor);
|
|
410
407
|
}
|
|
411
408
|
get isDisposed() {
|
|
412
409
|
return undefined === this.opaqueColor && undefined === this.opaqueAndCompositeColor && undefined === this.depthAndOrder
|
|
@@ -1450,7 +1447,7 @@ class Compositor extends SceneCompositor {
|
|
|
1450
1447
|
this._depthMS = undefined;
|
|
1451
1448
|
if (this._depth !== undefined) {
|
|
1452
1449
|
return this._textures.init(this._width, this._height, this._antialiasSamples)
|
|
1453
|
-
&& this._fbos.init(this._textures, this._depth, this._depthMS)
|
|
1450
|
+
&& this._fbos.init(this._textures, this._depth, this._depthMS, (0, core_bentley_1.expectDefined)(this.target.outputColorTexture))
|
|
1454
1451
|
&& this._geom.init(this._textures)
|
|
1455
1452
|
&& this.eyeDomeLighting.init(this._width, this._height, this._depth);
|
|
1456
1453
|
}
|
|
@@ -1465,11 +1462,11 @@ class Compositor extends SceneCompositor {
|
|
|
1465
1462
|
if (!this._textures.enableMultiSampling(this._width, this._height, this._antialiasSamples))
|
|
1466
1463
|
return false;
|
|
1467
1464
|
(0, core_bentley_1.assert)(undefined !== this._depth && undefined !== this._depthMS);
|
|
1468
|
-
return this._fbos.enableMultiSampling(this._textures, this._depth, this._depthMS);
|
|
1465
|
+
return this._fbos.enableMultiSampling(this._textures, this._depth, this._depthMS, (0, core_bentley_1.expectDefined)(this.target.outputColorTexture));
|
|
1469
1466
|
}
|
|
1470
1467
|
disableMultiSampling() {
|
|
1471
1468
|
(0, core_bentley_1.assert)(undefined !== this._depth);
|
|
1472
|
-
if (!this._fbos.disableMultiSampling(this._textures, this._depth))
|
|
1469
|
+
if (!this._fbos.disableMultiSampling(this._textures, this._depth, (0, core_bentley_1.expectDefined)(this.target.outputColorTexture)))
|
|
1473
1470
|
return false;
|
|
1474
1471
|
// Want to disable multisampling without deleting & reallocating other stuff.
|
|
1475
1472
|
this._depthMS = (0, core_bentley_1.dispose)(this._depthMS);
|