Import and visualize 3D urban models using the
CityJSON
format.
Overview
The xeokit SDK supports importing CityJSON, a lightweight, open,
JSON-based format for representing 3D city models.
CityJSON is designed as a simpler, more developer-friendly alternative to
CityGML, while preserving the same conceptual model. It is commonly used
to represent:
Each SceneObject becomes a CityObject with
a MultiSurface geometry referencing a shared, quantized vertex array; mesh
colour + opacity become appearance.materials, and DataModel types and
relationships supply each CityObject's type and parent/child links.
Shape
%%{init:{"theme":"dark"}}%%
classDiagram
direction TB
class CityJSONLoader {
+format : "CityJSON"
+load(params, options?) Promise~void~
}
class CityJSONExporter {
+format : "CityJSON"
+write(params, options?) Promise~any~
}
class ModelLoader {
<<formats>>
}
class ModelExporter {
<<formats>>
}
ModelLoader <|-- CityJSONLoader
ModelExporter <|-- CityJSONExporter
%%{init:{"theme":"default"}}%%
classDiagram
direction TB
class CityJSONLoader {
+format : "CityJSON"
+load(params, options?) Promise~void~
}
class CityJSONExporter {
+format : "CityJSON"
+write(params, options?) Promise~any~
}
class ModelLoader {
<<formats>>
}
class ModelExporter {
<<formats>>
}
ModelLoader <|-- CityJSONLoader
ModelExporter <|-- CityJSONExporter
classDiagram
direction TB
class CityJSONLoader {
+format : "CityJSON"
+load(params, options?) Promise~void~
}
class CityJSONExporter {
+format : "CityJSON"
+write(params, options?) Promise~any~
}
class ModelLoader {
<<formats>>
}
class ModelExporter {
<<formats>>
}
ModelLoader <|-- CityJSONLoader
ModelExporter <|-- CityJSONExporter
Features
CityJSON 1.1 — the OGC standard for city models;
buildings, terrain, roads, vegetation.
Solid + Surface primitives — polyhedral solids tessellate
into TrianglesPrimitive meshes via earcut; surface
collections become SurfacePrimitive meshes.
Per-feature semantics — CityJSON Features become
DataObjects with their original
id + type preserved.
Installation
npminstall@xeokit/sdk
Example: loading a CityJSON model (with error checking)
The following example demonstrates a complete CityJSON import workflow,
including explicit error handling for all xeokit factory calls.
// 1) Create containers for geometry and city semantics constscene = newScene(); constdata = newData();
// 2) Create Viewer and WebGL renderer constviewer = newViewer({ scene }); newWebGLRenderer({ viewer });
// 3) Create a View bound to an existing canvas element constviewResult = viewer.createView({ id:"myView", elementId:"myCanvas"// Ensure this HTMLElement exists });
if (viewResult.ok === false) { handleError(viewResult.error); return; }
constview = viewResult.value;
// 4) Position the camera view.camera.eye = [1841982.93, 10.03, -5173286.74]; view.camera.look = [1842009.49, 9.68, -5173295.85]; view.camera.up = [0, 1, 0];
// 5) Enable interactive camera control newViewController(view, {});
// 6) Create target models for the loader constsceneModelResult = scene.createModel({ id:"myModel" }); if (sceneModelResult.ok === false) { handleError(sceneModelResult.error); return; }
cityjson — CityJSON Importer / Exporter
Import and visualize 3D urban models using the CityJSON format.
Overview
The xeokit SDK supports importing CityJSON, a lightweight, open, JSON-based format for representing 3D city models.
CityJSON is designed as a simpler, more developer-friendly alternative to CityGML, while preserving the same conceptual model. It is commonly used to represent:
Importing CityJSON
Use CityJSONLoader to load CityJSON data into xeokit.
The loader populates:
This separation allows applications to visualize large urban models while still querying and analyzing their underlying city objects.
Exporting CityJSON
Use CityJSONExporter to serialize a SceneModel (and optional DataModel) back out to CityJSON — the inverse of CityJSONLoader.
Each SceneObject becomes a CityObject with a
MultiSurfacegeometry referencing a shared, quantized vertex array; mesh colour + opacity becomeappearance.materials, and DataModel types and relationships supply each CityObject'stypeand parent/child links.Shape
Features
earcut; surface collections becomeSurfacePrimitivemeshes.Features become DataObjects with their original id + type preserved.Installation
Example: loading a CityJSON model (with error checking)
The following example demonstrates a complete CityJSON import workflow, including explicit error handling for all xeokit factory calls.
Notes