Sharing and accessA simulated site
Choose what visitors can see
The public package keeps only what the operator chooses to publish, and none of the site's device ids.
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, isPublic, packScene, publicPackage, type PublicationFilter, type SceneObject } from "@klorad/api/world";
import { WHITE_TOWER } from "./thessaloniki";
/** A small site: an office, a cooling unit (a twin with its readings), a gate camera and an access point, with properties a visitor must not see. */
export function createPublishDemo() {
const scene = createScene({ name: "Northgate", coordinateSystem: { origin: WHITE_TOWER } });
scene.add({ id: "office", name: "Operations office", position: { east: 0, north: 0 }, geometry: { kind: "box", width: 20, depth: 14, height: 9 }, properties: { kind: "building", tenant: "Northgate SA" } });
scene.add({ id: "crac", name: "Server room cooling", position: { east: 6, north: 2, up: 9 }, geometry: { kind: "box", width: 2.4, depth: 1.2, height: 1.8 }, correspondence: "twin", binding: { source: "bms", entity: "p:northgate:r:crac" }, properties: { kind: "equipment", maintainer: "Coolco" } });
scene.add({ id: "gate-cam", name: "Gate camera", position: { east: -14, north: -12, up: 4 }, geometry: { kind: "cylinder", radius: 0.3, height: 0.6 }, properties: { kind: "camera" } });
scene.add({ id: "door", name: "Server room door", position: { east: 3, north: -7 }, geometry: { kind: "box", width: 1, depth: 0.2, height: 2.1 }, properties: { kind: "access", reader: "HID-22" } });
scene.observe({ objectId: "crac", quantity: "temperature", value: 22.5, observedAt: Date.now(), source: "bms" });
scene.observe({ objectId: "crac", quantity: "setpoint", value: 21, observedAt: Date.now(), source: "bms" });
return { scene };
}
/** The filter the controls build: nothing is public that it does not name. */
export function filterOf(o: { readonly hideSecurity: boolean; readonly properties: readonly string[]; readonly quantities: readonly string[] }): PublicationFilter {
return { ...(o.hideSecurity ? { exclude: { kind: ["camera", "access"] } } : {}), properties: o.properties, quantities: o.quantities, alarms: [] };
}
export async function project(scene: ReturnType<typeof createPublishDemo>["scene"], filter: PublicationFilter) {
const pub = await publicPackage(await packScene(scene), filter, "Northgate, public view");
return { pub, objects: pub.chunks.flatMap((c) => c.objects) as SceneObject[], isPublic: (o: SceneObject) => isPublic(filter, o) };
}Anchor40.62637° N 22.94838° E
East, north+0.0 m +0.0 m
Digital ObjectDigital ShadowDigital TwinStale