关于imodel测量单位的转换


有时候可能需要转换测量数据的单位,例如使用英尺表示或者使用m表示。 方法如下:

const opts: IModelAppOptions = {};
//此处QuantityFormatter类是imodel系统类,实际可能以用户自定义子类去实例化。
const quantityFormatter = new QuantityFormatter();
opts.quantityFormatter = quantityFormatter;

await IModelApp.startup(opts);

initPromises.push(UiFramework.initialize(this.store, IModelApp.i18n));

//注意,这行代码必须放在IModelApp.startup与UiFramework.initialize调用之后,否则会出错。
IModelApp.quantityFormatter.useImperialFormats = false;//如果设置为true,以英尺为单位;如果设置为false将以m为单位。

IModelApp.quantityFormatter.useImperialFormats = true 结果如下所示:

IModelApp.quantityFormatter.useImperialFormats = false 结果如下所示:

其他情况,需要用户实现QuantityFormatter的子类以进行扩展,未来对此限制可能会进行优化。