完全卸载并重新加载伪造查看器 [英] Completely unload and reload forge viewer

查看:28
本文介绍了完全卸载并重新加载伪造查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Angular 5 应用程序上使用 Forge Viewer.

I'm using the Forge Viewer on an Angular 5 application.

有没有办法完全卸载查看器以便以后重新加载?

Is there a way to completely unload the viewer so it can later be reloaded?

我有以下代码来卸载查看器:

I have the following code to unload the viewer:

if (this.viewer && this.viewer.running) {
  this.viewer.tearDown();
  this.viewer.finish();
  this.viewer = null;
}

而且我还有代码在用户每次进入页面时加载查看器.

And I also have the code to load the viewer every time the user enters the page.

目前,当用户导航到应用程序的不同页面时,该代码会被执行,但当用户返回包含查看器的页面时,它会在查看器所在的位置显示一个灰色框.

Currently, when a user navigates to a different page on the application, that code gets executed, but when the user comes back to the page that contains the viewer, it shows a grey box where the viewer should be.

这是一个重现该问题的 github 存储库:https://github.com/theivanaguilar/forge-viewer-reload

Here's a github repo that reproduces the issue: https://github.com/theivanaguilar/forge-viewer-reload

我在这里遗漏了什么吗?

Am I missing something here?

推荐答案

静态方法Autodesk.Viewing.Initializer只能调用一次,后续不会返回.每次加载组件时都需要调用所有其他查看器方法.所以你需要稍微重构一下你的代码.

The static method Autodesk.Viewing.Initializer can only be called once the subsequent times it will not return. All other viewer methods need to be invoked every time your component loads. So you need to refactor your code a bit.

我的应用程序正在使用 React 和 我在 appState 中保存了一个布尔值 以避免在初始化程序已经初始化的情况下调用它两次.

My app is using React and I save a boolean in the appState to avoid calling that Initializer twice if it has been initialized already.

希望能帮到你

这篇关于完全卸载并重新加载伪造查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