VTK.js widgetManager.addWidget(vtkLabelWidget) says "widget.getWidgetForView is not a function"

Hello,

I dynamically add vtkLabelWidget to the scene when users click on some checkboxes. The code that is perfectly working is:

  const widget = vtkLabelWidget.newInstance();
  widget.setInteractor(renderWindow.getInteractor());
  widget.setEnabled(1);
  widget.getWidgetRep().setLabelText(path);
  widget.getWidgetRep().setWorldPosition([x, y, z]);

Now when the users uncheck the checkbox, I want to remove the widget from the scene. Doing widgetManager.removeWidget(widget) doesn’t remove the widget from the scene.

I thought this is because I didn’t call VTK.js widgetManager.addWidget(widget). But when I add this line I get the message:

widget.getWidgetForView is not a function

Is that a bug or am I doing a mistake ?

It looks like you’re mixing the old widgets in vtk.js/Sources/Interaction/Widgets with the new widget manager in vtk.js/Sources/Widgets. WidgetManager can only be used with widgets located in vtk.js/Sources/Widgets, and the ones in Interaction/Widgets will be deprecated at some point.

Ok thank you. I didn’t realize that. I will move to the new widget architecture then. From your point of view, what is best way to get started to create a custom widget (do you have any simple example to get started, or should I get inspiration from the widgets already existing in vtk.js, or something else ?) ?

You can start by looking at the examples in Sources/Widgets/Widgets3D. The DistanceWidget should be a good place to start. We also have some docs on the vtk.js website.

Ok. Thank you !