viewerforge

Forge viewer isLayerVisible is always false


For some reason I get always false on viewer.isLayerVisible(layerNode). I followed this tutorial https://forge.autodesk.com/blog/toggle-sheet-layer-visibility I have event handler on LAYER_VISIBILITY_CHANGED_EVENT, here is my code snippet in typescript:

viewer.addEventListener(Autodesk.Viewing.LAYER_VISIBILITY_CHANGED_EVENT, (e) => {
var root = viewer.model["myData"].layersRoot; //getLayersRoot() is not a function for some reason
var overlayLayer = viewer["getSelectedLayer"]();
if (viewer["layerRoot"] != undefined) {
    var layerNode = root.children.filter((e) => { return e.name === overlayLayer })
    var isLayerVisible = viewer.isLayerVisible(layerNode);
    //show layer
    if (isLayerVisible) {
        viewer.impl.addOverlay("Edit2D", viewer["savedPoints"].overlayLayer)
    }
    //hide layer
    else {
        viewer.impl.removeOverlayScene("Edit2D")
    }
}

});

After switching some layers from layer manager off, I also get viewer.areAllVisible() as true.

Forge viewer version is 7.*

Do you have any advice? Thanks!


Solution

  • I found out that you can access visible and visible layers from indexToLayer viewer property

       var visibleLayers = Array.from(viewer.impl.layers.indexToLayer.filter(e => e != null && e.visible));