@itwin/core-frontend
Version:
iTwin.js frontend components
82 lines • 4.23 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Views
*/
import { assert } from "@itwin/core-bentley";
import { ContextRealityModel, FeatureAppearance, RealityDataFormat } from "@itwin/core-common";
import { PlanarClipMaskState } from "./PlanarClipMaskState";
import { RealityDataSource } from "./RealityDataSource";
import { SpatialClassifiersState } from "./SpatialClassifiersState";
import { createOrbitGtTileTreeReference, createRealityTileTreeReference, RealityModelTileTree } from "./tile/internal";
/** A [ContextRealityModel]($common) attached to a [[DisplayStyleState]] supplying a [[TileTreeReference]] used to draw the
* reality model in a [[Viewport]].
* @see [DisplayStyleSettings.contextRealityModels]($common).
* @see [[DisplayStyleState.contextRealityModelStates]].
* @see [[DisplayStyleState.attachRealityModel]].
* @public
* @extensions
*/
export class ContextRealityModelState extends ContextRealityModel {
_treeRef;
/** The iModel with which the reality model is associated. */
iModel;
/** The reality data source key with which the reality model is associated. */
rdSourceKey;
/** @internal */
constructor(props, iModel, displayStyle) {
super(props, { createClassifiers: (container) => SpatialClassifiersState.create(container) });
this.iModel = iModel;
this._appearanceOverrides = props.appearanceOverrides ? FeatureAppearance.fromJSON(props.appearanceOverrides) : undefined;
if (undefined === props.orbitGtBlob) {
this.rdSourceKey = props.rdSourceKey ? props.rdSourceKey : RealityDataSource.createKeyFromUrl(props.tilesetUrl);
}
else {
this.rdSourceKey = props.rdSourceKey ? props.rdSourceKey : RealityDataSource.createKeyFromOrbitGtBlobProps(props.orbitGtBlob);
}
const useOrbitGtTileTreeReference = this.rdSourceKey.format === RealityDataFormat.OPC;
this._treeRef = (!useOrbitGtTileTreeReference) ?
createRealityTileTreeReference({
iModel,
source: displayStyle,
rdSourceKey: this.rdSourceKey,
url: props.tilesetUrl,
name: props.name,
classifiers: this.classifiers,
planarClipMask: this.planarClipMaskSettings,
getDisplaySettings: () => this.displaySettings,
getBackgroundBase: () => displayStyle.settings.mapImagery.backgroundBase,
getBackgroundLayers: () => displayStyle.settings.mapImagery.backgroundLayers,
}) :
createOrbitGtTileTreeReference({
iModel,
orbitGtBlob: props.orbitGtBlob,
rdSourceKey: this.rdSourceKey,
name: props.name,
classifiers: this.classifiers,
source: displayStyle,
getDisplaySettings: () => this.displaySettings,
});
this.onPlanarClipMaskChanged.addListener((newSettings) => {
this._treeRef.planarClipMask = newSettings ? PlanarClipMaskState.create(newSettings) : undefined;
});
}
/** The tile tree reference responsible for drawing the reality model into a [[Viewport]]. */
get treeRef() { return this._treeRef; }
/** The set of available [[ActiveSpatialClassifier]]s that can be used to classify the reality model. */
get classifiers() {
assert(super.classifiers instanceof SpatialClassifiersState);
return super.classifiers;
}
/** The transient Id assigned to this reality model at run-time. */
get modelId() {
return (this._treeRef instanceof RealityModelTileTree.Reference) ? this._treeRef.modelId : undefined;
}
/** Whether the reality model spans the entire globe ellipsoid. */
get isGlobal() {
return this.treeRef.isGlobal;
}
}
//# sourceMappingURL=ContextRealityModelState.js.map