@itwin/measure-tools-react
Version:
Frontend framework and tools for measurements
192 lines • 7.12 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { BeUiEvent } from "@itwin/core-bentley";
/** Feature tracking helper for MeasureTools. Can control if features should be tracked and hook into the notification.
*/
export class FeatureTracking {
/**
* Gets if the feature tracking is enabled or not.
*/
static get isEnabled() {
return FeatureTracking._enabled;
}
/**
* Starts feature tracking events.
*/
static start() {
FeatureTracking._enabled = true;
}
/**
* Stops feature tracking events.
*/
static stop() {
FeatureTracking._enabled = false;
}
/**
* Emits an event that the specified feature was activated.
* @param feature Feature that was activated.
*/
static notifyFeature(feature) {
if (!FeatureTracking._enabled)
return;
this.onFeature.emit(feature);
}
/**
* Emits an event that the specified feature was activated with the specified toggled state.
* @param feature Feature that was activated.
* @param isOn current toggle state of the feature. This is added as metadata.
*/
static notifyToggledFeature(feature, isOn) {
this.notifyFeature(createToggledFeature(feature.name, feature.guid, isOn, feature.metaData, true));
}
/**
* Emits an event that the specified feature was activated.
* @param featureName name of the feature that was activated.
* @param featureGuid guid of the feature that was activated.
* @param metaData optional metadata for the feature.
*/
static notifyFeatureByName(featureName, featureGuid, metaData) {
this.notifyFeature({ name: featureName, guid: featureGuid, metaData });
}
/**
* Emits an event that the specified feature was activated with the specified toggled state.
* @param featureName name of the feature that was activated.
* @param featureGuid guid of the feature that was activated.
* @param isOn current toggle state of the feature. This is added as metadata.
* @param metaData optional additional metadata for the feature.
*/
static notifyToggledFeatureByName(featureName, featureGuid, isOn, metaData) {
this.notifyFeature(createToggledFeature(featureName, featureGuid, isOn, metaData, true));
}
}
FeatureTracking._enabled = true;
/** Feature tracking notification event. */
FeatureTracking.onFeature = new BeUiEvent();
/** State for a feature that can be toggled on/off */
export var ToggledState;
(function (ToggledState) {
ToggledState["On"] = "on";
ToggledState["Off"] = "off";
})(ToggledState || (ToggledState = {}));
/** Use this to create a feature that has metadata for a toggled "on/off" state. */
export function createToggledFeature(featureName, featureGuid, isOn, metaDataMap, copyMetaData) {
const metaData = metaDataMap
? copyMetaData
? new Map(metaDataMap)
: metaDataMap
: new Map();
metaData.set("toggled", isOn ? ToggledState.On : ToggledState.Off);
return { name: featureName, guid: featureGuid, metaData };
}
/* eslint-disable @typescript-eslint/naming-convention */
// Note: CRT_ prefix is legacy since these features were originally from the Civil-ReviewTools packages. Newly defined features do not need to use this prefix, and can use MST_ for MeaSure-Tools
export class MeasureToolsFeatures {
// Tools
static get Tools_ClearMeasurements() {
return {
name: "CRT_Tools_ClearMeasurements",
guid: "5838fd80-87e8-41a1-a813-15bcdc882ad1",
};
}
static get Tools_ToggleDisplayMeasurementAxes() {
return {
name: "CRT_Tools_ToggleDisplayMeasurementAxes",
guid: "d8a31a35-16d8-40c3-a5ea-1159ea644d7c",
};
}
static get Tools_MeasureArea() {
return {
name: "CRT_Tools_MeasureArea",
guid: "7000640d-c362-4533-9f60-3fc4e72af81f",
};
}
static get Tools_MeasureDistance() {
return {
name: "CRT_Tools_MeasureDistance",
guid: "10e474ee-9af8-4262-a505-77c9d896b065",
};
}
static get Tools_MeasureLocation() {
return {
name: "CRT_Tools_MeasureLocation",
guid: "6230e620-ffc2-4f7f-88d7-8652ae8cf91f",
};
}
static get Tools_MeasureAngle() {
return {
name: "MST_Tools_MeasureAngle",
guid: "19febcb9-24e7-49ee-980b-c2bb6a5dedef",
};
}
static get Tools_MeasureRadius() {
return {
name: "MST_Tools_MeasureRadius",
guid: "0ab34c10-2ab9-4982-9ed9-2760e6e455bd",
};
}
static get Tools_MeasurePerpendicular() {
return {
name: "MST_Tools_MeasurePerpendicular",
guid: "014ad558-3ad3-4c4d-bdb7-004783fdc149",
};
}
// Action toolbar
static get MeasurementActionsToolbar_Open() {
return {
name: "CRT_MeasurementActionsToolbar_Open",
guid: "8d92174a-9ccc-45a2-8638-4c9f66294022",
};
}
static get MeasurementActions_Delete() {
return {
name: "CRT_MeasurementActions_Delete",
guid: "269c820b-1361-4401-b711-ec4eaf333aff",
};
}
static get MeasurementActions_Lock() {
return {
name: "CRT_MeasurementActions_Lock",
guid: "e03e9d2a-e63b-4ea8-805d-59c1dbf94f86",
};
}
static get MeasurementActions_ToggleDisplayAxes() {
return {
name: "CRT_MeasurementActions_ToggleDisplayAxes",
guid: "ee61e68f-14d5-4d47-9fba-e8334d9b9097",
};
}
static get MeasurementActions_ToggleDisplayLabels() {
return {
name: "CRT_MeasurementActions_ToggleDisplayLabels",
guid: "3ee3fcd7-c158-481f-96e7-2f0907551357",
};
}
static get MeasurementActions_ToggleDisplayMeasurements() {
return {
name: "MST_MeasurementActions_ToggleDisplayMeasurements",
guid: "ef4bba9e-69f1-4f73-9db9-e176dd9335a4",
};
}
// Sheet measurement tools
static get Tools_MeasureDistance_createdInSheet() {
return {
name: "SMT_Tools_MeasureDistance_createdInSheet",
guid: "f3fde39b-c9d6-488a-a39a-2a253ff106d5"
};
}
static get Tools_MeasureArea_createdInSheet() {
return {
name: "SMT_Tools_MeasureArea_createdInSheet",
guid: "cd36e911-a472-4560-94e6-2128fd95f31c"
};
}
static get Tools_MeasureLocation_createdInSheet() {
return {
name: "SMT_Tools_MeasureLocation_createdInSheet",
guid: "10237379-3f9f-4f4a-93f7-fe453cb730a6"
};
}
}
//# sourceMappingURL=FeatureTracking.js.map