NO TOKEN
HTML
<script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js?v=2.15.*"></script>
<div id='MyViewerDiv' />
<img id='MyThumbnail' />
CSS
#MyViewerDiv {
width: 200px;
height: 200px;
border: 1px solid red;
}
#MyThumbnail {
position: fixed;
top: 8px;
left: 220px;
width: 200px;
height: 200px;
border: 1px solid black;
}
JavaScript
// Please make sure these 2 values get updated!
var documentId = 'urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bG12dGVzdHN1aXRlL0hvdXNlLmR3Zng';
var token = ''; // THIS EXAMPLE NEEDS A TOKEN!!
// Thank you!
// Forcing cookie to not be used.
// Needs to be set before Autodesk.Viewing.Initializer();
window.LMV_THIRD_PARTY_COOKIE = false;
var initOpts = Autodesk.Viewing.createInitializerOptions();
initOpts.accessToken = token;
Autodesk.Viewing.Initializer(initOpts, onInitialized);
function onInitialized() {
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
}
function onDocumentLoadSuccess(doc) {
var viewables = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {
'type': 'geometry'
}, true);
// Initialize thumbnail
// IMPORTANT: Setting the `src` attribute of an <img> tag will no longer be supported
// for Viewer version 2.16 and up -
// This mechanism works only up to version 2.15!
var thumbImg = document.getElementById('MyThumbnail');
var imgSrc = doc.getThumbnailPath(viewables[0]);
fetchAndSetThumbnail(thumbImg, imgSrc);
// Initialize Viewer (headless)
var svfUrl = doc.getViewablePath(viewables[0]);
var viewerDiv = document.getElementById('MyViewerDiv');
viewer = new Autodesk.Viewing.Viewer3D(viewerDiv);
viewer.start(svfUrl);
}
function onDocumentLoadFailure() {
alert('Failed initializng. Make sure you have a recent token for the specified documentId!');
}
function fetchAndSetThumbnail(thumbImg, imgSrc) {
var xhr = new XMLHttpRequest();
xhr.open("GET", imgSrc, true);
xhr.setRequestHeader("Authorization", "Bearer " + token);
// Ask for the result as an ArrayBuffer.
// Important note! This has to happen AFTER the xhr.open in order to work on IE.
// For more info please see: https://stackoverflow.com/a/34647690
xhr.responseType = "arraybuffer";
xhr.onload = function(e) {
// Obtain a blob: URL for the image data.
var arrayBufferView = new...