Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@itwin/measure-tools-react
Advanced tools
Copyright © Bentley Systems, Incorporated. All rights reserved.
The measure-tools-react package provides measurement tools and React components to access within an iTwin Viewer.
Every iTwin.js application has initialization code where they must call IModelApp.startup()
. This library has a similar initialization entry-point that must be called to configure localization and register tools.
Call the MeasureTools.startup()
AFTER the IModelApp one.
await IModelApp.startup(opts);
await MeasureTools.startup(opts);
After that, most of your code changes will be to consume the default measurement tools (such as measure distance, polygon, location, etc).
Note: Startup can be called any number of times but will only startup once. Some other libraries that use measure-tools may have already initialized it for you!
With a few short lines, you can add the measurement tools and widgets to your app. The iTwin Viewer accepts a callback, onIModelAppInit
, which you can use to initialize the MeasureTools. Afterwards, all you need to do is pass in the MeasureToolsUiItemsProvider
to the list of UiProviders for your viewer to register. This will add both the toolbar with all the measure tools and the measurement property widget to your app for you.
const handleOnIModelAppInit = async () => {
await MeasureTools.startup();
};
return (
<Viewer
...
onIModelAppInit={handleOnIModelAppInit}
uiProviders={[
new MeasureToolsUiItemsProvider(),
]}
/>
);
Measurements support a right click context menu called the "Action Toolbar". By default it is not enabled, however it is completely customizable by the application. Similar to how tools are constructed by creating item definitions, the action toolbar constructs a list of "action items" that can be applied to a selected measurement. Applications can register action providers to add to or modify the list of actions. The application can also set a filter to the toolbar to control what measurements the toolbar is shown for.
If multiple measurements are selected, the actions apply to all the measurements.
Below is an example to enable the toolbar with a default action provider. Actions are:
// Set default measurement action toolbar (call this after MeasureTools.startup)
MeasurementActionToolbar.setDefaultActionProvider();
Below is an example of registering a custom action, it toggles the display style of a measurement so that it renders semi-transparently like if it were "ghosted".
// Test faded style by adding an action button that toggles default / faded style
// If not all of them are faded, set the remaining to faded. Else, back to default.
MeasurementActionToolbar.addActionProvider((measurements: Measurement[], actionItemList: MeasurementActionItemDef[]) => {
actionItemList.push(
new MeasurementActionItemDef({
id: "faded-toggle",
iconSpec: "icon-palette",
label: () => IModelApp.localization.getLocalizedString("MeasureTools:Generic.faded"),
tooltip: () => IModelApp.localization.getLocalizedString("MeasureTools:Generic.faded"),
execute: (args: Measurement[]) => {
const notAllFaded = args.some((m) => m.style !== WellKnownMeasurementStyle.Faded);
args.forEach((m) => {
m.style = notAllFaded ? WellKnownMeasurementStyle.faded : WellKnownMeasurementStyle.Default;
});
Measurement.invalidateDecorationsForAll(args);
MeasurementUIEvents.notifyMeasurementsChanged();
},
})
);
}, 100);
There are a number of global UI events that are triggered when measurements are modified (e.g. added or removed). Some applications can create contextual UI buttons that will be turn visible or invisible based on these state changes.
For example, distance measurements can have their axes toggled on/off. An application may want to turn on all axes. It would determine the visibility state of a contextual UI button by hooking into the MeasurementUIEvents.onToggleMeasurementAxesButtonVisibilityChanged
notification event.
An application can further customize UI event behavior by registering override handlers to determine if a measurement is to be accepted/rejected by the UI event (e.g. display a "clear all measurements" button but only if measurements fit a certain criteria).
A concrete example of this customization is an application that has measurements organized into multiple groups. One group may be "frozen" due to some application state (state that the measure-tools library may be unaware of) and should not be cleared by the clear measurements tool. So the application would register a custom UI event handler that would cause those measurements to be ignored when the clear measurement tool is invoked.
FAQs
Frontend framework and tools for measurements
The npm package @itwin/measure-tools-react receives a total of 1,845 weekly downloads. As such, @itwin/measure-tools-react popularity was classified as popular.
We found that @itwin/measure-tools-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.