Module @xeokit/cityjson - v0.1.0

npm version

xeokit CityJSON Importer


Import 3D urban models from CityJSON format


The xeokit SDK allows us to import 3D urban models from CityJSON, a JSON-based file format specifically designed for lightweight, user-friendly, and human-readable storage and sharing of 3D models. CityJSON can represent both basic geometric shapes and intricate objects such as buildings and trees, offering a simple alternative to other formats like CityGML.

To import a CityJSON model into xeokit, simply use the @xeokit/cityjson!loadCityJSON function, which will load the file into both a SceneModel and a DataModel.



Installation

npm install @xeokit/cityjson

Usage

In the example below, we'll import a CityJSON file into a SceneModel and a DataModel. The @xeokit/core!SDKError class is used to handle errors that may occur during the process:

import { Scene } from "@xeokit/scene";
import { Data } from "@xeokit/data";
import { loadCityJSON } from "@xeokit/cityjson";

const scene = new Scene();
const data = new Data();
const dataModel = data.createModel({ id: "myModel" });
const sceneModel = scene.createModel({ id: "myModel" });

if (dataModel instanceof SDKError) {
console.error(dataModel.message);
} else if (sceneModel instanceof SDKError) {
console.error(dataModel.message);
} else {
fetch("myModel.json")
.then(response => response.json())
.then(jsonStr => {

const fileData = JSON.parse(jsonStr);

loadCityJSON({
fileData,
sceneModel,
dataModel,
rotateX: true
}).then(() => {
sceneModel.build();
dataModel.build();
}).catch((sdkError)=>{
console.error(sdkError.message);
});
}

@xeokit/cityjson

Index

Functions

Generated using TypeDoc