【问题标题】:How to create a Docking Panel (in the newer version of autodesk forge viewer)如何创建停靠面板(在较新版本的 Autodesk forge 查看器中)
【发布时间】:2020-08-06 09:13:12
【问题描述】:

注意:我已经根据答案中提供的建议更新了我以前的代码。

按照建议后,我发现停靠面板已添加到 DOM。但不显示(即使 z-index 设置为 2)

这是我迄今为止尝试过的。另外,在下面找到控制台结果的屏幕截图。

<html lang="en">
    <head>
        <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no" />
        <meta charset="utf-8">

        <link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css" type="text/css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js"></script>
        <style>
            body {
                margin: 0;
            }
            #forgeViewer {
                width: 100%;
                height: 100%;
                margin: 0;
                background-color: #F0F8FF;
            }
        </style>
    </head>
    <body>

        <div id="forgeViewer"></div>
    </body>
   <script>
   var viewer;

    var options = {
        env: 'AutodeskProduction',
        api: 'derivativeV2',  // for models uploaded to EMEA change this option to 'derivativeV2_EU'
        getAccessToken: function(onTokenReady) {
            var token = 'access token here';
            var timeInSeconds = 3600; // Use value provided by Forge Authentication (OAuth) API
            onTokenReady(token, timeInSeconds);
        }
    };
    SimplePanel = function(parentContainer, id, title, content, x, y)
{
  this.content = content;
Autodesk.Viewing.UI.DockingPanel.call(this, parentContainer, id, title,{shadow:false});

// Auto-fit to the content and don't allow resize.  Position at the coordinates given.
//
this.container.style.height = "150px";
this.container.style.width = "450px";
this.container.style.resize = "auto";
this.container.style.left = x + "px";
this.container.style.top = y + "px"; 
this.container.style.zIndex = 2;

};

SimplePanel.prototype = Object.create(Autodesk.Viewing.UI.DockingPanel.prototype);
SimplePanel.prototype.constructor = SimplePanel;

SimplePanel.prototype.initialize = function()
{ 
        this.title = this.createTitleBar(this.titleLabel || this.container.id);
this.container.appendChild(this.title);

this.container.appendChild(this.content);
this.initializeMoveHandlers(this.container);

this.closer = this.createCloseButton();
this.title.appendChild(this.closer);


var op = {left:false,heightAdjustment:45,marginTop:0};
this.scrollcontainer = this.createScrollContainer(op);

var html = [
    '<div class="uicomponent-panel-controls-container">',
    '<div class="panel panel-default">',
    '<table class="table table-hover table-responsive" id = "clashresultstable">',
    '<thead>',
    '<th>Name</th><th>Status</th><th>Found</th><th>Approved By</th><th>Description</th>',
    '</thead>',
    '<tbody>',
    '<tr><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td></tr>',
    '<tr><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td></tr>',
    '<tr><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td></tr>',
    '<tr><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td></tr>',
    '<tr><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td></tr>',
    '<tr><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td></tr>',
    '<tr><td>test</td><td>test</td><td>test</td><td>test</td><td>test</td></tr>',
    '</tbody>',
    '</table>',
    '</div>',
    '</div>'
].join('\n');


$(this.scrollContainer).append(html);

this.initializeMoveHandlers(this.title);
this.initializeCloseHandler(this.closer);        
};
    Autodesk.Viewing.Initializer(options, function() {

    var htmlDiv = document.getElementById('forgeViewer');
    viewer = new Autodesk.Viewing.GuiViewer3D(htmlDiv);
    var startedCode = viewer.start();
    if (startedCode > 0) {
        console.error('Failed to create a Viewer: WebGL not supported.');
        return;
    }

    console.log('Initialization complete, loading a model next...');

});

var documentId = 'urn:urn here';
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);


function onDocumentLoadSuccess(viewerDocument) {
    var defaultModel = viewerDocument.getRoot().getDefaultGeometry();
    viewer.loadDocumentNode(viewerDocument, defaultModel);
    viewer.addEventListener( Autodesk.Viewing.SELECTION_CHANGED_EVENT, event=>{
        //console.log(viewer.model.getData());
        console.log(viewer.model.getDocumentNode());
        // console.log(SimplePanel.container)
        viewer.getPropertyPanel(true).setVisible(true)
        var content = document.createElement('div');
        var mypanel = new  SimplePanel(NOP_VIEWER.container,'mypanel','My Panel',content);
        mypanel.setVisible(true);
})
}

function onDocumentLoadFailure() {
    console.error('Failed fetching Forge manifest');
}


   </script>
</html>```[![console output for the dom][1]][1]


 [![DOM screenshot on console][1]][1]


  [1]: https://i.stack.imgur.com/Lp1rm.png

【问题讨论】:

  • 你能解决吗?我正在经历同样的事情

标签: autodesk-forge autodesk-viewer


【解决方案1】:

您需要显式调用Autodesk.Viewing.UI.DockingPanel.setVisible(true) 以使面板可见,并将正确的z-index 放在视口中重叠元素之前的所需位置:

SimplePanel.container.style.width = width
SimplePanel.container.style.height = height
SimplePanel.container.style.left = left
SimplePanel.container.style.top = top
SimplePanel.container.style.z-index = 2 // or another value to suit the rest of your UI
SimplePanel.setVisible(true)

否则你会注意到它已经存在于 DOMtree 中,display 设置为 none 或者呈现在可见视口之外(定位在 top:0,left:0 等)或后面(被阻止)其他元素...

如果面板仍然没有出现,请尝试寻找相关的控制台输出,尤其是。触发选择事件并检查面板是否已在浏览器的开发人员工具中呈现到 DOMtree 但不知何故仍不可见时出现错误消息

【讨论】:

  • 你能用上面的代码示例纠正我吗?我尝试调用 Autodesk.Viewing.UI.DockingPanel.setVisible(true)。它显示它不是一个函数。我将 z-index 更改为 zIndex - 以克服左侧分配错误。仍然不确定您指的是哪里。我是 Autodesk forge API 的新手。
  • this.container.style.height = "150px"; this.container.style.width = "450px"; this.container.style.resize = "auto"; this.container.style.left = x + "px"; this.container.style.top = y + "px"; 这部分也一样吧?还有SimplePanel.setVisible(true)如果指定了为什么会设置Autodesk.Viewing.UI.DockingPanel.setVisible(true)@Bryan Huang
  • SimplePanel.container - 在控制台中返回未定义
  • 很抱歉打扰了 cmets。现在我已经根据建议更新了我的代码以及正确的屏幕截图。希望这是有道理的。有人可以通过更正我的代码来帮助解决这个问题吗? @Bryan Huang
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-15
  • 2020-08-06
  • 1970-01-01
  • 2021-03-09
  • 2021-11-12
  • 1970-01-01
相关资源
最近更新 更多