forge中创建右键二级菜单需要更改viewer3d中的部分源码需要更改以下几个函数用来实现hover的二级菜单效果,更改这几个函数主要是为了实现hover效果
实际效果如图:
ContextMenu.prototype.showMenu
ContextMenu.prototype.createMenuItem
ContextMenu.prototype.addCallbackToMenuItem
ContextMenu.prototype.addSubmenuCallbackToMenuItem
ContextMenu.prototype.hide
registerContextMenuCallback target中应该写为数组如
viewer.registerContextMenuCallback('Test', function (menu, status) {
if (status.hasSelected) {
menu.push({
title: "Test",
hasLevel: 'true',
target:[{
title: 'Hub details',
className: 'fa fa-cloud',
target:function (){
console.log(1)
}
}, {
title: 'Projects details',
className: 'fa fa-folder',
target:function (){
console.log(2)
}
}]
});
}
});
根据 Philippe Leefsma 和 Eason Kang 在stackoverflow上给的思路得出以上的结果 详情见 How to create two level context menu
代码见contextMenu