Skip to content

Instantly share code, notes, and snippets.

@leefsmp
Created October 21, 2016 08:21
Show Gist options
  • Save leefsmp/0afdb89de1971187ad402bb2b37fbc2e to your computer and use it in GitHub Desktop.
Save leefsmp/0afdb89de1971187ad402bb2b37fbc2e to your computer and use it in GitHub Desktop.
Illustrates how to load document offline/online with Forge Viewer
async onViewerCreated (data) {
try {
const { viewer, initialize, loadDocument } = data
viewer.addEventListener(
Autodesk.Viewing.FULLSCREEN_MODE_EVENT, (e) => {
this.onFullScreenMode(e)
})
const modelId = this.props.location.query.id
this.model = await this.modelSvc.getModel(
'forge-rcdb',
modelId)
if(!this.viewerEnvInitialized) {
this.viewerEnvInitialized = true
await initialize(
this.model.env,
'/api/forge/token/2legged')
}
viewer.start()
switch (this.model.env) {
case 'Local':
viewer.load(this.model.path)
break
case 'AutodeskProduction':
const doc = await loadDocument(
'urn:' + this.model.urn)
const path = ViewerToolkit.getDefaultViewablePath(doc)
viewer.loadModel(path)
break
}
this.viewer = viewer
} catch(ex) {
console.log('Viewer Initialization Error: ')
console.log(ex)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment