Annotate a model

Every way to put information on objects in the 3D viewer — labels, icons, templates, live data and BVL — on one model.

About these examples

One model, the AC11 Institute, in one viewer. Pick an example: it runs in the viewer next to its code, and the viewer is reset before the next one. A JavaScript example is the body of an async function with client, viewer, objectStateManager, vid and the sample data at hand; every person, issue, booking and reading in that data is made up. An annotation shows only while its object does, and spaces are hidden by default, so the examples on rooms show their spaces first. A view of one storey hides the other storeys. The three examples on section planes cut the building with planes; clearing Show planes in the viewer's bar hides them while they keep cutting.

Overview#

The Keller on its own: room tags, issues and comment threads from the application, a sensor in every lab, and the model's own accessibility data as a check. The rest of the list takes these apart.

// The Keller cut open: a room tag on every space, issues and comment threads from the application, a temperature
// sensor in every lab and the model's own accessibility data as a check. The rest of the list takes these apart.
const {AnnotationTemplates} = viewercommon;
const keller = 'buildingStorey.attribute.Name = "Keller"';
const day = 86400000;
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet("GET qid WHERE type = IFCSPACE AND " + keller);
// A point near a corner of a room's box (render space, millimetres, z up), so annotations of one room do not meet
const corner = (x, y) => (bounds) => [x < 0 ? bounds.min[0] - x : bounds.max[0] - x, y < 0 ? bounds.min[1] - y : bounds.max[1] - y, bounds.max[2]];

objectStateManager.addAnnotationLayer({template: AnnotationTemplates.roomTag, group: "rooms", query: {where: "type = IFCSPACE AND " + keller}});

objectStateManager.addAnnotationLayer({template: AnnotationTemplates.issue, key: "globalId", group: "issues", anchor: corner(900, 900),
	rows: data.issues.rows.map((row) => ({key: "issue-" + row.data.number, globalId: row.globalId,
		data: {...row.data, due: Date.now() + row.data.dueInDays * day}}))});

objectStateManager.addAnnotationLayer({template: AnnotationTemplates.conversation, key: "globalId", group: "threads", anchor: corner(-900, 900),
	rows: data.conversations.rows.map((row) => ({globalId: row.globalId, data: {...row.data, count: row.data.comments.length,
		comments: row.data.comments.map((comment) => ({...comment, at: Date.now() - comment.minutesAgo * 60000}))}}))});

const spaces = await client.bim.query([vid], "GET qid, attribute.Name, attribute.LongName, property.Pset_SpaceCommon.HandicapAccessible, " +
	"property.Pset_SpaceThermalRequirements.SpaceTemperatureMax WHERE type = IFCSPACE AND " + keller);

objectStateManager.addAnnotationLayer({template: AnnotationTemplates.checkResult, group: "access", anchor: corner(-700, -700),
	rows: spaces.filter((space) => space.property?.Pset_SpaceCommon?.HandicapAccessible).map((space) => {
		const accessible = space.property.Pset_SpaceCommon.HandicapAccessible.value === true;
		return {qid: space.qid, data: {check: "Accessibility", object: space.attribute.Name.value, rule: "Handicap accessible",
			outcome: accessible ? "pass" : "warn", expected: "true", actual: String(accessible)}};
	})});

objectStateManager.addAnnotationLayer({template: AnnotationTemplates.sensor, key: "qid", group: "sensors", anchor: corner(1400, -700),
	rows: spaces.filter((space) => /^Labor/.test(space.attribute.LongName?.value ?? "")).map((space, i) => ({qid: space.qid,
		data: {name: "T-" + space.attribute.Name.value, kind: "temperature", unit: "°C", value: 19.6 + i * 0.7, updatedAt: Date.now() - 60000,
			warn: [18, space.property?.Pset_SpaceThermalRequirements?.SpaceTemperatureMax?.value ?? 20], alarm: [15, 26]}}))});

The Keller on its own, with a room tag, issues, threads, a sensor and a check on its rooms.

Look: hover a pin for its card; orbit, and what goes behind walls fades or hides.

Labels and icons

Text labels#

The number and long name of every space on the Erdgeschoss, as two-line text labels. One TextAnnotation per object, added together.

// The number and long name of every space on the Erdgeschoss, as two-line labels on the spaces
const {TextAnnotation} = viewercommon;

const spaces = await client.bim.query([vid], 'GET qid, attribute.Name, attribute.LongName WHERE type = IFCSPACE AND buildingStorey.attribute.Name = "Erdgeschoss"');
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet(spaces.map((space) => space.qid));
const labels = spaces.map((space) => {
	const label = new TextAnnotation();
	label.qid = space.qid;
	label.lines = [space.attribute.Name.value, space.attribute.LongName?.value ?? ""];
	label.group = "spaces";
	return label;
});
await objectStateManager.addAnnotations(labels);

The Erdgeschoss on its own, a label on each space.

Look: zoom out until labels overlap; the nearer one stays and shows how many it stands for.

Icons with a click#

A wrench on each of the four technical rooms of the Keller. A click on an icon selects its room.

// A wrench on each of the four technical rooms of the Keller; a click on one selects its room
const {SvgAnnotation} = viewercommon;

const rooms = await client.bim.query([vid], 'GET qid WHERE type = IFCSPACE AND buildingStorey.attribute.Name = "Keller" AND attribute.LongName STARTS_WITH "Technikraum"');
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet(rooms.map((room) => room.qid));
for (const room of rooms) {
	const icon = new SvgAnnotation();
	icon.qid = room.qid;
	// asset() is a URL of the app's own files; in your application, use an icon of your own
	icon.image = asset("img/glyphicons-basic/glyphicons-basic-316-wrench.svg");
	icon.mainColor = "#008CC9";
	icon.group = "technical-rooms";
	icon.click = () => objectStateManager.setToSelectionSet([room.qid]);
	await objectStateManager.addAnnotation(icon);
}

The Keller, a wrench on Technikraum I to IV.

Look: click a wrench; the room is selected.

At a point you click#

A note where you click on a surface, rather than on a whole object. selectVertex hands over the point; its position is in the coordinates an annotation takes.

// Click a surface: a note appears where you clicked, and the next click places the next one
const {TextAnnotation} = viewercommon;

let count = 0;
let selector = null;
const place = () => selector = viewer.selectVertex((point) => {
	if (!point) {
		return;
	}
	const note = new TextAnnotation();
	note.position = point.position;
	note.lines = ["Note " + ++count, "Check this spot"];
	note.group = "notes";
	objectStateManager.addAnnotation(note);
	place();
});
place();
// Stop waiting for the next click: until it comes, the viewer snaps to points instead of lighting up objects
onReset(() => selector.cancel());

The Keller; each click on a surface adds a note there.

Look: click a wall, then the floor; each click adds the next note.

Images#

A picture pinned to the seminar room. An ImageAnnotation takes any image URL; this one is a sketch in a data URL.

// A photo pinned to the seminar room. The image is a made-up sketch as a data URL; any image URL works
const {ImageAnnotation} = viewercommon;

const [room] = await client.bim.query([vid], 'GET qid WHERE type = IFCSPACE AND attribute.LongName = "Seminarraum"');
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet([room.qid]);
const sketch = '<svg xmlns="http://www.w3.org/2000/svg" width="160" height="100" viewBox="0 0 160 100">' +
	'<rect width="160" height="100" fill="#DCE3EA"/><path d="M14 86 L80 30 L146 86 Z" fill="#F4F6F8"/>' +
	'<rect x="52" y="44" width="56" height="34" fill="#B9C4CF"/><circle cx="124" cy="24" r="10" fill="#EFB920"/></svg>';

const photo = new ImageAnnotation();
photo.qid = room.qid;
photo.image = "data:image/svg+xml," + encodeURIComponent(sketch);
photo.group = "photos";
await objectStateManager.addAnnotation(photo);

The Keller with a sketch pinned to the Seminarraum.

Look: the picture keeps its size while you zoom.

Live text, without templates#

A temperature in Labor K1 that changes every second, done the way it is done without templates: replace the label's lines. The sensors example below does it for many rooms at once.

// A temperature in Labor K1 that changes every second, the way it is done without templates: replace the lines.
// The sensors example further down does the same with a template and many rooms at once.
const {TextAnnotation} = viewercommon;

const [lab] = await client.bim.query([vid], 'GET qid WHERE type = IFCSPACE AND attribute.LongName = "Labor K1"');
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet([lab.qid]);
const reading = new TextAnnotation();
reading.qid = lab.qid;
reading.group = "reading";
let temperature = 21.0;
reading.lines = ["Labor K1", temperature.toFixed(1) + " °C"];
await objectStateManager.addAnnotation(reading);

const timer = setInterval(() => {
	temperature += (Math.random() - 0.5) * 0.4;
	reading.lines = ["Labor K1", temperature.toFixed(1) + " °C"];
}, 1000);
onReset(() => clearInterval(timer));

The labs of the Keller; Labor K1 shows a temperature that changes every second.

Look: the reading changes in place; nothing else redraws.

A busy view, readable

Behind walls#

Every one of the 206 windows labelled, in three groups that behave differently behind walls: hidden, dimmed, and always shown.

// Every window of the building labelled, in three groups that do three different things behind walls: hidden,
// dimmed, and always shown
const {TextAnnotation} = viewercommon;
const modes = ["hide", "dim", "none"];

const items = await client.bim.query([vid], "GET qid, buildingStorey.attribute.Name WHERE type = IFCWINDOW");
const labels = items.map((item, i) => {
	const label = new TextAnnotation();
	label.qid = item.qid;
	label.lines = ["Window " + (i + 1), item.buildingStorey?.attribute?.Name?.value ?? ""];
	label.occlusion = modes[i % 3];
	label.group = "windows-" + modes[i % 3];
	return label;
});
await objectStateManager.addAnnotations(labels);

The building from the south-east, a label on every window.

Look: orbit to the back; one window in three keeps its label, one dims, one hides.

Only what can be picked hides an annotation: the test reads the picking pass. With an object state manager made with {pickability: true}, setPickableSet decides both which objects take a click and which can hide a label, so objects shown only as context (the dimmed rest of a takeoff, say) neither stop a click nor hide a value. The quantity takeoff demo (Quantity takeoff) works that way.

An annotation on the top or bottom of its object, such as a room tag on the floor, stands for the whole object. It shows while the object's centre line, from floor to ceiling, can be seen, and nothing inside the object's box hides it. So the furniture in a room does not hide its tag, nor do the room's own walls when you look at a slant. The slab under the room hides the tag from below, and the storey above hides it from above.

Merging and counts#

Labels on all windows: overlapping ones merge into the nearest, which shows how many it stands for. An icon on every door, coloured by storey: merged icons show a ring of their colours.

// Labels on all windows: overlapping ones merge into the nearest, which shows how many it stands for. An icon on
// every door, coloured by storey: merged icons show a ring of their colours
const {TextAnnotation, SvgAnnotation} = viewercommon;
const STOREY_COLOURS = {"Keller": "#8E44AD", "Erdgeschoss": "#008CC9", "1. Obergeschoss": "#0F8B6C", "2. Obergeschoss": "#B45309", "Dachgeschoss": "#555555"};

const windows = await client.bim.query([vid], "GET qid WHERE type = IFCWINDOW");
await objectStateManager.addAnnotations(windows.map((item, i) => {
	const label = new TextAnnotation();
	label.qid = item.qid;
	label.lines = ["Window " + (i + 1)];
	label.group = "windows";
	return label;
}));

const doors = await client.bim.query([vid], "GET qid, buildingStorey.attribute.Name WHERE type = IFCDOOR");
await objectStateManager.addAnnotations(doors.map((item) => {
	const icon = new SvgAnnotation();
	icon.qid = item.qid;
	icon.image = asset("img/glyphicons-basic/glyphicons-basic-657-door.svg");
	icon.mainColor = STOREY_COLOURS[item.buildingStorey?.attribute?.Name?.value] ?? "#555555";
	icon.group = "doors";
	return icon;
}));

// Labels as dots that grow when hovered: viewer.setTextAnnotationMode("dot")

The building from the south-east, window labels with counts, door icons with rings.

Look: zoom in and the merged labels come apart; hover a ring for what it holds.

