diff --git a/packages/saved-views-react/src/api/utilities/translation/SavedViewTranslation.ts b/packages/saved-views-react/src/api/utilities/translation/SavedViewTranslation.ts index 15d8fafc..a011c233 100644 --- a/packages/saved-views-react/src/api/utilities/translation/SavedViewTranslation.ts +++ b/packages/saved-views-react/src/api/utilities/translation/SavedViewTranslation.ts @@ -4,8 +4,8 @@ *--------------------------------------------------------------------------------------------*/ import { IModelReadRpcInterface, type ViewQueryParams, type ViewStateProps } from "@itwin/core-common"; import { - DisplayStyle3dState, DrawingViewState, EmphasizeElements, SheetViewState, SpatialViewState, type BlankConnection, - type IModelConnection, type ViewState, type Viewport, + DisplayStyle3dState, DrawingViewState, EmphasizeElements, SheetViewState, SpatialViewState, type IModelConnection, + type ViewState, type Viewport, } from "@itwin/core-frontend"; import { isViewDataITwin3d, isViewDataITwinDrawing, isViewDataITwinSheet, type SavedViewRepresentation, @@ -255,10 +255,14 @@ async function fetchIModelViewData(iModel: IModelConnection, viewClassName: View } const viewId = await getDefaultViewIdFromClassName(iModel, viewClassName); + if (viewId === "") { + return manufactureEmptyViewState(iModel, viewClassName); + } + return iModel.views.load(viewId); } -function manufactureEmptyViewState(iModel: BlankConnection, viewClassName: ViewTypes): ViewState { +function manufactureEmptyViewState(iModel: IModelConnection, viewClassName: ViewTypes): ViewState { const blankViewState = SpatialViewState.createBlank( iModel, { x: 0, y: 0, z: 0 }, diff --git a/packages/test-app-frontend/src/App/ITwinJsApp/ITwinJsApp.tsx b/packages/test-app-frontend/src/App/ITwinJsApp/ITwinJsApp.tsx index 3993e344..fc84a710 100644 --- a/packages/test-app-frontend/src/App/ITwinJsApp/ITwinJsApp.tsx +++ b/packages/test-app-frontend/src/App/ITwinJsApp/ITwinJsApp.tsx @@ -17,7 +17,7 @@ import { FrontendIModelsAccess } from "@itwin/imodels-access-frontend"; import { IModelsClient } from "@itwin/imodels-client-management"; import { PageLayout } from "@itwin/itwinui-layouts-react"; import { useToaster } from "@itwin/itwinui-react"; -import { applyExtensionsToViewport, type LegacySavedViewBase } from "@itwin/saved-views-react/experimental"; +import { ModelCategoryOverrideProvider, applyExtensionsToViewport, type LegacySavedViewBase } from "@itwin/saved-views-react/experimental"; import { useEffect, useRef, useState, type ReactElement } from "react"; import { applyUrlPrefix } from "../../environment.js"; @@ -73,10 +73,11 @@ export function ITwinJsApp(props: ITwinJsAppProps): ReactElement | null { ); const viewportRef = useRef(); - const handleSavedViewSelect = (savedView: LegacySavedViewBase, viewState: ViewState) => { + const handleSavedViewSelect = async (savedView: LegacySavedViewBase, viewState: ViewState) => { setViewState(viewState); - if (viewportRef.current) { - applyExtensionsToViewport(viewportRef.current, savedView); + if (iModel && viewportRef.current) { + await clearAllOverrides(iModel, viewportRef.current); + await applyExtensionsToViewport(viewportRef.current, savedView); } }; @@ -206,3 +207,12 @@ async function getStoredViewState(iModel: IModelConnection): Promise { + const subcatProvider = viewport.findFeatureOverrideProviderOfType(ModelCategoryOverrideProvider); + if (subcatProvider) { + viewport.dropFeatureOverrideProvider(subcatProvider); + } + + iModel.selectionSet.emptyAll(); +}