iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
623 stars 211 forks source link

iTwin Viewer Measurement Units #2482

Closed sweetld closed 3 years ago

sweetld commented 3 years ago

I've been looking at changing the units that the iTwins Viewer displays in, as currently measurements are showing up in Imperial. Looking through the documentation, this seems to be the default, and if you want to display in Metric, then you have to change the setting.

It's this that I have been trying to do, but I'm clearly approaching it incorrectly, as it's having no effect...

I am trying to use the setUnitFormattingSettingsProvider()method with a LocalUnitFormatProvider instance, which from what I understand in the documentation allows switching to Metric if you pass the constructor a true Boolean, so basically like this:

IModelApp.quantityFormatter.setUnitFormattingSettingsProvider(new LocalUnitFormatProvider(new QuantityFormatter(true)));

Am I on the right track here, can anyone point me at an example, any advice would be really useful!

pmconne commented 3 years ago

It's this that I have been trying to do, but I'm clearly approaching it incorrectly, as it's having no effect..

Show your code?

I would have started with: IModelApp.quantityFormatter.setActiveUnitSystem("metric", true); but it appears that by default when you switch to a different iModel it will reset the settings (not sure if that matters in your case).

@bsteinbk

aruniverse commented 3 years ago

IModelApp.quantityFormatter.setActiveUnitSystem("metric", true);

You should be able to call this in the callback you pass into the onImodelConnected prop on the viewer. So even if you change models it should always set the unit system to metric.

sweetld commented 3 years ago

Thanks for your replies, this worked for me fine:

IModelApp.quantityFormatter.setActiveUnitSystem("metric", true);

sweetld commented 3 years ago

Just so you know, I did not actually need to trigger the reload of the active tool in my case, so this also worked:

IModelApp.quantityFormatter.setActiveUnitSystem("metric");