如何禁用右键单击事件或如何隐藏 Autodesk Forge Viewer 上的上下文菜单

How can I disable the right click event or how can I hide the context menu on the Autodesk Forge Viewer

如何禁用 Autodesk Forge 查看器上的右键单击事件。我想隐藏上下文 menu.Does 有人对此有想法吗?

如果您想隐藏上下文菜单,请使用:

viewer.contextMenu.hide();

如果您想删除上下文菜单项,并添加您自己的上下文菜单,请使用:

您可以通过 this.viewer.unregisterContextMenuCallback('Autodesk.Dasher.ContextMenuExtension'); 删除默认的 Autodesk Forge Viewer 上下文菜单 您可以通过

自行创建
    this.viewer.registerContextMenuCallback('Autodesk.Dasher.ContextMenuExtension',
(menu, status) => {}

参考:HOW TO ADD CUSTOM CONTEXT IN FORGE VIEWER。 这是示例 class,用于在 Forge Viewer 中删除和添加您自己的自定义上下文菜单:

    export default class ContextMenuExtension extends Autodesk.Viewing.Extension {
    
      constructor(viewer: Autodesk.Viewing.Private.GuiViewer3D, options: any) {
    
        super(viewer, options);
}
      load(): boolean {
    
        console.log('ContextMenuExtension loaded');
    
        let self = this;
    
        this.viewer.registerContextMenuCallback(
    
          'Autodesk.Dasher.ContextMenuExtension',
    
          (menu, status) => {
            // Remove all existing menu items
            while (menu.length > 0) {
              menu.pop();
            }
    
            // Add our new item if an object is selected
            if (status.hasSelected) {
              menu.push({
    
                title: 'Send to HoloLens',
                target: function(): void {
                  let messageSpecs = {
                    'msgTitleKey': 'Sent to HoloLens',
                    'messageKey': 'Sent to HoloLens',
                    'messageDefaultValue': 'This object has been sent to HoloLens for viewing.',
                  };
                  Autodesk.Viewing.Private.HudMessage.displayMessage(
    
                    self.viewer.container, messageSpecs
    
                  );

                  setTimeout(
                    () => {
                      Autodesk.Viewing.Private.HudMessage.dismiss();
                    }, 10000
                  );
                },
              });
            }
          }
        );
    
        return true;
      }
      unload(): boolean {
    
        console.log('ContextMenuExtension unloaded');
    
        this.viewer.unregisterContextMenuCallback('Autodesk.Dasher.ContextMenuExtension');
    
        return true;
      }
    }

如果您只想禁用上下文菜单,只需将 null 设置为 setContextMenu 方法即可。

viewer.setContextMenu(null);

如果您想再次显示上下文菜单,只需保留上下文并进行设置即可。

// you need to get current context menu before calling setsetContextMenu(null)
var contextMenu = viewer.contextmenu;  
viewer.setContextMenu(null);


....

//set preserved contextMenu inf you want to show it again.
viewer.setContextMenu(contextMenu);