Skip to content

Commit a51097e

Browse files
committed
no longer use fixed format props for bearing
1 parent 946ed2b commit a51097e

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

packages/itwin/measure-tools/src/api/FormatterUtils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,34 @@ export namespace FormatterUtils {
219219
return bearing;
220220
}
221221

222+
/**
223+
* Creates a FormatterSpec for bearing using the provided KoQ string with fallback to default bearing format.
224+
* @param bearingKoQ The Kind of Quantity string for bearing.
225+
* @param persistenceUnitName The persistence unit name for the bearing.
226+
* @returns A FormatterSpec for bearing formatting.
227+
*/
228+
export async function getBearingFormatterSpec(bearingKoQ: string, persistenceUnitName: string): Promise<FormatterSpec | undefined> {
229+
let formatProps: FormatProps | undefined;
230+
231+
try {
232+
// First try to get format props from the formats provider using the bearingKoQ
233+
formatProps = await IModelApp.formatsProvider.getFormat(bearingKoQ);
234+
} catch {
235+
// If that fails, formatProps will remain undefined and we'll use the fallback
236+
}
237+
238+
// If we couldn't get format props from the provider, use the default bearing format
239+
if (!formatProps) {
240+
formatProps = getDefaultBearingFormatProps();
241+
}
242+
243+
// Create and return the formatter spec
244+
return IModelApp.quantityFormatter.createFormatterSpec({
245+
persistenceUnitName,
246+
formatProps
247+
});
248+
}
249+
222250
export function getDefaultBearingFormatProps(): FormatProps {
223251
return {
224252
minWidth: 2,

packages/itwin/measure-tools/src/api/MeasurementManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ShimFunctions } from "./ShimFunctions.js";
1515
import type { GeometryStreamProps } from "@itwin/core-common";
1616
import type { BeButtonEvent, DecorateContext, Decorator, HitDetail, ScreenViewport, Viewport } from "@itwin/core-frontend";
1717
import type { IModelConnection } from "@itwin/core-frontend";
18-
import type { Measurement} from "./Measurement.js";
18+
import type { Measurement } from "./Measurement.js";
1919
/** Handler for overriding what is returned for the tooltip of a measurement. */
2020
export type MeasurementToolTipHandler = (measurement: Measurement, pickContext: MeasurementPickContext) => Promise<HTMLElement | string>;
2121

packages/itwin/measure-tools/src/measurements/DistanceMeasurement.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ export class DistanceMeasurement extends Measurement {
198198
this._lengthPersistenceUnitName = "Units.M";
199199
this._coordinateKoQ = "AecUnits.LENGTH_COORDINATE";
200200
this._coordinatePersistenceUnitName = "Units.M";
201+
this._bearingKoQ = "RoadRailUnits.BEARING";
202+
this._bearingPersistenceUnitName = "Units.RAD";
201203
if (props) this.readFromJSON(props);
202204

203205
this.populateFormattingSpecsRegistry().then(() => this.createTextMarker().catch())
@@ -609,14 +611,7 @@ export class DistanceMeasurement extends Measurement {
609611
},
610612
);
611613
if (this._bearingKoQ && this._bearingPersistenceUnitName) {
612-
let bearingSpec: FormatterSpec | undefined;
613-
const bearingFormatProps = FormatterUtils.getDefaultBearingFormatProps();
614-
if (bearingFormatProps) {
615-
bearingSpec = await IModelApp.quantityFormatter.createFormatterSpec({
616-
persistenceUnitName: this._bearingPersistenceUnitName,
617-
formatProps: bearingFormatProps
618-
});
619-
}
614+
const bearingSpec = await FormatterUtils.getBearingFormatterSpec(this._bearingKoQ, this._bearingPersistenceUnitName);
620615
const fBearing: string = IModelApp.quantityFormatter.formatQuantity(bearing, bearingSpec);
621616
data.properties.push({
622617
label: MeasureTools.localization.getLocalizedString(

0 commit comments

Comments
 (0)