Limits#

At most 30 window labels, those nearest the camera, and at most 50 annotations in the viewer altogether.

// At most 30 window labels, those nearest the camera, and at most 50 annotations in the viewer altogether
const {TextAnnotation} = viewercommon;
const label = (item, text, group, limit) => {
	const annotation = new TextAnnotation();
	annotation.qid = item.qid;
	annotation.lines = [text];
	annotation.group = group;
	annotation.groupLimit = limit;
	return annotation;
};

const windows = await client.bim.query([vid], "GET qid WHERE type = IFCWINDOW");
await objectStateManager.addAnnotations(windows.map((item, i) => label(item, "Window " + (i + 1), "windows", 30)));

const doors = await client.bim.query([vid], "GET qid WHERE type = IFCDOOR");
await objectStateManager.addAnnotations(doors.map((item, i) => label(item, "Door " + (i + 1), "doors", null)));

viewer.setAnnotationLimit(50);

The building from the south-east; only the nearest labels show.

Look: orbit; the labels move to the windows that are nearest now.

Smaller further away#

Window labels drawn smaller further from the camera, down to 40 % of their size, and not at all beyond 40 m.

// Window labels that are drawn smaller further from the camera (down to 40 %), and not at all beyond 40 m
const {TextAnnotation} = viewercommon;

const windows = await client.bim.query([vid], "GET qid WHERE type = IFCWINDOW");
await objectStateManager.addAnnotations(windows.map((item, i) => {
	const label = new TextAnnotation();
	label.qid = item.qid;
	label.lines = ["Window " + (i + 1)];
	label.scaleByDistance = true;
	label.maxDistanceMm = 40000;
	label.group = "windows";
	return label;
}));

The south-west corner up close, window labels shrinking along the façade and gone beyond 40 m.

Look: zoom out; the labels shrink, then disappear at 40 m.

On hover only#

A label that appears beside a window only while the window is hovered, outside its footprint so it does not cover it.

// A label that appears beside a window only while the window is hovered, outside the window's footprint
const {TextAnnotation} = viewercommon;

const windows = await client.bim.query([vid], "GET qid, buildingStorey.attribute.Name, property.Pset_WindowCommon.ThermalTransmittance WHERE type = IFCWINDOW");
await objectStateManager.addAnnotations(windows.map((item, i) => {
	const label = new TextAnnotation();
	label.qid = item.qid;
	const u = item.property?.Pset_WindowCommon?.ThermalTransmittance?.value;
	label.lines = ["Window " + (i + 1) + ", " + (item.buildingStorey?.attribute?.Name?.value ?? ""), u == null ? "U-value unknown" : "U = " + u + " W/m²K"];
	label.visibility = "hover";
	label.group = "windows";
	return label;
}));

The building from the south-east; hovering a window shows its label.

Look: move over the façade; each window's label follows the pointer.

Section planes#

Labels on every space, and a section box around the 1. Obergeschoss. Its annotation mode decides what happens to the labels it cuts away: hide them, ignore the box, or project them onto its faces.

// Labels on every space of the building, and a section box around the 1. Obergeschoss. What the box does with the
// labels it cuts away is its annotation mode: "hide" (the default), "ignore", or "project" onto its faces
const {TextAnnotation} = viewercommon;

const spaces = await client.bim.query([vid], "GET qid, attribute.Name WHERE type = IFCSPACE");
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet(spaces.map((space) => space.qid));
await objectStateManager.addAnnotations(spaces.map((space) => {
	const label = new TextAnnotation();
	label.qid = space.qid;
	label.lines = [space.attribute.Name.value];
	label.group = "spaces";
	return label;
}));

// Around the storey's spaces, from floor to ceiling: its stair reaches into the storey above
const rooms = await objectStateManager.queryToQids('GET qid WHERE type = IFCSPACE AND buildingStorey.attribute.Name = "1. Obergeschoss"');
const box = viewer.getSectionPlanes().startSectionBox(await viewer.getMainAabbFor(rooms));
box.setAnnotationMode("project");

A section box around the 1. Obergeschoss; the labels of the other storeys sit on its faces.

Look: the labels of the other storeys sit on the box's top and bottom faces; the next example switches between the modes.

Hide, ignore or project#

The three annotation modes on one plane, a button each: a section plane through the middle of the building cuts away its east half, and the buttons in the viewer's bar choose what it does with the labels of the corridors there. The frame's toolbar stands in for the controls of your application.

// A label on the corridors at both ends of every storey, and a section plane through the middle of the building that
// cuts away its east half. The buttons in the viewer's bar set the plane's annotation mode: what it does with the labels
// on the side it cuts away
const {TextAnnotation} = viewercommon;

const corridors = await client.bim.query([vid], 'GET qid, attribute.LongName WHERE type = IFCSPACE AND attribute.LongName STARTS_WITH "Flur" ' +
	'AND (attribute.LongName ENDS_WITH "West" OR attribute.LongName ENDS_WITH "Ost")');
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet(corridors.map((space) => space.qid));
await objectStateManager.addAnnotations(corridors.map((space) => {
	const label = new TextAnnotation();
	label.qid = space.qid;
	label.lines = [space.attribute.LongName.value];
	label.group = "corridors";
	// Seen from outside: through the façade, which would hide every one of them
	label.occlusion = "none";
	return label;
}));

// Its normal points east, to the side it cuts away; its handle sits at roof height, clear of the labels
const spaces = await objectStateManager.queryToQids("GET qid WHERE type = IFCSPACE");
const {min, max} = await viewer.getObjectsAabb(spaces);
const plane = viewer.getSectionPlanes().startPlaneAt([(min[0] + max[0]) / 2, (min[1] + max[1]) / 2, max[2]], [1, 0, 0]);

// The frame's bar stands in for the controls of your application
const modes = [
	{value: "hide", label: "Hide", title: "The plane hides the labels on the side it cuts away, as it hides the building there (the default)"},
	{value: "ignore", label: "Ignore", title: "The labels on the side the plane cuts away stay where they are"},
	{value: "project", label: "Project", title: "The labels on the side the plane cuts away move onto the plane"}
];
toolbar.separator();
toolbar.note("Labels the plane cuts away:");
toolbar.radio(modes, plane.getAnnotationMode(), (mode) => {
	plane.setAnnotationMode(mode);
	status(modes.find((item) => item.value == mode).title);
});

The building cut through the middle; the labels of its east corridors hidden, left where they were, or on the cut.

Look: Ignore leaves the east labels in the air where the cut-away half stood; Project lines them up on the cut, each at its own storey.

From the top#

The same three buttons on a plane from the top, the way you look into a storey: the plane cuts just under the ceiling of the 1. Obergeschoss, and every space of the building has its number, in its storey's colour. The buttons choose what the plane does with the numbers of the 2. Obergeschoss and the Dachgeschoss above it. Its reach keeps that to one storey: setAnnotationReach(3000) hides every label more than 3 m past the plane, whatever the mode, so in a tower only the storey above comes along. The spaces are taken out of the end caps (removeFromEndcapsSet): they are solids too, and their caps would close every room; the walls and slabs keep theirs.

// The number of every space of the building in its storey's colour, and a section plane from the top just under the
// ceiling of the 1. Obergeschoss. The buttons in the viewer's bar set the plane's annotation mode, what it does with
// the numbers of the 2. Obergeschoss and the Dachgeschoss, the storeys it cuts away; and its reach, how far past the
// plane that mode goes
const {TextAnnotation} = viewercommon;
const STOREY_COLOURS = {"Keller": "#8E44AD", "Erdgeschoss": "#008CC9", "1. Obergeschoss": "#0F8B6C", "2. Obergeschoss": "#B45309", "Dachgeschoss": "#555555"};

// Spaces are solids too: with end caps, the cut would close every room under a hatched lid. Only theirs go, the walls
// and slabs keep theirs; onReset puts them back for the next example
const spaceQids = await objectStateManager.queryToQids("GET qid WHERE type = IFCSPACE");
await objectStateManager.removeFromEndcapsSet(spaceQids);
onReset(() => objectStateManager.addToEndcapsSet(spaceQids));

// Its normal points up, to the side it cuts away. Not at the ceiling itself: there it runs along the underside of the
// floor slab above. Its handle sits on the south-west corner of the storey, clear of the labels
const rooms = await objectStateManager.queryToQids('GET qid WHERE type = IFCSPACE AND buildingStorey.attribute.Name = "1. Obergeschoss"');
const {min, max} = await viewer.getObjectsAabb(rooms);
const plane = viewer.getSectionPlanes().startPlaneAt([min[0], min[1], max[2] - 100], [0, 0, 1]);
// One storey of this building is 3 m: with that reach the storey above keeps its labels and those further up are
// hidden, whatever the mode. Measured from each label's own place, before Project moves it
const reaches = [
	{value: "storey", label: "One storey", distance: 3000, title: "The mode reaches 3 m past the plane: the labels of the storeys above that are hidden"},
	{value: "all", label: "All storeys", distance: Infinity, title: "The mode reaches every storey above the plane (the default)"}
];
plane.setAnnotationReach(reaches[0].distance);

const spaces = await client.bim.query([vid], "GET qid, attribute.Name, buildingStorey.attribute.Name WHERE type = IFCSPACE");
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet(spaces.map((space) => space.qid));
await objectStateManager.addAnnotations(spaces.map((space) => {
	const storey = space.buildingStorey?.attribute?.Name?.value;
	const colour = STOREY_COLOURS[storey] ?? "#555555";
	const label = new TextAnnotation();
	label.qid = space.qid;
	label.lines = [space.attribute.Name.value];
	label.backgroundColor = colour + "CC";
	label.backgroundHoverColor = colour;
	// A group per storey: labels merge only within their group, so one of the 2. Obergeschoss never takes in one of
	// the 1. Obergeschoss below it
	label.group = "spaces-" + storey;
	return label;
}));

// The frame's bar stands in for the controls of your application
const modes = [
	{value: "hide", label: "Hide", title: "The plane hides the labels of the storeys above it, as it hides the storeys (the default)"},
	{value: "ignore", label: "Ignore", title: "The labels of the storeys above the plane stay where they are"},
	{value: "project", label: "Project", title: "The labels of the storeys above the plane move down onto it"}
];
toolbar.separator();
toolbar.note("Labels the plane cuts away:");
toolbar.radio(modes, plane.getAnnotationMode(), (mode) => {
	plane.setAnnotationMode(mode);
	status(modes.find((item) => item.value == mode).title);
});
toolbar.note("Reach:");
toolbar.radio(reaches, reaches[0].value, (value) => {
	const reach = reaches.find((item) => item.value == value);
	plane.setAnnotationReach(reach.distance);
	status(reach.title);
});

The 1. Obergeschoss cut open from the top, a number on every space; those of the storey above hidden, left where they were, or on the cut, and those further up hidden.

Look: Project puts each number of the 2. Obergeschoss on the cut, right above the room under it (319 over 219); Ignore leaves them higher up, off their rooms; Hide shows the 1. Obergeschoss alone. All storeys brings back the grey numbers of the Dachgeschoss, almost 5 m past the plane.

Templates from model data

Object labels#

The name, long name and type with its icon, on the spaces and doors of the Erdgeschoss. The objectLabel template asks for its fields itself, so a WHERE clause is all it needs, in JavaScript or in BVL.

// The name, long name and type with its icon on the spaces and doors of the Erdgeschoss: the objectLabel template
// gets its fields itself, so a WHERE clause is all it needs
const erdgeschoss = 'buildingStorey.attribute.Name = "Erdgeschoss"';
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet("GET qid WHERE type = IFCSPACE AND " + erdgeschoss);
objectStateManager.addAnnotationLayer({
	template: "objectLabel",
	group: "labels",
	query: {where: "type IN (IFCSPACE, IFCDOOR) AND " + erdgeschoss}
});
// SHOW: spaces are hidden by default, and an annotation shows only while its object does
if (type IN (IFCSPACE, IFCDOOR) AND buildingStorey.attribute.Name = "Erdgeschoss") {
	SHOW annotate(template("objectLabel") "labels");
}

The Erdgeschoss on its own, an object label on each space and door.

Look: switch to the BVL tab; the same labels come from the server's resolution.

Room tags#

Number, name and net floor area on every space of the 1. Obergeschoss, as the architectural room tag on the floor of the room. The same in BVL.

// The architectural room tag on every space of the 1. Obergeschoss: number, name and net floor area, on the floor of
// the room, drawn smaller further away
const where = 'type = IFCSPACE AND buildingStorey.attribute.Name = "1. Obergeschoss"';
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet("GET qid WHERE " + where);
objectStateManager.addAnnotationLayer({
	template: "roomTag",
	group: "rooms",
	scaleByDistance: true,
	query: {where}
});
// SHOW: spaces are hidden by default, and an annotation shows only while its object does
if (type = IFCSPACE AND buildingStorey.attribute.Name = "1. Obergeschoss") {
	SHOW annotate(template("roomTag") scale distance anchor bottom "rooms");
}

The 1. Obergeschoss on its own, a room tag on each of its spaces.

Look: zoom out; the tags shrink to 40 % and stay readable longer than the rooms.

Properties of your own#

The spaces of the Keller with fields of your own GET: their category, whether they are accessible, their maximum temperature. A card shows three fields; with more, hover it for all of them.

// The spaces of the Keller with fields of your own GET: their category, whether they are accessible and their
// maximum temperature, from the model's property sets. A card shows three fields; with more, hover it for all of them
const where = 'type = IFCSPACE AND buildingStorey.attribute.Name = "Keller"';
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet("GET qid WHERE " + where);
objectStateManager.addAnnotationLayer({
	template: "properties",
	group: "spaces",
	query: {
		where,
		get: {
			Category: "property.Pset_SpaceCommon.Category",
			Accessible: "property.Pset_SpaceCommon.HandicapAccessible",
			"Max. temperature": "property.Pset_SpaceThermalRequirements.SpaceTemperatureMax"
		}
	}
});

The Keller on its own, its spaces with category, accessibility and temperature.

Look: the keys read as you named them; quantities keep their units.

What you select#

Whatever you select gets its type and storey. The selection is a query parameter, so it is never spliced into the query text.

// Whatever you select gets its properties: the selection is bound to the query as a parameter, never spliced into it
const get = {Type: "niceType", Storey: "buildingStorey.attribute.Name"};
const layer = objectStateManager.addAnnotationLayer({template: "properties", group: "selection", rows: []});

const follow = () => {
	const selected = [...objectStateManager.getSelectedQids()].map(String);
	layer.setQuery(selected.length == 0 ? null : {where: "qid IN $selection", parameters: {selection: selected}, get});
};
const listener = {addedToSelectionSet: follow, removedFromSelectionSet: follow, setToSelectionSet: follow};
objectStateManager.addSelectionListener(listener);
onReset(() => objectStateManager.removeSelectionListener(listener));
status("Select objects in the viewer");

The Erdgeschoss; selected objects get a card with their type and storey.

Look: select a few objects with Shift; the cards follow the selection.

A template of your own#

A template written on the page: the category of a space as a coloured chip, with its net floor area beside it. Its fields are BQL, so the layer only needs a WHERE clause. With hover: "template" it draws its own hover: ctx.hovered is true while the chip or its space is under the pointer, and the chip is drawn again when that changes.

// A template written here: the category of a space as a coloured chip, with its net floor area beside it. Its fields
// are BQL, so the layer only needs a WHERE clause
const {defineTemplate, html} = viewercommon;
const COLOURS = {Office: "#33689B", Labor: "#8E44AD", Technik: "#B45309", WC: "#0F8B6C", Flur: "#777777"};
const colourOf = (category) => COLOURS[category] ?? "#555555";

const spaceCategory = defineTemplate({
	name: "docs.spaceCategory",
	fields: {category: "property.Pset_SpaceCommon.Category", area: "quantity.*.NetFloorArea"},
	// Hovered, or its space is: ringed in its category's colour (ctx.hovered)
	hover: "template",
	css: `
		.chip { display: inline-flex; align-items: center; gap: 6px; font: 12px var(--bwa-font); white-space: nowrap; }
		.chip b { padding: 2px 8px; border-radius: 10px; color: #FFFFFF; background: var(--c); font-weight: 600; }
		.chip span { padding: 1px 6px; border-radius: 3px; background: var(--bwa-surface); color: var(--bwa-text); box-shadow: var(--bwa-shadow); }
		.chip b, .chip span { transition: box-shadow 150ms ease-out; }
		.chip.hovered b { box-shadow: 0 0 0 2px #FFFFFF, 0 0 0 3.5px var(--c); }
		.chip.hovered span { box-shadow: 0 0 0 1.5px var(--c), 0 4px 10px rgba(27, 39, 51, .2); }`,
	status: (d) => ({color: colourOf(d.category), label: d.category ?? "no category"}),
	label: (d) => (d.category ?? "No category") + (d.area ? ", " + d.area : ""),
	render: (d, ctx) => html`<div class=${ctx.hovered ? "chip hovered" : "chip"} style=${"--c:" + colourOf(d.category)}><b>${d.category ?? "—"}</b>${d.area ? html`<span>${d.area}</span>` : null}</div>`
});

const where = 'type = IFCSPACE AND buildingStorey.attribute.Name = "Keller"';
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet("GET qid WHERE " + where);
objectStateManager.addAnnotationLayer({template: spaceCategory, group: "categories", query: {where}});

The Keller on its own, a category chip on every space.

Look: hover a chip or its space, and the chip rings in its colour; the chips merge by colour, and a count's tooltip lists the categories it holds.

A card of your own can look like the built-in ones: AnnotationTemplateKit.css, included in the template's css, styles a .card with its .head, .eyebrow, h3, .facts, .meta, .actions and .button, and AnnotationTemplateKit.pill(color, label) draws a status pill. The repair notes demo (Annotations to mobile) is built that way.

One per zone#

One annotation per zone of the model, on the bounds of its spaces together: its name, description and number of spaces.

// One annotation per zone of the model, on the bounds of its spaces together: the zone's name, its description and
// how many spaces it has. A row with qids sits on the union of their boxes
const zones = await client.bim.query([vid], "GET attribute.Name, attribute.Description, members(qid) WHERE type = IFCZONE");
// The zones' spaces are hidden by default, and a row about several objects shows only while one of them does
await objectStateManager.addToVisibleSet("GET qid WHERE type = IFCSPACE");

