Prompt specification
Build or customize the Three.js 3D scene "Design a readable public map" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Design a readable public map
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/design-a-readable-public-map-x0476
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts tactile maps. Create a simplified civic-center layout with editable map symbols; users assign distinct tactile forms to services and test whether identical symbols consistently identify equivalent destinations. Low-poly.
Working Three.js Starter (design-a-readable-public-map-x0476):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tactile Civic Map Lab</title>
<style>
:root {
--ink: #1d2927;
--muted: #68736e;
--line: #dce1da;
--paper: #f7f8f3;
--panel: #fffef9;
--green: #245f51;
--green-light: #e4eee8;
--orange: #d96646;
--blue: #4779b9;
--purple: #8060a8;
--shadow: 0 14px 40px rgba(29, 48, 42, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #e8ebe4;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
select {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
select:focus-visible {
outline: 3px solid rgba(71, 121, 185, 0.35);
outline-offset: 2px;
}
.app {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: 72px minmax(0, 1fr);
}
header {
position: relative;
z-index: 50;
display: flex;
align-items: center;
gap: 28px;
padding: 0 22px;
background: rgba(255, 254, 249, 0.96);
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 250px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 2px solid var(--green);
border-radius: 50%;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--green);
}
.brand-mark::before {
width: 8px;
height: 8px;
border-radius: 50%;
left: 7px;
top: 7px;
}
.brand-mark::after {
width: 13px;
height: 13px;
right: 6px;
bottom: 6px;
transform: rotate(45deg);
border-radius: 2px;
}
.brand-name {
font-size: 14px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.brand-sub {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.project {
flex: 1;
min-width: 0;
}
.project h1 {
margin: 0;
font-size: 17px;
font-weight: 760;
letter-spacing: -0.015em;
}
.project p {
margin: 4px 0 0;
color: var(--muted);
font-size: 12px;
}
.header-meta {
display: flex;
align-items: center;
gap: 12px;
}
.meta-pill {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
white-space: nowrap;
}
.meta-pill::before {
content: "";
width: 7px;
height: 7px;
background: #4b9b74;
border-radius: 50%;
box-shadow: 0 0 0 3px #e6f1ea;
}
.header-button,
.tool-button,
.primary-button,
.secondary-button {
border: 0;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease;
}
.header-button:hover,
.tool-button:hover,
.primary-button:hover,
.secondary-button:hover {
transform: translateY(-1px);
}
.header-button {
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 9px;
background: white;
font-size: 12px;
font-weight: 750;
}
.mobile-toggle {
display: none;
}
main {
position: relative;
min-height: 0;
display: grid;
grid-template-columns: 285px minmax(0, 1fr) 326px;
}
.panel {
position: relative;
z-index: 20;
min-height: 0;
overflow-y: auto;
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #c8d0c8 transparent;
}
.left-panel {
border-right: 1px solid var(--line);
}
.right-panel {
border-left: 1px solid var(--line);
}
.panel-section {
padding: 21px 20px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: flex-start;
gap: 10px;
margin-bottom: 15px;
}
.step {
display: grid;
place-items: center;
flex: 0 0 auto;
width: 25px;
height: 25px;
border-radius: 7px;
background: var(--green);
color: white;
font-size: 11px;
font-weight: 850;
}
.section-heading h2 {
margin: 0;
font-size: 14px;
line-height: 1.25;
letter-spacing: -0.01em;
}
.section-heading p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.service-list {
display: grid;
gap: 7px;
}
.service-row {
width: 100%;
display: grid;
grid-template-columns: 31px 1fr auto;
align-items: center;
gap: 9px;
padding: 10px;
text-align: left;
border: 1px solid transparent;
border-radius: 10px;
background: #f5f6f1;
cursor: pointer;
transition: 140ms ease;
}
.service-row:hover {
border-color: #cbd4cb;
background: #f0f3ed;
}
.service-row.selected {
border-color: var(--green);
background: var(--green-light);
box-shadow: inset 3px 0 0 var(--green);
}
.service-icon {
display: grid;
place-items: center;
width: 30px;
height: 30px;
border: 1px solid rgba(29, 41, 39, 0.12);
border-radius: 8px;
background: white;
}
.service-name {
display: block;
font-size: 12px;
font-weight: 760;
line-height: 1.25;
}
.service-group {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.service-form {
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.glyph {
display: inline-block;
width: 13px;
height: 13px;
flex: 0 0 auto;
background: var(--c, var(--green));
}
.glyph.circle {
border-radius: 50%;
}
.glyph.square {
border-radius: 2px;
}
.glyph.triangle {
clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.glyph.diamond {
width: 11px;
height: 11px;
transform: rotate(45deg);
}
.glyph.bar {
width: 19px;
height: 7px;
border-radius: 2px;
}
.glyph.hex {
clip-path: polygon(
25% 5%,
75% 5%,
100% 50%,
75% 95%,
25% 95%,
0 50%
);
}
.selection-card {
padding: 13px;
border: 1px solid #d8dfd7;
border-radius: 11px;
background: #f7f9f4;
}
.selection-kicker {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.selection-title {
margin-top: 4px;
font-size: 14px;
font-weight: 800;
}
.selection-value {
display: flex;
align-items: center;
gap: 8px;
margin-top: 9px;
color: var(--muted);
font-size: 11px;
}
.selection-value .glyph {
width: 17px;
height: 17px;
}
.palette {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.form-button {
min-height: 70px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
padding: 8px 4px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
cursor: pointer;
transition: 140ms ease;
}
.form-button:hover {
border-color: #9daf9f;
background: #f5f8f3;
transform: translateY(-1px);
}
.form-button.active {
border-color: var(--green);
background: var(--green-light);
box-shadow: inset 0 0 0 1px var(--green);
}
.form-button .glyph {
width: 24px;
height: 24px;
background: var(--green);
}
.form-button .glyph.bar {
width: 31px;
height: 11px;
}
.form-button .glyph.diamond {
width: 20px;
height: 20px;
}
.form-label {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.text-button {
width: 100%;
padding: 9px 0 0;
border: 0;
background: none;
color: var(--green);
cursor: pointer;
font-size: 11px;
font-weight: 800;
text-align: left;
}
.text-button:hover {
text-decoration: underline;
}
.micro-note {
margin: 12px 0 0;
padding-left: 12px;
border-left: 2px solid #d3dbd2;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.audit-banner {
display: flex;
align-items: center;
gap: 10px;
padding: 12px;
border: 1px solid #e6c58f;
border-radius: 10px;
background: #fff7e7;
}
.audit-banner.good {
border-color: #b8d7c2;
background: #edf7ef;
}
.audit-icon {
display: grid;
place-items: center;
width: 28px;
height: 28px;
border-radius: 50%;
background: #e6ad53;
color: white;
font-size: 14px;
font-weight: 900;
}
.audit-banner.good .audit-icon {
background: #4b976a;
}
.audit-title {
font-size: 12px;
font-weight: 850;
}
.audit-subtitle {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.audit-rows {
display: grid;
gap: 7px;
margin-top: 12px;
}
.audit-row {
display: grid;
grid-template-columns: 22px 1fr;
gap: 8px;
padding: 9px 0;
border-bottom: 1px solid #edf0ea;
}
.audit-row:last-child {
border-bottom: 0;
}
.audit-state {
width: 20px;
height: 20px;
display: grid;
place-items: center;
border-radius: 50%;
background: #e4f0e6;
color: #387b50;
font-size: 11px;
font-weight: 900;
}
.audit-row.fail .audit-state {
background: #fae5de;
color: #bb5639;
}
.audit-group {
font-size: 11px;
font-weight: 800;
}
.audit-detail {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.primary-button {
width: 100%;
padding: 11px 13px;
border-radius: 9px;
background: var(--green);
color: white;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.02em;
}
.secondary-button {
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: white;
font-size: 11px;
font-weight: 800;
}
.route-select {
width: 100%;
margin: 2px 0 10px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: white;
color: var(--ink);
font-size: 12px;
font-weight: 700;
}
.route-score {
display: flex;
justify-content: space-between;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.route-feedback {
min-height: 42px;
margin-top: 10px;
padding: 10px;
border-radius: 8px;
background: #f2f4ef;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.route-feedback.correct {
background: #e6f4e9;
color: #2f7448;
}
.route-feedback.wrong {
background: #fbe9e2;
color: #a84c34;
}
#nextTarget {
width: 100%;
margin-top: 8px;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e7eae2;
}
#sceneHost {
position: absolute;
inset: 0;
}
#sceneHost canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.map-heading {
position: absolute;
z-index: 8;
top: 18px;
left: 18px;
max-width: 310px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
background: rgba(255, 254, 249, 0.86);
backdrop-filter: blur(12px);
box-shadow: 0 8px 28px rgba(31, 51, 44, 0.1);
pointer-events: none;
}
.eyebrow {
color: var(--green);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.map-heading h2 {
margin: 5px 0 0;
font-size: 18px;
letter-spacing: -0.025em;
}
.map-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.view-tools {
position: absolute;
z-index: 9;
top: 18px;
right: 18px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 11px;
background: rgba(255, 254, 249, 0.88);
backdrop-filter: blur(12px);
box-shadow: 0 8px 28px rgba(31, 51, 44, 0.1);
}
.tool-button {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: var(--ink);
font-size: 17px;
font-weight: 800;
}
.tool-button:hover,
.tool-button.active {
border-color: #d3dcd2;
background: #edf2eb;
}
.map-legend {
position: absolute;
z-index: 8;
left: 18px;
bottom: 18px;
width: 215px;
padding: 12px 13px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 11px;
background: rgba(255, 254, 249, 0.88);
backdrop-filter: blur(12px);
box-shadow: 0 8px 28px rgba(31, 51, 44, 0.09);
pointer-events: none;
}
.legend-title {
margin-bottom: 8px;
font-size: 10px;
font-weight: 850;
}
.legend-items {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--c);
}
.interaction-tip {
position: absolute;
z-index: 8;
right: 18px;
bottom: 18px;
max-width: 250px;
padding: 9px 11px;
border-radius: 9px;
background: rgba(29, 41, 39, 0.82);
color: white;
font-size: 9px;
line-height: 1.45;
text-align: right;
pointer-events: none;
}
.marker-tooltip {
position: absolute;
z-index: 12;
display: none;
min-width: 135px;
padding: 8px 10px;
border-radius: 8px;
background: rgba(29, 41, 39, 0.92);
color: white;
box-shadow: var(--shadow);
font-size: 10px;
line-height: 1.45;
pointer-events: none;
transform: translate(12px, 12px);
}
.marker-tooltip strong {
display: block;
font-size: 11px;
}
.toast {
position: absolute;
z-index: 30;
left: 50%;
bottom: 22px;
padding: 10px 14px;
border-radius: 9px;
background: rgba(29, 41, 39, 0.92);
color: white;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.close-mobile {
display: none;
}
@media (max-width: 1120px) {
main {
grid-template-columns: 250px minmax(0, 1fr) 292px;
}
.panel-section {
padding: 18px 16px;
}
.project p {
display: none;
}
.meta-pill {
display: none;
}
}
@media (max-width: 820px) {
header {
gap: 10px;
padding: 0 12px;
}
.brand {
min-width: auto;
}
.brand-copy {
display: none;
}
.project h1 {
font-size: 14px;
}
.mobile-toggle {
display: block;
}
.header-button:not(.mobile-toggle) {
display: none;
}
main {
display: block;
}
.stage {
width: 100%;
height: 100%;
}
.panel {
position: absolute;
z-index: 40;
top: 12px;
bottom: 12px;
width: min(320px, calc(100% - 24px));
border: 1px solid var(--line);
border-radius: 13px;
box-shadow: var(--shadow);
display: none;
}
body.show-left .left-panel,
body.show-right .right-panel {
display: block;
}
.close-mobile {
position: absolute;
top: 9px;
right: 9px;
z-index: 2;
display: grid;
place-items: center;
width: 29px;
height: 29px;
border: 1px solid var(--line);
border-radius: 8px;
background: white;
cursor: pointer;
}
.map-heading {
max-width: 240px;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<div class="brand-name">Tactile Atlas</div>
<div class="brand-sub">Wayfinding research lab</div>
</div>
</div>
<div class="project">
<h1>Civic Center / Tactile Map</h1>
<p>Assign raised forms and test whether equivalent destinations remain distinguishable.</p>
</div>
<div class="header-meta">
<span class="meta-pill">8 destinations · 4 groups</span>
<button class="header-button mobile-toggle" id="toggleLeft">Services</button>
<button class="header-button mobile-toggle" id="toggleRight">Tests</button>
<button class="header-button" id="resetAll">Reset study</button>
</div>
</header>
<main>
<aside class="panel left-panel">
<button class="close-mobile" id="closeLeft" aria-label="Close services">×</button>
<section class="panel-section">
<div class="section-heading">
<div class="step">1</div>
<div>
<h2>Assign a raised form</h2>
<p>Select a destination, then choose its tactile symbol.</p>
</div>
</div>
<div class="service-list" id="serviceList"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<div class="step">A</div>
<div>
<h2>Form library</h2>
<p>Shape is the accessible signal; color is supplementary.</p>
</div>
</div>
<div class="palette" id="palette"></div>
<div class="selection-card" style="margin-top: 12px">
<div class="selection-kicker">Editing</div>
<div class="selection-title" id="selectedName">Main Library</div>
<div class="selection-value">
<i class="glyph circle" id="selectedGlyph"></i>
<span id="selectedValue">Circle</span>
</div>
</div>
<button class="text-button" id="suggestForms">Apply suggested group forms →</button>
<p class="micro-note">
Drag any raised symbol directly on the map to adjust its exact position.
</p>
</section>
</aside>
<section class="stage" id="stage">
<div id="sceneHost"></div>
<div class="map-heading">
<div class="eyebrow">Interactive civic model</div>
<h2>North Commons</h2>
<p>Low-poly map study · raised symbols identify service types</p>
</div>
<div class="view-tools">
<button class="tool-button" id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button class="tool-button" id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button class="tool-button" id="topView" title="Plan view" aria-label="Plan view">▦</button>
<button class="tool-button" id="resetView" title="Reset view" aria-label="Reset view">↺</button>
</div>
<div class="map-legend">
<div class="legend-title">Destination groups</div>
<div class="legend-items" id="legendItems"></div>
</div>
<div class="interaction-tip">
Drag background to orbit · Shift-drag to pan<br />
Scroll to zoom · Drag symbols to reposition
</div>
<div class="marker-tooltip" id="markerTooltip"></div>
<div class="toast" id="toast"></div>
</section>
<aside class="panel right-panel">
<button class="close-mobile" id="closeRight" aria-label="Close tests">×</button>
<section class="panel-section">
<div class="section-heading">
<div class="step">2</div>
<div>
<h2>Consistency audit</h2>
<p>Identical symbols should identify equivalent destinations.</p>
</div>
</div>
<div class="audit-banner" id="auditBanner">
<div class="audit-icon" id="auditIcon">!</div>
<div>
<div class="audit-title" id="auditTitle">Checking system</div>
<div class="audit-subtitle" id="auditSubtitle"></div>
</div>
</div>
<div class="audit-rows" id="auditRows"></div>
<button class="primary-button" id="runAudit" style="margin-top: 12px">
Run consistency check
</button>
</section>
<section class="panel-section">
<div class="section-heading">
<div class="step">B</div>
<div>
<h2>Route drill</h2>
<p>Find the raised symbol for a named destination.</p>
</div>
</div>
<label class="selection-kicker" for="routeSelect">Destination prompt</label>
<select class="route-select" id="routeSelect"></select>
<button class="primary-button" id="startRoute">Start route test</button>
<button class="secondary-button" id="nextTarget" style="display: none">
Next destination
</button>
<div class="route-score">
<span>Route score</span>
<span id="routeScore">0 / 0</span>
</div>
<div class="route-feedback" id="routeFeedback">
Start a test, then click the matching symbol on the map.
</div>
</section>
<section class="panel-section">
<div class="selection-kicker">Test logic</div>
<p class="micro-note" style="margin-top: 9px">
Equivalent destinations should share one form. Different destination
groups should never reuse the same form. The live audit checks both rules.
</p>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const FORM_NAMES = {
circle: "Circle",
square: "Square",
triangle: "Triangle",
diamond: "Diamond",
bar: "Raised bar",
hex: "Hexagon"
};
const GROUPS = {
library: { label: "Library", color: "#d86648" },
health: { label: "Health", color: "#2f9d91" },
postal: { label: "Postal", color: "#4e78c4" },
transit: { label: "Transit", color: "#8060a8" }
};
const SUGGESTED = {
library: "circle",
health: "square",
postal: "triangle",
transit: "diamond"
};
const initialServices = [
{
id: "library",
name: "Main Library",
group: "library",
form: "circle",
position: [-5.8, -2.25]
},
{
id: "annex",
name: "Library Annex",
group: "library",
form: "circle",
position: [-2.65, -2.35]
},
{
id: "clinic",
name: "Health Clinic",
group: "health",
form: "square",
position: [-5.75, 2.3]
},
{
id: "first-aid",
name: "First Aid",
group: "health",
form: "square",
position: [-2.75, 2.75]
},
{
id: "post",
name: "Post Office",
group: "postal",
form: "triangle",
position: [5.05, -2.3]
},
{
id: "mail",
name: "Mail Kiosk",
group: "postal",
// Intentionally inconsistent so the audit has something to demonstrate.
form: "square",
position: [3.05, 1.95]
},
{
id: "transit",
name: "Transit Hub",
group: "transit",
form: "diamond",
position: [5.8, 2.25]
},
{
id: "bus",
name: "Bus Stop",
group: "transit",
form: "diamond",
position: [1.95, 2.2]
}
];
let services = initialServices.map((service) => ({
...service,
position: [...service.position]
}));
let selectedId = services[0].id;
// ------------------------------------------------------------
// Interface
// ------------------------------------------------------------
function glyphMarkup(form, color = GROUPS.library.color) {
return `<i class="glyph ${form}" style="--c:${color}"></i>`;
}
function renderServices() {
$("#serviceList").innerHTML = services.map((service) => {
const group = GROUPS[service.group];
return `
<button
class="service-row ${service.id === selectedId ? "selected" : ""}"
data-service="${service.id}"
>
<span class="service-icon">
${glyphMarkup(service.form, group.color)}
</span>
<span>
<span class="service-name">${service.name}</span>
<span class="service-group">${group.label} group</span>
</span>
<span class="service-form">${FORM_NAMES[service.form]}</span>
</button>
`;
}).join("");
document.querySelectorAll("[data-service]").forEach((button) => {
button.addEventListener("click", () => {
selectService(button.dataset.service);
document.body.classList.remove("show-left");
});
});
}
function renderPalette() {
const service = services.find((item) => item.id === selectedId);
$("#palette").innerHTML = Object.entries(FORM_NAMES).map(([form, name]) => {
return `
<button
class="form-button ${service.form === form ? "active" : ""}"
data-form="${form}"
title="Assign ${name}"
>
${glyphMarkup(form)}
<span class="form-label">${name}</span>
</button>
`;
}).join("");
document.querySelectorAll("[data-form]").forEach((button) => {
button.addEventListener("click", () => {
assignForm(button.dataset.form);
});
});
}
function renderSelection() {
const service = services.find((item) => item.id === selectedId);
const group = GROUPS[service.group];
$("#selectedName").textContent = service.name;
$("#selectedValue").textContent = `${FORM_NAMES[service.form]} · ${group.label}`;
const glyph = $("#selectedGlyph");
glyph.className = `glyph ${service.form}`;
glyph.style.setProperty("--c", group.color);
}
function renderLegend() {
$("#legendItems").innerHTML = Object.values(GROUPS).map((group) => {
return `
<div class="legend-item">
<span class="legend-dot" style="--c:${group.color}"></span>
<span>${group.label}</span>
</div>
`;
}).join("");
}
function renderRouteSelect() {
$("#routeSelect").innerHTML = services.map((service) => {
return `<option value="${service.id}">${service.name}</option>`;
}).join("");
}
function selectService(id) {
selectedId = id;
renderServices();
renderPalette();
renderSelection();
for (const [serviceId, marker] of markerMap) {
marker.userData.ring.visible = serviceId === selectedId;
}
}
function assignForm(form) {
const service = services.find((item) => item.id === selectedId);
service.form = form;
updateMarkerSymbol(service);
renderServices();
renderPalette();
renderSelection();
runAudit(false);
showToast(`${service.name} now uses ${FORM_NAMES[form].toLowerCase()}.`);
}
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const host = $("#sceneHost");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e7eae2");
scene.fog = new THREE.Fog("#e7eae2", 35, 65);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
host.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#fff9e8", "#70807a", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff3d5", 3.15);
sun.position.set(-8, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9d7e1", 0.75);
fill.position.set(10, 8, -12);
scene.add(fill);
const cameraState = {
theta: 0.64,
phi: 0.76,
radius: 25,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const material = (color, extra = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...extra
});
const palette = {
ground: material("#d9d4c4"),
surface: material("#e9e4d7"),
sidewalk: material("#f4efe2"),
road: material("#697271"),
roadMark: material("#e9dfb9"),
grass: material("#aebd91"),
grassDark: material("#819c72"),
trunk: material("#8c6a4c"),
window: material("#547d83"),
door: material("#476b68"),
cream: material("#fff8e7")
};
function addBox(parent, width, height, depth, x, y, z, mat, cast = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addGroundPlane() {
const shadowGround = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
material("#e1e5dc")
);
shadowGround.rotation.x = -Math.PI / 2;
shadowGround.position.y = -0.66;
shadowGround.receiveShadow = true;
scene.add(shadowGround);
addBox(scene, 20, 0.56, 13.6, 0, -0.38, 0, palette.ground, true);
addBox(scene, 19.6, 0.18, 13.15, 0, -0.05, 0, palette.surface);
// Wide sidewalk beds, followed by inset asphalt.
addBox(scene, 4.4, 0.055, 12.85, 0, 0.025, 0, palette.sidewalk);
addBox(scene, 19.25, 0.055, 4.35, 0, 0.027, 0, palette.sidewalk);
addBox(scene, 3.6, 0.065, 12.75, 0, 0.064, 0, palette.road);
addBox(scene, 19.2, 0.067, 3.45, 0, 0.066, 0, palette.road);
// Road dashes.
for (const z of [-5.4, -3.6, 3.6, 5.4]) {
addBox(scene, 0.11, 0.022, 0.68, 0, 0.106, z, palette.roadMark);
}
for (const x of [-7.8, -5.8, -3.8, 3.8, 5.8, 7.8]) {
addBox(scene, 0.72, 0.022, 0.11, x, 0.108, 0, palette.roadMark);
}
// Crosswalks.
for (let i = -3; i <= 3; i++) {
addBox(scene, 0.23, 0.025, 1.05, i * 0.46, 0.114, 1.42, palette.roadMark);
addBox(scene, 0.23, 0.025, 1.05, i * 0.46, 0.115, -1.42, palette.roadMark);
}
// Park and plaza patches.
addBox(scene, 2.15, 0.035, 2.3, -8.15, 0.03, 0.05, palette.grass);
addBox(scene, 2.2, 0.035, 2.0, 8.05, 0.03, -0.05, palette.grass);
addBox(scene, 1.9, 0.035, 2.7, -8.25, 0.032, 3.5, palette.grassDark);
addBox(scene, 1.8, 0.035, 2.3, 8.2, 0.032, 4.2, palette.grass);
}
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.arcTo(x + width, y, x + width, y + height, radius);
context.arcTo(x + width, y + height, x, y + height, radius);
context.arcTo(x, y + height, x, y, radius);
context.arcTo(x, y, x + width, y, radius);
context.closePath();
}
function addTextSprite(text, options = {}) {
const {
color = "#25322e",
background = "rgba(255,254,247,0.92)",
width = 512,
height = 128,
fontSize = 42
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
context.fillStyle = background;
roundedRect(context, 6, 12, width - 12, height - 24, 22);
context.fill();
context.fillStyle = color;
context.font = `800 ${fontSize}px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.renderOrder = 10;
return sprite;
}
function addBuilding({
x,
z,
width,
depth,
height,
color,
roof = "#c5bca7",
label,
labelWidth = 2.8
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const bodyMat = material(color);
const roofMat = material(roof);
addBox(group, width, height, depth, 0, height / 2 + 0.1, 0, bodyMat, true);
addBox(
group,
width + 0.2,
0.18,
depth + 0.2,
0,
height + 0.12,
0,
roofMat,
true
);
// Front windows and a centered door.
const frontZ = depth / 2 + 0.012;
const windowCount = Math.max(2, Math.floor(width / 0.85));
for (let i = 0; i < windowCount; i++) {
const xOffset = (i - (windowCount - 1) / 2) * 0.78;
if (Math.abs(xOffset) < 0.45) continue;
addBox(
group,
0.42,
0.46,
0.04,
xOffset,
height * 0.57,
frontZ,
palette.window
);
}
addBox(group, 0.58, 0.78, 0.055, 0, 0.49, frontZ + 0.015, palette.door);
// A shallow entrance step.
addBox(
group,
0.9,
0.1,
0.48,
0,
0.11,
depth / 2 + 0.19,
palette.sidewalk
);
if (label) {
const sprite = addTextSprite(label.toUpperCase());
sprite.position.set(0, height + 0.72, 0);
sprite.scale.set(labelWidth, labelWidth * 0.25, 1);
group.add(sprite);
}
return group;
}
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.15, 0.72, 6),
palette.trunk
);
trunk.position.y = 0.36;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.35, 6),
palette.grassDark
);
crown.position.y = 1.18;
crown.castShadow = true;
group.add(crown);
const top = new THREE.Mesh(
new THREE.ConeGeometry(0.33, 0.92, 6),
palette.grass
);
top.position.y = 1.8;
top.castShadow = true;
group.add(top);
}
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
const wood = material("#a47851");
addBox(group, 1.25, 0.11, 0.34, 0, 0.48, 0, wood, true);
addBox(group, 1.25, 0.32, 0.09, 0, 0.73, -0.16, wood, true);
addBox(group, 0.08, 0.45, 0.27, -0.48, 0.25, 0, palette.trunk);
addBox(group, 0.08, 0.45, 0.27, 0.48, 0.25, 0, palette.trunk);
}
function addShelter(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const frame = material("#4d6665");
const glass = material("#9fc4c4", { transparent: true, opacity: 0.65 });
addBox(group, 1.55, 0.11, 1.05, 0, 1.3, 0, frame, true);
addBox(group, 0.09, 1.25, 0.09, -0.67, 0.65, -0.4, frame, true);
addBox(group, 0.09, 1.25, 0.09, 0.67, 0.65, -0.4, frame, true);
addBox(group, 1.28, 0.95, 0.035, 0, 0.67, -0.39, glass);
addBox(group, 1.12, 0.12, 0.31, 0, 0.47, 0.05, material("#bd8a5f"), true);
}
function addCompass() {
const group = new THREE.Group();
group.position.set(8.7, 0.08, -5.55);
scene.add(group);
const ring = new THREE.Mesh(
new THREE.CylinderGeometry(0.56, 0.56, 0.08, 12),
palette.cream
);
ring.receiveShadow = true;
group.add(ring);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.22, 0.72, 3),
material("#d35e43")
);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(0, 0.25, -0.2);
arrow.castShadow = true;
group.add(arrow);
const north = addTextSprite("N", {
width: 128,
height: 128,
fontSize: 72,
background: "rgba(255,254,247,0)"
});
north.position.set(0, 0.12, 0.78);
north.scale.set(0.62, 0.62, 1);
group.add(north);
}
function buildScene() {
addGroundPlane();
addBuilding({
x: -5.8,
z: -4.1,
width: 3.4,
depth: 2.25,
height: 1.65,
color: "#d88d72",
roof: "#b76754",
label: "Main Library",
labelWidth: 3.2
});
addBuilding({
x: -2.65,
z: -4.2,
width: 2.3,
depth: 2.05,
height: 1.95,
color: "#d8b274",
roof: "#b8955f",
label: "Library Annex",
labelWidth: 2.75
});
addBuilding({
x: 5.05,
z: -4.1,
width: 3.0,
depth: 2.2,
height: 1.55,
color: "#7e9eb0",
roof: "#607e8c",
label: "Post Office",
labelWidth: 3.0
});
addBuilding({
x: -5.75,
z: 4.15,
width: 3.1,
depth: 2.2,
height: 1.7,
color: "#76aaa0",
roof: "#56897f",
label: "Health Clinic",
labelWidth: 3.0
});
addBuilding({
x: -2.75,
z: 4.15,
width: 1.75,
depth: 1.25,
height: 0.95,
color: "#e0b976",
roof: "#c29b58",
label: "First Aid",
labelWidth: 2.15
});
addBuilding({
x: 5.75,
z: 4.05,
width: 2.8,
depth: 2.35,
height: 1.85,
color: "#9a8ab1",
roof: "#78668f",
label: "Transit Hub",
labelWidth: 2.9
});
addBuilding({
x: 3.2,
z: 2.65,
width: 1.05,
depth: 0.78,
height: 0.68,
color: "#7e9fc0",
roof: "#567696",
label: "Mail Kiosk",
labelWidth: 2.1
});
addShelter(2.35, 3.55);
const treePositions = [
[-8.4, -4.5, 0.9],
[-8.4, -1.7, 0.78],
[-3.8, 5.7, 0.85],
[-8.3, 4.5, 0.92],
[8.2, -3.1, 0.82],
[8.3, 2.0, 0.78],
[7.8, 5.5, 0.88],
[0.75, 5.7, 0.72],
[0.8, -5.7, 0.75],
[-0.8, 2.55, 0.58],
[0.85, -2.55, 0.58]
];
treePositions.forEach(([x, z, scale]) => addTree(x, z, scale));
addBench(-3.7, -0.95, 0);
addBench(3.75, -0.95, 0);
addBench(-0.55, 4.9, Math.PI / 2);
addCompass();
}
buildScene();
// ------------------------------------------------------------
// Tactile markers
// ------------------------------------------------------------
const markerMap = new Map();
const markerGroups = [];
function makeFormMesh(form, color) {
const mat = material(color, { roughness: 0.72 });
let mesh;
if (form === "circle") {
mesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.37, 0.37, 0.24, 12),
mat
);
} else if (form === "square") {
mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.64, 0.23, 0.64),
mat
);
} else if (form === "triangle") {
mesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.46, 0.24, 3),
mat
);
mesh.rotation.y = Math.PI / 6;
} else if (form === "diamond") {
mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.56, 0.23, 0.56),
mat
);
mesh.rotation.y = Math.PI / 4;
} else if (form === "bar") {
mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.92, 0.22, 0.3),
mat
);
} else {
mesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.43, 0.23, 6),
mat
);
}
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.position.y = 0.31;
return mesh;
}
function createMarker(service) {
const group = new THREE.Group();
group.position.set(service.position[0], 0, service.position[1]);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.53, 0.58, 0.18, 12),
material("#fff7e8")
);
base.position.y = 0.1;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const symbol = makeFormMesh(service.form, GROUPS[service.group].color);
group.add(symbol);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.61, 0.035, 6, 28),
new THREE.MeshBasicMaterial({
color: "#173e34",
transparent: true,
opacity: 0.9,
depthTest: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.205;
ring.renderOrder = 8;
ring.visible = service.id === selectedId;
group.add(ring);
group.traverse((object) => {
object.userData.serviceId = service.id;
});
group.userData.serviceId = service.id;
group.userData.symbol = symbol;
group.userData.ring = ring;
markerMap.set(service.id, group);
markerGroups.push(group);
scene.add(group);
return group;
}
function updateMarkerSymbol(service) {
const marker = markerMap.get(service.id);
if (!marker) return;
const oldSymbol = marker.userData.symbol;
if (oldSymbol) {
marker.remove(oldSymbol);
oldSymbol.geometry.dispose();
oldSymbol.material.dispose();
}
const symbol = makeFormMesh(service.form, GROUPS[service.group].color);
marker.add(symbol);
marker.userData.symbol = symbol;
marker.traverse((object) => {
object.userData.serviceId = service.id;
});
}
services.forEach(createMarker);
// ------------------------------------------------------------
// Custom camera and pointer controls
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const dragPoint = new THREE.Vector3();
let cameraDrag = null;
let symbolDrag = null;
let hoverFrame = null;
function setPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function findServiceId(object) {
let current = object;
while (current) {
if (current.userData.serviceId) return current.userData.serviceId;
current = current.parent;
}
return null;
}
function pickMarker(event) {
setPointer(event);
const hits = raycaster.intersectObjects(markerGroups, true);
return hits.length ? hits[0] : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
const hit = pickMarker(event);
if (hit) {
const id = findServiceId(hit.object);
selectService(id);
if (routeTest.active) {
handleRouteClick(id);
return;
}
symbolDrag = {
id,
startX: event.clientX,
startY: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
return;
}
const mode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
cameraDrag = {
mode,
lastX: event.clientX,
lastY: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (symbolDrag) {
setPointer(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
const x = THREE.MathUtils.clamp(dragPoint.x, -9.3, 9.3);
const z = THREE.MathUtils.clamp(dragPoint.z, -6.15, 6.15);
const marker = markerMap.get(symbolDrag.id);
marker.position.x = x;
marker.position.z = z;
const service = services.find((item) => item.id === symbolDrag.id);
service.position[0] = x;
service.position[1] = z;
if (
Math.abs(event.clientX - symbolDrag.startX) +
Math.abs(event.clientY - symbolDrag.startY) > 4
) {
symbolDrag.moved = true;
}
}
return;
}
if (cameraDrag) {
const dx = event.clientX - cameraDrag.lastX;
const dy = event.clientY - cameraDrag.lastY;
cameraDrag.lastX = event.clientX;
cameraDrag.lastY = event.clientY;
if (cameraDrag.mode === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.08,
1.18
);
} else {
const panScale = cameraState.radius * 0.00145;
cameraState.target.x -= dx * panScale;
cameraState.target.z += dy * panScale;
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -7, 7);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -5, 5);
}
return;
}
const hit = pickMarker(event);
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
if (hit) {
const id = findServiceId(hit.object);
const service = services.find((item) => item.id === id);
const group = GROUPS[service.group];
const tooltip = $("#markerTooltip");
tooltip.innerHTML = `
<strong>${service.name}</strong>
${FORM_NAMES[service.form]} form · ${group.label}
`;
tooltip.style.display = "block";
const rect = host.getBoundingClientRect();
tooltip.style.left = `${event.clientX - rect.left}px`;
tooltip.style.top = `${event.clientY - rect.top}px`;
} else {
$("#markerTooltip").style.display = "none";
}
});
function endPointer(event) {
if (symbolDrag) {
if (symbolDrag.moved) {
const service = services.find((item) => item.id === symbolDrag.id);
showToast(`${service.name} marker repositioned.`);
}
symbolDrag = null;
}
cameraDrag = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("pointerleave", () => {
if (!cameraDrag && !symbolDrag) {
$("#markerTooltip").style.display = "none";
}
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.018,
12,
39
);
}, { passive: false });
function resetCamera() {
cameraState.theta = 0.64;
cameraState.phi = 0.76;
cameraState.radius = 25;
cameraState.target.set(0, 0, 0);
$("#topView").classList.remove("active");
}
$("#zoomIn").addEventListener("click", () => {
cameraState.radius = Math.max(12, cameraState.radius - 2);
});
$("#zoomOut").addEventListener("click", () => {
cameraState.radius = Math.min(39, cameraState.radius + 2);
});
$("#resetView").addEventListener("click", resetCamera);
$("#topView").addEventListener("click", () => {
const isActive = $("#topView").classList.toggle("active");
if (isActive) {
cameraState.theta = 0;
cameraState.phi = 0.08;
cameraState.radius = 27;
cameraState.target.set(0, 0, 0);
} else {
cameraState.theta = 0.64;
cameraState.phi = 0.76;
}
});
// ------------------------------------------------------------
// Consistency audit
// ------------------------------------------------------------
function runAudit(announce = true) {
const groupForms = {};
const formOwners = {};
for (const groupId of Object.keys(GROUPS)) {
const members = services.filter((service) => service.group === groupId);
const forms = [...new Set(members.map((service) => service.form))];
groupForms[groupId] = { members, forms };
for (const form of forms) {
formOwners[form] ||= [];
formOwners[form].push(groupId);
}
}
const issues = [];
for (const [groupId, info] of Object.entries(groupForms)) {
if (info.forms.length > 1) {
issues.push({
type: "split",
groupId,
message: `${GROUPS[groupId].label} destinations use ${info.forms.length} different forms.`
});
}
}
for (const [form, owners] of Object.entries(formOwners)) {
if (owners.length > 1) {
issues.push({
type: "reuse",
form,
message: `${FORM_NAMES[form]} is used for ${owners.map((id) => GROUPS[id].label).join(" and ")}.`
});
}
}
const banner = $("#auditBanner");
const icon = $("#auditIcon");
const title = $("#auditTitle");
const subtitle = $("#auditSubtitle");
banner.classList.toggle("good", issues.length === 0);
if (issues.length === 0) {
icon.textContent = "✓";
title.textContent = "System is consistent";
subtitle.textContent = "Equivalent destinations share forms; different groups remain distinct.";
} else {
icon.textContent = "!";
title.textContent = `${issues.length} consistency ${issues.length === 1 ? "issue" : "issues"} found`;
subtitle.textContent = "Adjust the highlighted assignments before testing routes.";
}
$("#auditRows").innerHTML = Object.entries(groupForms).map(([groupId, info]) => {
const crossConflict = info.forms.some((form) => formOwners[form].length > 1);
const split = info.forms.length > 1;
const ok = !split && !crossConflict;
let detail;
if (split) {
detail = `Split forms: ${info.forms.map((form) => FORM_NAMES[form]).join(" + ")}.`;
} else if (crossConflict) {
const otherGroups = formOwners[info.forms[0]]
.filter((id) => id !== groupId)
.map((id) => GROUPS[id].label);
detail = `${FORM_NAMES[info.forms[0]]} is also used for ${otherGroups.join(" and ")}.`;
} else {
detail = `${info.members.length} destinations share the ${FORM_NAMES[info.forms[0]].toLowerCase()} form.`;
}
return `
<div class="audit-row ${ok ? "" : "fail"}">
<div class="audit-state">${ok ? "✓" : "×"}</div>
<div>
<div class="audit-group">${GROUPS[groupId].label}</div>
<div class="audit-detail">${detail}</div>
</div>
</div>
`;
}).join("");
if (announce) {
showToast(
issues.length === 0
? "Audit passed: every destination group is distinct and internally consistent."
: `Audit complete: ${issues.length} ${issues.length === 1 ? "issue" : "issues"} found.`
);
}
}
$("#runAudit").addEventListener("click", () => runAudit(true));
$("#suggestForms").addEventListener("click", () => {
for (const service of services) {
service.form = SUGGESTED[service.group];
updateMarkerSymbol(service);
}
renderServices();
renderPalette();
renderSelection();
runAudit(false);
showToast("Suggested forms applied: four distinct destination groups.");
});
// ------------------------------------------------------------
// Route drill
// ------------------------------------------------------------
const routeTest = {
active: false,
answered: false,
targetId: null,
score: 0,
attempts: 0
};
function startRoute() {
routeTest.active = true;
routeTest.answered = false;
routeTest.targetId = $("#routeSelect").value;
routeTest.score = 0;
routeTest.attempts = 0;
const target = services.find((service) => service.id === routeTest.targetId);
$("#routeFeedback").className = "route-feedback";
$("#routeFeedback").textContent = `Find ${target.name}. Click its raised symbol on the map.`;
$("#routeScore").textContent = "0 / 0";
$("#nextTarget").style.display = "none";
$("#startRoute").textContent = "Restart route test";
showToast(`Route test started: find ${target.name}.`);
}
function handleRouteClick(id) {
if (!routeTest.active || routeTest.answered) return;
const target = services.find((service) => service.id === routeTest.targetId);
const clicked = services.find((service) => service.id === id);
const feedback = $("#routeFeedback");
routeTest.attempts += 1;
if (id === routeTest.targetId) {
routeTest.score += 1;
routeTest.answered = true;
feedback.className = "route-feedback correct";
feedback.textContent = `Correct. ${target.name} uses the ${FORM_NAMES[target.form].toLowerCase()} form.`;
$("#routeScore").textContent = `${routeTest.score} / ${routeTest.attempts}`;
$("#nextTarget").style.display = "block";
} else {
feedback.className = "route-feedback wrong";
feedback.textContent = `Not quite. ${clicked.name} belongs to the ${GROUPS[clicked.group].label} group. Try again.`;
$("#routeScore").textContent = `${routeTest.score} / ${routeTest.attempts}`;
}
}
$("#startRoute").addEventListener("click", startRoute);
$("#nextTarget").addEventListener("click", () => {
const currentIndex = services.findIndex(
(service) => service.id === routeTest.targetId
);
let nextIndex = currentIndex;
while (nextIndex === currentIndex) {
nextIndex = Math.floor(Math.random() * services.length);
}
$("#routeSelect").value = services[nextIndex].id;
routeTest.targetId = services[nextIndex].id;
routeTest.answered = false;
const target = services[nextIndex];
const feedback = $("#routeFeedback");
feedback.className = "route-feedback";
feedback.textContent = `Find ${target.name}. Click its raised symbol on the map.`;
$("#nextTarget").style.display = "none";
});
// ------------------------------------------------------------
// Reset and mobile panels
// ------------------------------------------------------------
$("#resetAll").addEventListener("click", () => {
services = initialServices.map((service) => ({
...service,
position: [...service.position]
}));
for (const service of services) {
const marker = markerMap.get(service.id);
marker.position.set(service.position[0], 0, service.position[1]);
updateMarkerSymbol(service);
}
selectedId = services[0].id;
routeTest.active = false;
routeTest.answered = false;
routeTest.score = 0;
routeTest.attempts = 0;
renderServices();
renderPalette();
renderSelection();
renderRouteSelect();
runAudit(false);
resetCamera();
$("#startRoute").textContent = "Start route test";
$("#nextTarget").style.display = "none";
$("#routeScore").textContent = "0 / 0";
$("#routeFeedback").className = "route-feedback";
$("#routeFeedback").textContent = "Start a test, then click the matching symbol on the map.";
showToast("Study reset.");
});
$("#toggleLeft").addEventListener("click", () => {
document.body.classList.toggle("show-left");
document.body.classList.remove("show-right");
});
$("#toggleRight").addEventListener("click", () => {
document.body.classList.toggle("show-right");
document.body.classList.remove("show-left");
});
$("#closeLeft").addEventListener("click", () => {
document.body.classList.remove("show-left");
});
$("#closeRight").addEventListener("click", () => {
document.body.classList.remove("show-right");
});
// ------------------------------------------------------------
// Utilities and render loop
// ------------------------------------------------------------
let toastTimer = null;
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 2600);
}
const resizeObserver = new ResizeObserver(() => {
const width = host.clientWidth;
const height = host.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
resizeObserver.observe(host);
renderServices();
renderPalette();
renderSelection();
renderLegend();
renderRouteSelect();
runAudit(false);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
for (const marker of markerMap.values()) {
if (marker.userData.ring.visible) {
const scale = 1 + Math.sin(elapsed * 3.2) * 0.045;
marker.userData.ring.scale.setScalar(scale);
}
}
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```