2017-02-02 1 views
0

내 코드에서 뷰어가 모델 파일을로드 한 상태에서 완료된 후에 만 ​​작업이 수행되도록 Autodesk.Viewing.GEOMETRY_LOADED_EVENT 이벤트에 리스너를 연결했습니다. 나는 this의 사례를 따라 갔다.Forge 뷰어 PDF 파일에 대해 Autodesk.Viewing.GEOMETRY_LOADED_EVENT가 트리거되지 않음

// 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 GET의 트리거로 작동합니다. 하지만 최근에 발견 한 한 가지가 pdf과 같은 일부 파일 유형의 경우이 이벤트가 실행되지 않습니다. 3d 파일, rvt, dwg 파일 등 모든 다른 파일들에 대해 이것은 완벽하게 정상적으로 작동합니다. 그러나 pdf 파일의 경우이 작동하지 않습니다.

이것이 올바른지, 이것이 pdf 파일에서 작동하지 않습니까? 이러한 파일이 뷰어에 의해로드되는 시점을 알기 위해 무엇을 할 수 있습니까? 여기에 내가 사용할 수있는 다른 비슷한 사건이 있습니까?

우리의 응용 프로그램에서는 3D 모델에서 PDF 파일을 포함한 2D 파일에 이르기까지 모든 종류의 파일을 지원해야합니다. 따라서 뷰어가 지원하는 모든 파일 형식에 대해로드가 완료되면 트리거되는 이벤트가 필요합니다.

감사합니다.

+1

.PDF을했다, 그래서 나는 GEOMETRY_LOADED_EVENT이 발생하지 않는 것으로 예상된다 같아요. 문서가 완전히로드되었는지 확인할 수있는 다른 이벤트가 있으면 개발 팀에 문의하십시오. –

+0

@PhilippeLeefsma 좋습니다. 그러나 시청자가 파일을 완전히로드 한 시점을 알기 위해 듣기 위해 이벤트가 필요합니다. 이 문제를 해결할 수있는 방법이 있으면 알려주십시오. – kabirbaidhya

+0

그게 내가 바라는 바로 그거야, 내가 의견을 얻을 때 알려주지 ... –

답변

0

어쨌든 모든 것을 시도했지만 결국 응용 프로그램에서 작동하도록 해킹을해야했습니다. 그러나 작업 : 어떤 형상을 포함하지 않는

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