Skip to content

Basic implementation

Ruben de Laat edited this page Aug 9, 2018 · 8 revisions

This page does contain some pseudo code, it is based on this example.

Please read about the requirements first.

First

Make sure your code is loaded a JavaScript Module. This means that the script tag should have a type="module".

Import required modules

The following code assumes that the BIMserver JavaScript API has been installed on the localhost:8080 BIMserver. Obviously you can simply include the API modules in your own project as well.

import BimServerClient from "http://localhost:8080/apps/bimserverjavascriptapi/bimserverclient.js"
import BimServerViewer from "../viewer/bimserverviewer.js"

BimServerClient is a generic client to communicate with BIMserver, BimServerViewer is what we instantiate to get a viewer.

Connect to a BIMserver API and authenticate

In most cases, your application probably already has done this, if it's doing other stuff with BIMserver.

var api = new BimServerClient("[ADDRESS OF A BIMSERVER]");
this.api.init(() => {
  this.api.login([USERNAME], [PASSWORD], () => {
    // So now authentication has succeeded, make sure that for a real implementation you also check for errors
    
  });
});

Load a model

// Get the project details
this.api.call("ServiceInterface", "getProjectByPoid", {
	poid: this.demoSettings.poid
}, (project) => {
	// Select what canvas to bind the viewer to
	var canvas = document.getElementById("glcanvas");
					
	// Create a new BimServerViewer
	this.bimServerViewer = new BimServerViewer(this.api, this.demoSettings.viewerSettings, canvas, window.innerWidth, window.innerHeight);

	// Load the model
	this.bimServerViewer.loadModel(project);
});
Clone this wiki locally