简体   繁体   English

如何正确地将Autodesk Viewer LayerManager恢复到RestoreState

[英]How to get Autodesk Viewer LayerManager to RestoreState properly

I've encountered a bug in the Autodesk Viewer LayerManager extension that breaks the restoreState functionality. 我在Autodesk Viewer LayerManager扩展中遇到了一个破坏restoreState功能的错误。 I am saving the state of a multilayer DWG file using getState and re-applying that state using restoreState. 我使用getState保存多层DWG文件的状态,并使用restoreState重新应用该状态。 When i restore state, most or all of the layers are hidden, even if they weren't when i saved the state. 当我恢复状态时,大多数或所有图层都被隐藏,即使它们不是我保存状态时也是如此。

It looks like this is an issue with how the state is being saved and interpreted. 看起来这是一个如何保存和解释状态的问题。 I dug into the state JSON and found the list of visible layers ( state.objectSet[0].isolated ) in this form: 我挖掘了状态JSON,并以这种形式找到了可见层列表( state.objectSet[0].isolated ):

["0","1","2","3","4","5"]

After some experimenting i found out that the LayerManager is expecting either the integer indices of the layers or the string names of the layers. 经过一些实验,我发现LayerManager期望层的整数索引或层的字符串名称。 Something like: 就像是:

[0,1,2,3,4,5]

or 要么

["layer0","layer1","layer2","layer3","layer4","layer5"]

(assuming those are the names of each layer) (假设这些是每一层的名称)

So the current implementation breaks because it looks for layers with the names "0", "1", "2", etc. no matter what the actual layer names are. 因此,当前实现中断,因为它查找名称为“0”,“1”,“2”等的层,无论实际层名称是什么。

I am wondering if there is a way to fix or work around this. 我想知道是否有办法解决或解决这个问题。 A temporary solution is to parse the state JSON and cast the layer numbers to integers but that is a bit of a hack. 一个临时的解决方案是解析状态JSON并将层数转换为整数,但这有点像黑客。

This is a known issue and is currently being looked into by our Engineering. 这是一个已知问题,目前我们的工程师正在研究。 Can stay tuned to our Forge Blog and look out for the releases notes to keep tabs on a fix. 可以继续关注我们的Forge博客并查看发行说明以密切关注修复。

In the meantime as quick workaround you can programmatically reveal all the layers once all graphics are loaded: 与此同时,作为快速解决方法,您可以在加载所有图形后以编程方式显示所有图层:

viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, ()=>viewer.showAll())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM