Docs
API reference

@klorad/engine-cesium

The scene on the globe with CesiumJS. A reader like the three.js and OpenLayers ones, drawing the same World, with buildings streamed as 3D Tiles and their elements as features.

import { createCesiumRenderer } from "@klorad/engine-cesium";

Peer dependency: cesium 1.131 or later, below 2. Cesium loads its workers and assets at run time from CESIUM_BASE_URL: copy Workers, Assets, ThirdParty and Widgets from the package's Build/Cesium to a folder your site serves, set window.CESIUM_BASE_URL to it before the renderer is created, and load Widgets/CesiumWidget/CesiumWidget.css from it.

ExportKindDescription
createCesiumRenderer(options)functionDraws the scene on a globe in container. Returns a CesiumRenderer.
CesiumView (from @klorad/engine-cesium/react)componentThe same as a React component, reading the scene from the nearest KloradProvider. Its ref is the camera every Klorad view gives (frame, frameFeature, which frames the building that holds the element since this view does not draw its elements one by one, view, setView, setDrag, metresPerPixel, footprint, toScreen), so @klorad/stage works on the globe.
CameraView, GlobeCamera, GlobePointerHittypeThe camera as every reader has it, the same as Cesium takes it, and what is under the pointer.
defaultCesiumPalettevalueThe default colours: correspondence by colour, the selection, the globe.
CesiumPalette, HeightstypeFor palette and heights.
GlobeImagery, GlobeTerraintypeImagery as { url, credit?, maximumLevel? }, an XYZ template; terrain as { url, credit? }, the address of a tileset CesiumJS reads as terrain.
GlobeLight, lightDirection, globeIntensitytype, functionsA look's sun as the globe's light (ADR-0105), by the light option or prop and setLight: { azimuth, elevation, intensity, color } over the scene's origin. A light of its own, not the clock's sun: the clock, camera, terrain and selection are left as they are, and its strength stays above two fifths of Cesium's own.
GlobeRelieftypeWhere the globe's terrain stands (ADR-0104): "off", "loading", "on" or "failed".
cesiumCapabilities, CESIUM_MODEL_FORMATSvalueWhat this reader draws: models as glTF or GLB and 3D Tiles; every shape; a feature by its building.
outlineOf, onEarth, heightOf, colourOf, featureStyle, objectOfPick, Pickedfunction, typeHow objects are placed and coloured, as plain numbers, for a reader that draws them its own way.

What it draws

GeometryOn the globe
model, format 3d-tilesThe tileset, streamed, placed by the object's position, heading, pitch, roll and scale.
model, format gltf or glbThe model, placed the same way.
model, any other formatA point at its position.
featureNothing of its own: its building's tiles draw it. Selected, a style colours its feature.
box, extrusionThe footprint raised to its height.
polygonThe area on the ground.
cylinder, sphereThe solid at its position.
polylineA corridor as wide as its width.
markerA point at its position.
splatA point at its position.
groupNothing of its own: its parts are drawn.

Options

Prop

Type

CesiumRenderer

