Skip to content

Instantly share code, notes, and snippets.

@leefsmp
Last active September 24, 2015 15:15
Show Gist options
  • Save leefsmp/30ecb25407e65a0f2e94 to your computer and use it in GitHub Desktop.
Save leefsmp/30ecb25407e65a0f2e94 to your computer and use it in GitHub Desktop.
Initialize viewer with local language
//////////////////////////////////////////////////////////////////////////
// Get token from our API URL.
// Current View & Data API requires a synchronous method
//
//////////////////////////////////////////////////////////////////////////
var getToken = function () {
var xhr = new XMLHttpRequest();
xhr.open("GET", '/api/token', false);
xhr.send(null);
var response = JSON.parse(xhr.responseText);
return response.access_token;
};
//////////////////////////////////////////////////////////////////////////
// on html document loaded
//
//////////////////////////////////////////////////////////////////////////
function onload() {
//List of Supported Languages:
// Chinese Simplified: zh-cn
// Chinese Traditional: zh-tw
// Czech: cs
// English: en
// French: fr
// German: de
// Italian: it
// Japanese: ja
// Korean: ko
// Polish: pl
// Portuguese Brazil: pt-br
// Russian: ru
// Spanish: es
// Turkish: tr
var options = {
language:'fr', //default - en
env: 'AutodeskProduction',
getAccessToken: getToken,
refreshToken: getToken
};
urn = Autodesk.Viewing.Private.getParameterByName('urn') || urn;
Autodesk.Viewing.Initializer(options, function () {
initializeViewer('viewer', 'urn:' + urn, '3d');
});
}
//////////////////////////////////////////////////////////////////////////
// Initialize viewer and load model
//
//////////////////////////////////////////////////////////////////////////
function initializeViewer(containerId, urn, role) {
Autodesk.Viewing.Document.load(urn, function (model) {
var rootItem = model.getRootItem();
var geometryItems = Autodesk.Viewing.Document.getSubItemsWithProperties(
rootItem,
{ 'type': 'geometry', 'role': role },
true);
var viewer = new Autodesk.Viewing.Private.GuiViewer3D(
document.getElementById(containerId));
viewer.start();
viewer.load(model.getViewablePath(geometryItems[0]));
}, function (msg) {
console.log('Error loading document: ' + msg);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment