weijie
weijie

Reputation: 54

How to create two level context menu in autodesk forge

I want to creat two level context menu but there is no api for this.Just look like this level context menu image what I can do?

Upvotes: 1

Views: 441

Answers (2)

Felipe
Felipe

Reputation: 4375

It is rather straighforward to acheive a multi level context menu by deriving from Autodesk.Viewing.UI.ObjectContextMenu. Simply provide an array in the target field:

buildMenu (event, node) {

  var menu = []

  switch (node.type) {

    case 'hubs':

      menu.push({
        title: 'Show details',
        className: 'fa fa-share',
        target: [{
          title: 'Hub details',
          className: 'fa fa-cloud',
          target: () => {
            this.emit('context.details', {
              event, node, type: 'hubs'
            })
          }
        }, {
          title: 'Projects details',
          className: 'fa fa-folder',
          target: () => {
            this.emit('context.details', {
              event, node, type: 'hubs.projects'
            })
          }
        }]
      })

      break

enter image description here

A complete example of this can be found here: DataContextMenu.js

Upvotes: 1

Eason Kang
Eason Kang

Reputation: 7070

Unfortunately, it's not available on current viewer version. You might have to write your own context menu in deep. But there is a workaround that you can follow:

  1. Override functions of Autodesk.Viewing.Private.ContextMenu to provide multiple level menus.
  2. Refer codes from Autodesk.Viewing.UI.ObjectContextMenu, then create your owned ObjectContextMenu and replace contextMenu property with the your owned multiple levels ContextMenu from the step 1.
  3. Refer codes from Autodesk.Viewing.Extensions.ViewerObjectContextMenu, then write your owned ViewerObjectContextMenu that inherits the custom ObjectContextMenu from the step 2.

P.S. This is just a workaround, it's not the formal solution, you might have to use it at your own risk.

Upvotes: 0

Related Questions