简体   繁体   中英

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. I am saving the state of a multilayer DWG file using getState and re-applying that state using 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:

["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. 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.

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.

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.

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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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