How to add custom menu to Autodesk Forge Viewer?

走远了吗. 提交于 2019-12-13 05:16:19

问题


Helo I'm using Viewer Example form here: https://forge.autodesk.com/en/docs/viewer/v5/tutorials/basic-viewer/ (Step 1) and now I need:

1. add custom menu on right click
2. get info's for clicked object, like Area, Volume, Length (if 3D) or length if 2D.

How to do that, please?

I try to copy whole "class MyContextMenu extends ... " code from https://forge.autodesk.com/blog/customize-viewer-context-menu but it does not worked.

Thank you.


回答1:


Here's a simple example of adding custom menu items to the context menu: http://jsfiddle.net/s47vy5u3/2. You'll just need to include your Forge app's access token and some viewable URN. The menu customization code itself looks like this:

function customizeMenu() {
    const viewer = NOP_VIEWER;
    viewer.registerContextMenuCallback('MyCustomMenuItems', function(menu, status) {
    menu.push({
      title: 'My custom menu item',
      target: () => {
        // Add your menu item's code here
      }
    });
  });
}


来源:https://stackoverflow.com/questions/52989533/how-to-add-custom-menu-to-autodesk-forge-viewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!