Skip to content

Commit a14f23e

Browse files
committed
add listener to update unit system of schema formats provider
1 parent 41ae96f commit a14f23e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

apps/test-viewer/src/components/Viewer.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ function onIModelConnected(imodel: IModelConnection) {
9393

9494
imodel.schemaContext.getSchema(new SchemaKey("AecUnits", SchemaMatchType.Latest)).then((schema) => {
9595
if (schema) {
96-
IModelApp.formatsProvider = new SchemaFormatsProvider(imodel.schemaContext, IModelApp.quantityFormatter.activeUnitSystem);
96+
const schemaFormatsProvider = new SchemaFormatsProvider(imodel.schemaContext, IModelApp.quantityFormatter.activeUnitSystem);
97+
const removeListener = IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener((args) => {
98+
schemaFormatsProvider.unitSystem = args.system;
99+
});
100+
IModelApp.formatsProvider = schemaFormatsProvider;
97101
console.log("Registered SchemaFormatsProvider");
102+
103+
IModelConnection.onClose.addOnce(removeListener)
98104
}
99105
}).catch((_) => {
100106
console.error("No common AecUnits schema found in iModel, not registering a SchemaFormatsProvider");

0 commit comments

Comments
 (0)