objectStateManager.addAnnotationLayer({
	template: "properties",
	group: "zones",
	occlusion: "none",
	rows: zones.filter((zone) => (zone.members ?? []).length > 0).map((zone) => ({
		key: zone.attribute.Name.value,
		qids: zone.members.map((member) => member.qid),
		data: {name: zone.attribute.Name.value, Spaces: zone.members.length, Description: zone.attribute.Description?.value}
	}))
});

The building from the south-west, a card in the middle of each zone.

Look: the temperature zones span storeys; their cards sit between them.

Data from your application

Issues#

Eight issues from an issue tracker, each on a room by its GlobalId: a pin in its status colour, open and urgent ones in front, a card on hover with buttons your application handles.

// Eight issues from an issue tracker (a JSON file here), each on a room by its GlobalId: a pin in its status colour,
// open and urgent ones in front, a card on hover, and the card's buttons wired to the application
const day = 86400000;

const issues = objectStateManager.addAnnotationLayer({
	template: "issue",
	key: "globalId",
	group: "issues",
	rows: data.issues.rows.map((row) => ({key: "issue-" + row.data.number, globalId: row.globalId,
		data: {...row.data, due: Date.now() + row.data.dueInDays * day}})),
	onAction: (action, row) => {
		if (action == "zoom") {
			objectStateManager.viewFit([row.qid], {animate: true, margin: 20});
		} else if (action == "open") {
			status("Here your application opens issue #" + row.data.number);
		}
	}
});
issues.addEventListener("expand", (event) => status("Card of #" + event.detail.row.data.number + (event.detail.pinned ? ", pinned" : "")));
// The rooms are spaces, hidden by default, and an annotation shows only while its object does: show the objects the
// layer found for the GlobalIds
await issues.ready;
await objectStateManager.addToVisibleSet([...issues.rows()].map((row) => row.qid));

The Keller on its own, issue pins on its rooms; Labor K1 has two.

Look: hover a pin, then click Zoom to in its card.

Conversations#

Comment threads on rooms: who takes part and how much is unread, the last comments on hover. Closing a thread changes its row, and the annotation follows.

// Comment threads on rooms: who takes part and how much is unread, the last comments on hover. Close thread changes
// the row, and the annotation follows
const threads = objectStateManager.addAnnotationLayer({
	template: "conversation",
	key: "globalId",
	group: "threads",
	rows: data.conversations.rows.map((row) => ({globalId: row.globalId, data: {...row.data, count: row.data.comments.length,
		comments: row.data.comments.map((comment) => ({...comment, at: Date.now() - comment.minutesAgo * 60000}))}})),
	onAction: (action, row) => {
		if (action == "close") {
			threads.update(row.key, {status: row.data.status == "open" ? "closed" : "open", unread: 0});
		} else if (action == "reply") {
			status("Here your application opens the reply box of the thread");
		}
	}
});
// The rooms are spaces, hidden by default, and an annotation shows only while its object does: those of the Keller
// show, the thread on a room upstairs stays hidden with it
await objectStateManager.addToVisibleSet('GET qid WHERE type = IFCSPACE AND buildingStorey.attribute.Name = "Keller"');

The Keller on its own, comment threads on the seminar room and Labor K4.

Look: click Close thread in a card; the stack greys out.

BCF topics#

The topics of a BCF file, placed by the GlobalIds of their components: the topic type's code in the status colour, the details on hover.

// The topics of a BCF file (as JSON here), placed by the GlobalIds of their components: the topic type's code in the
// status colour, the details on hover, Open viewpoint flies to the component
const day = 86400000;

const topics = objectStateManager.addAnnotationLayer({
	template: "bcfTopic",
	group: "bcf",
	rows: data.bcfTopics.rows.map((row) => ({globalId: row.globalId, data: {...row.data, dueDate: Date.now() + row.data.dueInDays * day}})),
	onAction: (action, row) => {
		if (action == "viewpoint") {
			objectStateManager.viewFit([row.qid], {animate: true, margin: 20});
		} else {
			status("Here your application opens the topic \"" + row.data.title + "\"");
		}
	}
});
// The topics' components are rooms here, spaces hidden by default, and an annotation shows only while its object does
await topics.ready;
await objectStateManager.addToVisibleSet([...topics.rows()].map((row) => row.qid));

The Keller on its own, BCF topics on four rooms.

Look: Open viewpoint in a card flies to the component.

Sensors#

A temperature sensor in every lab and meeting room of the Keller, against the room's own maximum temperature from the model, and CO₂ in the seminar room. A simulated feed sends a reading per room every second.

// A temperature sensor in every lab and meeting room of the Keller, against the room's own maximum temperature from
// the model, and CO2 in the seminar room. A simulated feed sends a reading per room every second; one sensor has gone
// quiet. Far away the sensors are dots; alarms come to the front
const rooms = await client.bim.query([vid], "GET qid, attribute.GlobalId, attribute.Name, attribute.LongName, property.Pset_SpaceThermalRequirements.SpaceTemperatureMax " +
	'WHERE type = IFCSPACE AND buildingStorey.attribute.Name = "Keller" AND (attribute.LongName STARTS_WITH "Labor" OR attribute.LongName STARTS_WITH "Besprechungsraum" OR attribute.LongName = "Seminarraum")');

// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet(rooms.map((room) => room.qid));
// A random walk per room, seeded by its GlobalId: a room reads about the same every time
const random = (seed) => () => (seed = (Math.imul(seed ^ (seed >>> 15), 0x2C1B3C6D) + 0x9E3779B9) >>> 0) / 4294967296;
const seedOf = (text) => [...text].reduce((hash, c) => Math.imul(hash ^ c.charCodeAt(0), 16777619) >>> 0, 2166136261);