MemberDescription
select(objectId | null)Shows an object as selected; selection is your state, not the world's.
selectFeature({ of, feature } | null)Picks out an element of a building's tileset that has no object of its own (selectedFeature on CesiumView).
setTransform(mode | null)Shows the move or turn handles on the selected object, or hides them (the transform option and prop).
setOperational(on)The Operational look (ADR-0109; the operational option and prop): a building's linked elements in the shadow colour and the rest of it faint, faint models and shapes that are not connected, and a pick that drills through the faint to the connected. No lines are drawn on the globe.
setHidden(ids)What a person hides while they work (ADR-0113; the hidden option and prop): those objects are not drawn and not picked; the others are shown.
setFeatureFilters(filters | null)Shows only some elements of a building (ADR-0067; the featureFilters option and prop): a record of the building's object id to the keys of the elements to draw, as the tiles' globalId names them. A building not named is drawn whole; null draws every building whole.
setEmphasis(emphasis | null)Makes some objects and elements stand out and draws everything else faint (ADR-0128; the emphasis option and prop): { objects, features }, object ids and, for each building by its object id, the keys of its elements as the tiles' globalId names them. A pointer passes through what is faint to what stands out. null draws everything as it is.
frame(objectIds?, { animate? })Flies to the given objects, or to all of them. A scene with no objects is framed at its own origin, from 80 metres, so the globe never opens on the whole Earth.
view()Where the camera is, as a CameraView.
setView(view, { animate? })Moves the camera to a view or changes part of it; it flies there unless animate is false. The tilt stays between 5 and 90 degrees.
setDrag(mode)What a drag with the main button or one finger does from now on: "pan" or "rotate" (the drag option, default "pan"). The other button, or Ctrl or Shift, does the other; the wheel and a pinch zoom (the right button turns or pans, it does not zoom, and Shift does not look around).
metresPerPixel()Metres per CSS pixel at the camera target, for a scale bar.
footprint()The ground in view as a box on Earth, around the target.
toScreen(point)Where a point of the scene's frame falls on the globe, in CSS pixels, and whether it is shown.
setImagery(imagery | null)Draws the globe with other imagery, or with none.
setTerrain(terrain | null)Turns terrain on, or off with null. Returns a promise that settles once the globe is drawn again; a source that does not answer is reported to onError and the globe stays as it was.
groundHeight(place)How high the ground stands at { east, north }, in metres over the scene's ground: the terrain as drawn there, and 0 on the plain globe.
enterVR()Refused: walk a scene in a headset with @klorad/engine-three.
widgetThe CesiumWidget, for what this reader does not do.
dispose()Stops following the scene and destroys the widget.

The renderer never changes the scene. It follows its events: an object added, updated or removed is drawn again at once.

Imagery and terrain

globe.setImagery({ url: "https://tiles.example.com/aerial/{z}/{x}/{y}.jpg", credit: "© Example Imagery" });
await globe.setTerrain({ url: "https://tiles.example.com/terrain", credit: "© Example Terrain" });
await globe.setTerrain(null);

Imagery is raster tiles as an XYZ template. Terrain is a tileset CesiumJS reads as terrain: an address that answers layer.json, with quantized mesh or heightmap tiles. A credit is drawn on the globe itself, beside Cesium's own mark.

A scene's ground is a flat plane at its origin's height. On a plain globe it is drawn on the globe's surface. With terrain on, the reader asks the terrain its height at the scene's origin and draws the scene's ground there, so the scene is neither buried nor left in the air where it stands; the hills around it are the terrain's own, and the scene does not follow them. The camera keeps its view of the scene through the change. With heights: "ellipsoid" the heights you stored are drawn as stored. Terrain is solid while it is on: it hides what is behind it and what is under it (the globe's depth test against terrain is on with terrain and off on the plain globe). groundHeight({ east, north }) gives the height of the drawn terrain at a place, in metres over the scene's ground, and 0 on the plain globe. The camera's view is measured on the scene's own ground, not on the hills, so view() gives the same view while the hills load, and turning terrain on or off leaves the camera as far from the scene as it was. onTerrain says where the terrain stands, so a page can say that it is loading, or that it did not load and the globe is plain: a plain globe must not pass for terrain. heightOf(object, cs, heights, level) takes that level as its last argument, nothing by default.

The reader names no provider and uses nothing of Cesium ion: the addresses, their terms and their credits are your app's. See the guide Put a basemap and terrain under a scene.

Serving Cesium's assets

Cesium loads its workers and assets from CESIUM_BASE_URL. The package ships klorad-cesium-assets, which copies them out of your app's own cesium package into a folder your app serves: run klorad-cesium-assets public/cesium before next dev and next build, set window.CESIUM_BASE_URL = "/cesium/" before loading the reader, and link /cesium/Widgets/CesiumWidget/CesiumWidget.css. Keep the copied folder out of version control.

Something wrong or unclear? Tell us.