To integrate the BIMSurfer viewer into your own application, you can follow the pattern established in the Minimal class. This involves configuring server connection details, authenticating via BimServerClient, fetching project details, and then initializing the BimServerViewer on a specific HTML canvas.
Integration Steps:
- Configure Settings: Define a settings object containing
bimServerAddress, bimServerLogin (username and password), poid (Project ID), and viewerSettings. - Initialize API: Create an instance of
BimServerClient using the server address and call .init(). - Authenticate: Use
.login(username, password, successCallback, errorCallback) to authenticate. - Fetch Project: Use
.call("ServiceInterface", "getProjectByPoid", { poid: ... }, successCallback, errorCallback) to retrieve the project object. - Initialize Viewer: Create a new
BimServerViewer by passing viewerSettings, a target canvas element, width, height, and an optional parameter. - Load Model: Call
.loadModel(api, project) on the viewer instance to begin rendering.
import { BimServerClient } from "../../bimserverjavascriptapi/bimserverclient.js";
import { BimServerViewer } from "../viewer/bimserverviewer.js";
// 1. Define settings
const settings = {
bimServerAddress: "YOUR_BIMSERVER_ADDRESS",
bimServerLogin: {
username: "admin@bimserver.org",
password: "admin"
},
poid: 196609,
viewerSettings: {}
};
// 2. Connect and Initialize API
const api = new BimServerClient(settings.bimServerAddress);
api.init(() => {
// 3. Login
api.login(settings.bimServerLogin.username, settings.bimServerLogin.password, () => {
// 4. Get project details
api.call("ServiceInterface", "getProjectByPoid", {
poid: settings.poid
}, (project) => {
// 5. Initialize Viewer on a canvas
const canvas = document.getElementById("glcanvas");
const viewer = new BimServerViewer(
settings.viewerSettings,
canvas,
window.innerWidth,
window.innerHeight,
null
);
// 6. Load the model
viewer.loadModel(api, project);
}, (error) => {
console.error(error.message);
});
}, () => {
console.error("Error logging-in");
});
});