如何将自定义菜单添加到Autodesk Forge Viewer? [英] How to add custom menu to Autodesk Forge Viewer?
问题描述
你好 我在这里使用查看器示例"表单: https://forge.autodesk.com/zh-CN/docs/viewer/v5/tutorials/basic-viewer/ (步骤1) 现在我需要:
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.
请问该怎么做?
我尝试从中复制整个类MyContextMenu扩展..."代码 https://forge.autodesk.com/blog/customize-viewer-context-菜单 但这不起作用.
I try to copy whole "class MyContextMenu extends ... " code from https://forge.autodesk.com/blog/customize-viewer-context-menu but it does not worked.
谢谢.
推荐答案
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
}
});
});
}
这篇关于如何将自定义菜单添加到Autodesk Forge Viewer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!