const sensors = rooms.map((room, i) => {
	const co2 = room.attribute.LongName.value == "Seminarraum";
	const max = room.property?.Pset_SpaceThermalRequirements?.SpaceTemperatureMax?.value ?? 22;
	const next = random(seedOf(room.attribute.GlobalId.value));
	const centre = co2 ? 820 : max - 1;
	const step = co2 ? 60 : 0.35;
	const history = [];
	let value = centre;
	for (let h = 0; h < 24; h++) {
		value += (next() - 0.5) * step * 2;
		history.push(value);
	}
	return {qid: room.qid, next, centre, step, quiet: i == rooms.length - 1,
		data: {name: (co2 ? "CO2-" : "T-") + room.attribute.Name.value, space: room.attribute.LongName.value, kind: co2 ? "co2" : "temperature",
			unit: co2 ? "ppm" : "°C", warn: co2 ? [null, 1000] : [18, max], alarm: co2 ? [null, 1400] : [15, max + 3],
			value, history, updatedAt: Date.now() - (i == rooms.length - 1 ? 40 * 60000 : 30000)}};
});

const layer = objectStateManager.addAnnotationLayer({template: "sensor", key: "qid", group: "sensors", rows: sensors.map(({qid, data}) => ({qid, data}))});

const timer = setInterval(() => {
	layer.updateMany(sensors.filter((sensor) => !sensor.quiet).map((sensor) => {
		const pull = (sensor.centre - sensor.data.value) * 0.1;
		sensor.data.value += pull + (sensor.next() - 0.5) * sensor.step * 2;
		sensor.data.history = [...sensor.data.history.slice(1), sensor.data.value];
		return [String(sensor.qid), {value: sensor.data.value, history: sensor.data.history, updatedAt: Date.now()}];
	}));
}, 1000);
onReset(() => clearInterval(timer));

The labs of the Keller with live readings; one sensor has gone quiet.

Look: zoom out past 30 m; the sensors become dots in their state's colour.

Desks#

The 52 desks of the building as free, booked or in use, who and until when on hover. A template written here, on bookings that change every two seconds.

// The 52 desks of the building as free, booked or in use, who and until when on hover: a template written here, on
// bookings that change every two seconds
const {defineTemplate, html} = viewercommon;
const STATES = {"free": {color: "#5CB85C", label: "Free"}, "booked": {color: "#F0AD4E", label: "Booked"}, "in-use": {color: "#D9534F", label: "In use"}};

const desk = defineTemplate({
	name: "docs.desk",
	compactSize: [18, 18],
	expandable: true,
	defaults: {expand: "hover", anchor: "top"},
	// Hovered, or its desk is: larger, ringed in its state's colour (ctx.hovered)
	hover: "template",
	status: (d) => STATES[d.state],
	label: (d) => d.desk + ", " + STATES[d.state].label.toLowerCase() + (d.person ? ", " + d.person : ""),
	css: `
		.desk { width: 18px; height: 18px; border-radius: 4px; background: var(--c); box-shadow: 0 0 0 2px #FFFFFF, 0 1px 3px rgba(27, 39, 51, .3);
			transition: transform 150ms ease-out, box-shadow 150ms ease-out; }
		.desk.hovered { transform: scale(1.2); box-shadow: 0 0 0 2px #FFFFFF, 0 0 0 3.5px var(--c), 0 3px 8px rgba(27, 39, 51, .35); }
		.card { width: 210px; padding: 8px 10px; background: var(--bwa-surface); border-radius: var(--bwa-radius); box-shadow: var(--bwa-shadow); }
		.card b { display: block; font-weight: 600; }
		.card span { font-size: 12px; color: var(--bwa-text-muted); }`,
	render: (d, ctx) => ctx.state == "compact"
		? html`<div class=${ctx.hovered ? "desk hovered" : "desk"} style=${"--c:" + STATES[d.state].color}></div>`
		: html`<div class="card"><b>${d.desk} · ${STATES[d.state].label}</b><span>${d.person ? d.person + " until " + d.untilHour + ":00" : "Free to book"}</span></div>`
});

const bookings = new Map(data.desks.rows.map((row) => [row.globalId, {...row.data}]));
const layer = objectStateManager.addAnnotationLayer({template: desk, key: "globalId", group: "desks",
	rows: [...bookings].map(([globalId, booking]) => ({globalId, data: booking}))});

const NEXT = {"free": "booked", "booked": "in-use", "in-use": "free"};
const timer = setInterval(() => {
	const globalIds = [...bookings.keys()];
	const globalId = globalIds[Math.floor(Math.random() * globalIds.length)];
	const booking = bookings.get(globalId);
	booking.state = NEXT[booking.state];
	booking.person = booking.state == "free" ? null : booking.person ?? "Lotte Mulder";
	booking.untilHour = booking.untilHour ?? 17;
	layer.update(globalId, {...booking});
}, 2000);
onReset(() => clearInterval(timer));

The 2. Obergeschoss on its own, each desk a square in its booking's colour; the desks of the storeys below are hidden with them.

Look: watch a desk change colour; its card changes with it.

Maintenance#

The technical rooms and the two lab benches as assets: the name and tag from the model, the schedule from a maintenance system, joined on the GlobalId.

// The technical rooms and the two lab benches as assets: the name and tag from the model, the schedule from a
// maintenance system, joined on the GlobalId. Overdue inspections come to the front
const day = 86400000;
const schedule = data.maintenance.rows;

const assets = objectStateManager.addAnnotationLayer({
	template: "asset",
	key: "globalId",
	group: "maintenance",
	query: {where: "attribute.GlobalId IN $assets", parameters: {assets: schedule.map((row) => row.globalId)}},
	rows: schedule.map((row) => ({globalId: row.globalId, data: {code: row.data.code, assetType: row.data.assetType,
		lastInspection: Date.now() - row.data.lastInspectionDaysAgo * day, nextDue: Date.now() + row.data.nextDueInDays * day}})),
	onAction: (action, row) => status("Here your maintenance system opens a work order for " + row.data.code)
});
// The technical rooms are spaces, hidden by default, and an annotation shows only while its object does; the benches
// are furniture, which shows with its storey
await assets.ready;
await objectStateManager.addToVisibleSet([...assets.rows()].filter((row) => row.type == "IFCSPACE").map((row) => row.qid));

The Keller on its own, asset chips on its technical rooms; the lab benches are in Labor I, one storey up.

