Forge 查看器 isLayerVisible 始终为 false
Forge viewer isLayerVisible is always false
出于某种原因,我在 viewer.isLayerVisible(layerNode) 上总是出错。
我遵循了本教程 https://forge.autodesk.com/blog/toggle-sheet-layer-visibility
我在 LAYER_VISIBILITY_CHANGED_EVENT 上有事件处理程序,这是我在打字稿中的代码片段:
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")
}
}
});
关闭图层管理器中的某些图层后,我还得到 viewer.areAllVisible() 为真。
Forge 查看器版本为 7。*
你有什么建议吗?谢谢!
我发现您可以从 indexToLayer 查看器访问可见层和可见层 属性
var visibleLayers = Array.from(viewer.impl.layers.indexToLayer.filter(e => e != null && e.visible));
出于某种原因,我在 viewer.isLayerVisible(layerNode) 上总是出错。 我遵循了本教程 https://forge.autodesk.com/blog/toggle-sheet-layer-visibility 我在 LAYER_VISIBILITY_CHANGED_EVENT 上有事件处理程序,这是我在打字稿中的代码片段:
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")
}
}
});
关闭图层管理器中的某些图层后,我还得到 viewer.areAllVisible() 为真。
Forge 查看器版本为 7。*
你有什么建议吗?谢谢!
我发现您可以从 indexToLayer 查看器访问可见层和可见层 属性
var visibleLayers = Array.from(viewer.impl.layers.indexToLayer.filter(e => e != null && e.visible));