工具栏按钮扩展

viewer.addRadialToolbarButton({

打开 API 调试

工具栏按钮扩展

BimEngine 支持向右下角径向工具栏和右上角视图下拉菜单追加业务按钮。

径向工具栏

viewer.addRadialToolbarButton({
  id: 'custom-action',
  icon: 'https://example.com/icons/action.svg',
  title: '业务操作',
  onClick: () => {
    console.log('custom action');
  }
});

切换型按钮可通过以下方法更新状态:

viewer.setRadialToolbarButtonActive('custom-action', true);

创建实例时若设置 enableRadialToolbar: false,以上方法会静默忽略。

视图下拉菜单

const remove = viewer.engine?.addViewDropdownButton({
  key: 'capture-image',
  label: '获取截图',
  onClick: () => {
    const image = viewer.engine?.captureViewBase64('image/jpeg', 0.9);
    console.log(image);
  },
  closeOnClick: true
});

// 页面卸载或不再需要时移除
// remove?.();
// viewer.engine?.removeViewDropdownButton('capture-image');

key 必须唯一;重复注册会覆盖已有的同 key 自定义按钮。