如何禁用右键单击事件或如何隐藏 Autodesk Forge 查看器上的上下文菜单
Posted
技术标签:
【中文标题】如何禁用右键单击事件或如何隐藏 Autodesk Forge 查看器上的上下文菜单【英文标题】:How can I disable the right click event or how can I hide the context menu on the Autodesk Forge Viewer 【发布时间】:2021-05-20 07:47:39 【问题描述】:如何在 Autodesk Forge 查看器上禁用右键单击事件。我想隐藏上下文菜单。有人知道吗?
【问题讨论】:
【参考方案1】:如果您只想禁用上下文菜单,只需将 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);
【讨论】:
viewer.setContextMenu(null);帮助。谢谢【参考方案2】:如果你想隐藏上下文菜单,使用这个:
viewer.contextMenu.hide();
如果您想删除上下文菜单项,并添加自己的上下文菜单,请使用:
您可以通过this.viewer.unregisterContextMenuCallback('Autodesk.Dasher.ContextMenuExtension');
删除默认 Autodesk Forge 查看器上下文菜单
您可以通过
this.viewer.registerContextMenuCallback('Autodesk.Dasher.ContextMenuExtension',
(menu, status) =>
参考:HOW TO ADD CUSTOM CONTEXT IN FORGE VIEWER。 这是用于在 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;
【讨论】:
以上是关于如何禁用右键单击事件或如何隐藏 Autodesk Forge 查看器上的上下文菜单的主要内容,如果未能解决你的问题,请参考以下文章