Look: the overdue air handling unit has a red dot and comes first.

Progress per storey#

Fit-out progress per storey from a planning file: one ring per storey, on the bounds of its spaces together.

// Fit-out progress per storey from a planning file: one ring per storey, on the bounds of its spaces together
const day = 86400000;
const at = (days) => Date.now() + days * day;

const rows = [];
for (const plan of data.planning.rows) {
	const spaces = await client.bim.query([vid], 'GET qid WHERE type = IFCSPACE AND buildingStorey.attribute.Name = "' + plan.storey + '"');
	const {plannedStartInDays, plannedEndInDays, actualStartInDays, forecastEndInDays, ...rest} = plan.data;
	rows.push({key: plan.storey, qids: spaces.map((space) => space.qid), data: {...rest,
		plannedStart: at(plannedStartInDays), plannedEnd: at(plannedEndInDays), actualStart: at(actualStartInDays), forecastEnd: at(forecastEndInDays)}});
}

// Spaces are hidden by default, and a row about several objects shows only while one of them does
await objectStateManager.addToVisibleSet(rows.flatMap((row) => row.qids));
objectStateManager.addAnnotationLayer({template: "progress", group: "progress", occlusion: "none", rows});

The building from the south-west, a progress ring on each storey.

Look: hover the late storey for planned against forecast.

From BVL

Text and icons#

The annotations BVL had before templates: an icon on every lab of the Keller, and the long name of every room there while it is hovered.

// SHOW: spaces are hidden by default, and an annotation shows only while its object does
if (type = IFCSPACE AND property.Pset_SpaceCommon.Category = "Labor" AND buildingStorey.attribute.Name = "Keller") {
	SHOW annotate(svg("glyphicons-basic-625-chemistry.svg") occlusion dim cluster off "labs");
}
if (type = IFCSPACE AND buildingStorey.attribute.Name = "Keller") {
	SHOW annotate(text(attribute.LongName) hover "names");
}

The Keller on its own, a flask on every lab.

Look: hover a room for its name.

An accessibility check#

The model's HandicapAccessible as a check on the spaces of the 1. Obergeschoss: a pass where it is true, a warning where it is false, drawn by the checkResult template.

// SHOW: spaces are hidden by default, and an annotation shows only while its object does
if (type = IFCSPACE AND property.Pset_SpaceCommon.HandicapAccessible = true AND buildingStorey.attribute.Name = "1. Obergeschoss") {
	SHOW annotate(template("checkResult", "check" = "Accessibility", "rule" = "Handicap accessible", "outcome" = "pass") "access");
}
if (type = IFCSPACE AND property.Pset_SpaceCommon.HandicapAccessible = false AND buildingStorey.attribute.Name = "1. Obergeschoss") {
	SHOW annotate(template("checkResult", "check" = "Accessibility", "rule" = "Handicap accessible", "outcome" = "warn",
		"expected" = "true", "actual" = "false") occlusion dim "access");
}

The 1. Obergeschoss on its own, a pass or a warning on each space.

Look: hover a warning for what was expected against what was found.

Your own template, named in BVL#

The category chip of "A template of your own", registered by this page as docs.spaceCategory and named in BVL with its fields bound. A viewer that has not registered the template shows the fields as text.

// SHOW: spaces are hidden by default, and an annotation shows only while its object does
if (type = IFCSPACE AND buildingStorey.attribute.Name = "Keller") {
	SHOW annotate(template("docs.spaceCategory", "category" = property.Pset_SpaceCommon.Category, "area" = quantity.*.NetFloorArea) "categories");
}

The Keller on its own, a category chip on every space.

Look: the same chips as in the JavaScript example; here the server resolves the category and area.

Your own look

Another accent and font#

The same kinds of annotations in another accent, font and radius: the theme variables, set on an element around the viewer. Every template reads them.

// The same kinds of annotations in another accent, font and radius: the theme variables, set on an element around the
// viewer. Every template reads them, so one rule restyles them all
const root = viewer.container;
const theme = {"--bwa-accent": "#8E44AD", "--bwa-accent-strong": "#6C3483", "--bwa-font": "Georgia, 'Times New Roman', serif", "--bwa-radius": "10px"};
for (const [name, value] of Object.entries(theme)) {
	root.style.setProperty(name, value);
}
onReset(() => Object.keys(theme).forEach((name) => root.style.removeProperty(name)));

const keller = 'buildingStorey.attribute.Name = "Keller"';
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet("GET qid WHERE type = IFCSPACE AND " + keller);
objectStateManager.addAnnotationLayer({template: "objectLabel", group: "labels", query: {where: "type = IFCSPACE AND " + keller}});
objectStateManager.addAnnotationLayer({template: "conversation", key: "globalId", group: "threads",
	rows: data.conversations.rows.map((row) => ({globalId: row.globalId, data: {...row.data, count: row.data.comments.length,
		comments: row.data.comments.map((comment) => ({...comment, at: Date.now() - comment.minutesAgo * 60000}))}}))});

The Keller on its own, object labels and threads in purple and a serif font.

Look: hover a thread; its card has the new accent too.

Markup in data stays text#

Data from outside with markup in it: a name that tries to run script, a link that is not one, a type in bold. A template escapes every value.

// Data from outside with markup in it: a name that tries to run script, a link that is not one, a type in bold. A
// template escapes every value, so they show as the text they are
const [lab] = await client.bim.query([vid], 'GET qid WHERE type = IFCSPACE AND attribute.LongName = "Labor K1"');
// Spaces are hidden by default, and an annotation shows only while its object does
await objectStateManager.addToVisibleSet([lab.qid]);

objectStateManager.addAnnotationLayer({
	template: "objectLabel",
	group: "escaping",
	rows: [{qid: lab.qid, type: "IFCSPACE", data: {name: '<img src=x onerror="alert(1)">', longName: "javascript:alert(1)", objectType: "<b>bold?</b>"}}]
});

Labor K1 with an object label whose data is markup, shown as text.

Look: the label shows the markup as characters; nothing runs.

AC11 Institute, annotatedLive demo
Loads the AC11 Institute demo model in this page with the demo API token of your account: open BIM.works and sign in once in this browser.
32 examples