Models and mapsA mock ground: flat coloured tiles and hills from a formula
Draw a 3D scene over a basemap and terrain
A basemap and real elevation under a 3D scene, placed by the scene's own location on Earth.
What this example defines: its scene and, where it has them, its simulated source and its styling. The page imports and runs this file; the page's own renderer, panels and controls are not in it. For a complete app to run on your machine, download the quickstart starter.
import { createScene, type Scene } from "@klorad/api/world";
import type { Land } from "@klorad/engine-three";
/** Where the site is on Earth. The land is drawn around this place and meets the scene's ground at it. */
export const SITE_ORIGIN = { lat: 40.66, lon: 22.865, height: 8 };
/**
* Stands every object on the ground a person sees, and says how high each now stands. Terrain is
* solid: it hides what is under it, and it moves no object by itself. An app that wants its
* objects on the land asks the view how high the ground is at each place (`groundHeight`: the
* land as drawn over terrain, 0 on flat ground) and writes that height itself.
*/
export function standOnGround(scene: Scene, groundHeight: (place: { east: number; north: number }) => number): Record<string, number> {
const heights: Record<string, number> = {};
for (const o of scene.objects()) {
const at = scene.coordinateSystem.toLocal(o.position);
const up = groundHeight(at);
scene.update(o.id, { position: { east: at.east, north: at.north, up } });
heights[o.id] = up;
}
return heights;
}
/** A depot's office, a shed and a mast; nothing in the scene knows about the land under it. */
export function createLandDemo(origin: { lat: number; lon: number; height: number } = SITE_ORIGIN) {
const scene = createScene({ name: "A depot on its land", coordinateSystem: { origin } });
scene.add({ id: "office", name: "Office", position: { east: 0, north: 0 }, geometry: { kind: "box", width: 20, depth: 14, height: 9 }, properties: { kind: "building" } });
scene.add({ id: "shed", name: "Shed", position: { east: 60, north: 30 }, geometry: { kind: "box", width: 30, depth: 18, height: 7 }, properties: { kind: "building" } });
scene.add({ id: "mast", name: "Mast", position: { east: -400, north: 250 }, geometry: { kind: "box", width: 3, depth: 3, height: 40 }, properties: { kind: "mast" } });
return { scene };
}
/** The land a page asks for: a basemap as XYZ raster tiles, terrain as a quantized mesh tileset, or both. */
export function landOf(ground: string, basemap: "none" | "streets" | "aerial", terrain: boolean): Land | null {
if (basemap === "none" && !terrain) return null;
return {
...(basemap === "none" ? {} : { imagery: { url: `${ground}/${basemap}/{z}/{x}/{y}.png`, credit: "Mock tiles", maximumLevel: 19 } }),
...(terrain ? { terrain: { url: `${ground}/terrain`, credit: "Mock terrain" } } : {}),
};
}Anchor40.66000° N 22.86500° E
East, north+0.0 m +0.0 m
Digital ObjectDigital ShadowDigital TwinStale