Models and mapsGenerated geometry at real coordinates
Compare geographic and local coordinates
Thessaloniki's waterfront, where every point of the scene is a real place 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 { StyleFn } from "@klorad/engine-three";
import { blocks, landmarks, park, sea, square, streets, WHITE_TOWER } from "./thessaloniki";
/**
* Thessaloniki's waterfront. The scene is anchored on Earth at the White Tower; a landmark is
* placed by its latitude and longitude, the town around it in metres east and north of the
* anchor. Both end up as positions on Earth.
*/
export function buildSpace(): Scene {
const scene = createScene({ name: "Thessaloniki waterfront", coordinateSystem: { origin: WHITE_TOWER } });
const here = { east: 0, north: 0 };
// Areas and lines: the shapes of a map, in metres around the object's position.
scene.add({ id: "sea", name: "Thermaic Gulf", position: here, geometry: { kind: "polygon", footprint: sea }, properties: { role: "water" } });
scene.add({ id: "park", name: "Waterfront park", position: here, geometry: { kind: "polygon", footprint: park }, properties: { role: "park" } });
scene.add({ id: "square", name: "Square and avenue", position: here, geometry: { kind: "polygon", footprint: square }, properties: { role: "square" } });
for (const s of streets) {
scene.add({ id: s.id, name: s.name, position: here, geometry: { kind: "polyline", path: [...s.path], width: s.width }, properties: { role: "street" } });
}
// The fabric of the town: one footprint raised to a height per block.
for (const b of blocks()) {
scene.add({ id: b.id, name: "City block", position: here, geometry: { kind: "extrusion", footprint: b.footprint, height: b.height }, properties: { role: "block" } });
}
// Landmarks, each at its own latitude and longitude: a glTF model, or a pin where there is no building to draw.
for (const l of landmarks) {
scene.add({
id: l.id,
name: l.name,
position: { lat: l.lat, lon: l.lon },
orientation: { heading: l.heading },
geometry: l.model ? { kind: "model", uri: l.model } : { kind: "marker" },
properties: { role: "landmark" },
});
}
return scene;
}
const LOOK: Record<string, { color: string; opacity: number }> = {
water: { color: "#0f396b", opacity: 0.55 },
park: { color: "#1f6f5c", opacity: 0.4 },
square: { color: "#8aa3b5", opacity: 0.35 },
street: { color: "#3b5568", opacity: 0.9 },
block: { color: "#5f7d92", opacity: 0.5 },
landmark: { color: "#27cee7", opacity: 0.6 },
};
/** The town stays quiet so the landmarks, and whatever is added to the scene, stand out. */
export const spaceStyle: StyleFn = ({ object, palette }) => {
const role = String(object.properties.role ?? "");
const look = LOOK[role] ?? { color: object.color ?? palette.shadow, opacity: 1 };
return role === "landmark" || !LOOK[role] ? { ...look, label: object.name } : look;
};Click the ground to drop a pin at that latitude and longitude.
Anchor40.62637° N 22.94838° E
East, north+0.0 m +0.0 m
Landmark, by latitude and longitudeCity block, a footprint and a heightStreet, a line with a widthSea and park, areasYour pins