对接面板可调整大小和滚动容器

时间:2017-01-12 13:40:26

标签: autodesk-forge autodesk-viewer

如何调整停靠面板的大小?如何在Docking Panel中创建滚动容器?

我已使用此答案How to create a Docking Panel中给出的简单面板扩展了Docking Panel。如此理想将会知道如何制作它们

SimplePanel.prototype.initialize = function()

或创建停靠面板时的某处。

1 个答案:

答案 0 :(得分:1)

我更喜欢扩展机制,这样你就可以定义自包含它的JavaScript文件。这是一个例子。现在 style.resize ="自动" 代码行以及如何 appendChild 与其他元素(例如,充满其他元素的DIV)。使用此扩展程序,您只需要调用 viewer.loadExtension()

AutodeskNamespace('Autodesk.ADN.Viewing.Extension');

Autodesk.ADN.Viewing.Extension.MyExtension = function (viewer, options) {
  Autodesk.Viewing.Extension.call(this, viewer, options);

  var _self = this;

  ///////////////////////////////////////////////////////////////////////////
  // load callback
  ///////////////////////////////////////////////////////////////////////////
  _self.load = function () {

    // need to access geometry? wait until is loaded
    viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
      createDockPanel();
    });

    return true;
  };

  var _dockPanel;

  function createDockPanel() {
    _dockPanel = new Autodesk.Viewing.UI.DockingPanel(viewer.container, 'ecom', 'Cart');

    _dockPanel.container.style.top = "10px";
    _dockPanel.container.style.left = "10px";

    _dockPanel.container.style.width = "auto";
    _dockPanel.container.style.height = "auto";
    _dockPanel.container.style.resize = "auto";

    _dockPanel.container.appendChild(document.getElementById(‘someOtherElement’)); // for instance, a DIV

    _dockPanel.setVisible(true);
  }


  ///////////////////////////////////////////////////////////////////////////
  // unload callback
  ///////////////////////////////////////////////////////////////////////////
  _self.unload = function () {
    _dockPanel.setVisible(false)
    return true;
  };
};

Autodesk.ADN.Viewing.Extension.MyExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype);

Autodesk.ADN.Viewing.Extension.MyExtension.prototype.constructor = Autodesk.ADN.Viewing.Extension.MyExtension;

Autodesk.Viewing.theExtensionManager.registerExtension('Autodesk.ADN.Viewing.Extension.MyExtension', Autodesk.ADN.Viewing.Extension.MyExtension);