opensourceBIM / BIMserver-JavaScript-API

BIMserver JavaScript API
GNU Lesser General Public License v3.0
56 stars 35 forks source link

BIMserver-JavaScript-API

A JavaScript API for the OpenSource BIMserver.

Usage

Static import

Download the combined minified library and include it in your HTML.

<script type="module" src="https://github.com/opensourceBIM/BIMserver-JavaScript-API/raw/master/bimserverapi.js?_v=%VERSION%"></script>

The ?_v=%VERSION% addition is there for efficient caching purposes. Any server system serving these files can tell the client to cache these files indefinitely.

Import as an ES6 module

If you are using a transpiler such as Typescript or Babel, or a bundler such as Webpack or Rollup, you can import the module using the Import syntax.

It is also possible to load the ES6 module directly into the browser, however not all browser support this yet.

import { BimServerClient } from './js/bimserverclient.js';
const api = new BimServerClient("../..");
api.init((client, version) => {
    console.log(version.version);
});

Dynamic import

When the location on the API is not known in advance, you can use dynamic loading, in most browsers you'll need to use a "dev" version for this to work (Chrome 64 for example).

var address = "http://addressofapi";
Promise.all([
    address + "/bimserverclient.js",
    address + "/bimserverapipromise.js"
].map(x => import(x)))
.then(([BimServerClient, BimServerApiPromise]) => {
    var api = new BimServerClient.BimServerClient("../..");
    api.init((client, version) => {
        document.getElementById("version").innerHTML = JSON.stringify(version.version, 0, 2);
    });
});

Version returned from BIMserver instance

To do.

API documentation

To do.

Build the library