Forge 查看器 Autodesk.Viewing.GEOMETRY_LOADED_EVENT 未针对 pdf 文件触发
Forge viewer Autodesk.Viewing.GEOMETRY_LOADED_EVENT not being triggered for pdf files
在我的代码中,我将侦听器附加到 Autodesk.Viewing.GEOMETRY_LOADED_EVENT
事件,以确保只有 运行 查看器完全完成模型文件的加载后才会发生。我遵循了 this.
中的示例
// Attach event handlers
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, () => $timeout(handleViewerGeometryLoaded));
viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, () => $timeout(handleViewerSelectionChanged));
function handleViewerGeometryLoaded() {
// Perform some actions here after everything is loaded.
}
只要在查看器加载完文件时触发 GEOMETRY_LOADED_EVENT
,这就完全可以正常工作。但我最近发现一件事,对于某些文件类型,如 pdf
,此事件不会被触发。对于所有其他文件,如 3d 文件、rvt、dwg 文件等,这工作得很好。但是对于 pdf 文件,这不起作用。
这对 pdf 文件不起作用是否正确?我该怎么做才能知道查看器何时加载了这些文件?我可以在这里使用任何其他类似的事件吗?
在我们的应用程序中,我们需要支持从 3d 模型到 2d 文件的各种文件,甚至包括 pdf 文件。因此,我需要某种事件,该事件在为查看器支持的所有文件类型完成加载时触发。
谢谢。
无论如何,我尝试了所有方法,但最终我不得不做这个 hack 以使其在我的应用程序中工作。但它完成了工作:)
let modelCompletelyLoaded === false;
function ensureModelsWithoutGeometryLoaded(viewer) {
const CHECK_INTERVAL = 1000;
return new Promise(resolve => {
// This is a dirty hack we need to do to ensure pdf files
// to know when pdf files are loaded. We had to do this since
// the GEOMETRY_LOADED_EVENT won't get triggered for the pdf files and
// the files that doesn't have any geometry so we need to poll continously
// to know if the model is fully loaded.
let loadChecker = setInterval(() => {
let hasMyData = viewer.model && viewer.model.myData;
let loaded = hasMyData && viewer.model.myData.loadDone;
let is2d = hasMyData && viewer.model.myData.is2d;
let hasInstanceTree = hasMyData && (typeof viewer.model.myData.instanceTree === 'object');
// It's not a 2d model, or the instanceTree has been loaded i.e the it has geometry
// it implies that this couldn't be a pdf file, just skip it.
if (is2d === false || hasInstanceTree) {
clearInterval(loadChecker);
} else if (loaded) {
// Loaded now. Okay, great trigger the event finally.
resolve();
clearInterval(loadChecker);
}
}, CHECK_INTERVAL);
});
}
function handleObjectLoaded() {
if (modelCompletelyLoaded === true) {
return
}
modelCompletelyLoaded === true;
// Perform some actions here after everything is loaded.
// ...
}
// Attach event handlers (this would work for all the files except those that doesn't have geometry data).
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, handleObjectLoaded);
// For pdf files and those that don't contain geometry do this
ensureModelsWithoutGeometryLoaded(viewer).then(handleObjectLoaded);
在我的代码中,我将侦听器附加到 Autodesk.Viewing.GEOMETRY_LOADED_EVENT
事件,以确保只有 运行 查看器完全完成模型文件的加载后才会发生。我遵循了 this.
// Attach event handlers
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, () => $timeout(handleViewerGeometryLoaded));
viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, () => $timeout(handleViewerSelectionChanged));
function handleViewerGeometryLoaded() {
// Perform some actions here after everything is loaded.
}
只要在查看器加载完文件时触发 GEOMETRY_LOADED_EVENT
,这就完全可以正常工作。但我最近发现一件事,对于某些文件类型,如 pdf
,此事件不会被触发。对于所有其他文件,如 3d 文件、rvt、dwg 文件等,这工作得很好。但是对于 pdf 文件,这不起作用。
这对 pdf 文件不起作用是否正确?我该怎么做才能知道查看器何时加载了这些文件?我可以在这里使用任何其他类似的事件吗?
在我们的应用程序中,我们需要支持从 3d 模型到 2d 文件的各种文件,甚至包括 pdf 文件。因此,我需要某种事件,该事件在为查看器支持的所有文件类型完成加载时触发。
谢谢。
无论如何,我尝试了所有方法,但最终我不得不做这个 hack 以使其在我的应用程序中工作。但它完成了工作:)
let modelCompletelyLoaded === false;
function ensureModelsWithoutGeometryLoaded(viewer) {
const CHECK_INTERVAL = 1000;
return new Promise(resolve => {
// This is a dirty hack we need to do to ensure pdf files
// to know when pdf files are loaded. We had to do this since
// the GEOMETRY_LOADED_EVENT won't get triggered for the pdf files and
// the files that doesn't have any geometry so we need to poll continously
// to know if the model is fully loaded.
let loadChecker = setInterval(() => {
let hasMyData = viewer.model && viewer.model.myData;
let loaded = hasMyData && viewer.model.myData.loadDone;
let is2d = hasMyData && viewer.model.myData.is2d;
let hasInstanceTree = hasMyData && (typeof viewer.model.myData.instanceTree === 'object');
// It's not a 2d model, or the instanceTree has been loaded i.e the it has geometry
// it implies that this couldn't be a pdf file, just skip it.
if (is2d === false || hasInstanceTree) {
clearInterval(loadChecker);
} else if (loaded) {
// Loaded now. Okay, great trigger the event finally.
resolve();
clearInterval(loadChecker);
}
}, CHECK_INTERVAL);
});
}
function handleObjectLoaded() {
if (modelCompletelyLoaded === true) {
return
}
modelCompletelyLoaded === true;
// Perform some actions here after everything is loaded.
// ...
}
// Attach event handlers (this would work for all the files except those that doesn't have geometry data).
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, handleObjectLoaded);
// For pdf files and those that don't contain geometry do this
ensureModelsWithoutGeometryLoaded(viewer).then(handleObjectLoaded);