Survey Map
A monochrome city drawn in fine lines on black, generated entirely in code: districts on their own street grids, highways sweeping through, a river cutting across, all under a surveyor's grid with compass letters and a scale bar. Grid squares develop into bright aerial views of the city under your cursor and fade back behind it, a click sends a survey pulse developing squares as it ripples out, and scrolling pans across the city. When idle, squares develop on their own.
Tweak
LIVELIVEColour
Map
Motion
Labels
Compass letters and scale bar
Interactive
Squares develop under the cursor, clicks send a pulse
Usage
Follows your tweaks.
import { SurveyMap } from "@/components/inreact/survey-map";
export function Hero() {
return (
<SurveyMap
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the map */}
</SurveyMap>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/survey-map.jsonOr copy the source
Install the dependencies, then save this as components/inreact/survey-map.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Survey Map: a dark city map whose grid squares develop into aerial photographs.
*
* A monochrome city drawn in fine lines on black: districts each laid out on
* their own street grid, highways sweeping through, a river cutting across, all
* under a surveyor's grid with compass letters and a scale bar. Here and there a
* square of the grid develops into a bright aerial view (rooftops, blocks,
* streets in relief) then fades back into lines.
*
* It reacts: squares develop under your cursor and along its trail, then fade
* as you move on; a click sends a survey pulse rippling out, developing squares
* as it passes; scrolling pans across the city. On load the streets draw in.
* When idle, squares develop and fade on their own and the map drifts slowly.
*
* <SurveyMap className="h-screen w-full">
* <YourHero />
* </SurveyMap>
*
* WebGL: one shader (procedural districts, streets, highways, river, grid and
* aerial tiles, all antialiased); the labels are a light HTML layer. GSAP drives
* every motion. Pauses off-screen; reduced motion shows a still frame; a CSS
* grid without WebGL.
*/
export interface SurveyMapProps {
/** Colour of the lines and the developed squares. */
ink?: string;
/** Background colour. */
background?: string;
/** Size of a grid square, in px at 1000px tall (scales with the height). */
cell?: number;
/** How busy the city is. */
density?: number;
/** Brightness of the developed squares. */
intensity?: number;
/** How often squares develop on their own. */
activity?: number;
/** Speed of the drift. */
speed?: number;
/** Show the compass letters and scale bar. */
labels?: boolean;
/** Cursor reveal, click pulse. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the map. */
children?: ReactNode;
className?: string;
}
const TRAIL = 12;
const VERT = `attribute vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;
const FRAG = `
#extension GL_OES_standard_derivatives : enable
precision highp float;
uniform vec2 uRes, uPan, uPulseC;
uniform float uTime, uIn, uCell, uDensity, uIntensity, uActivity, uPulse, uPulseAmp, uPx;
uniform vec3 uInk, uBg;
uniform vec3 uTrail[${TRAIL}];
float hash(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
vec2 hash2(vec2 p) { return vec2(hash(p), hash(p + 17.31)); }
float vnoise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);
}
float fbm(vec2 p) {
float v = 0.0, a = 0.5;
for (int i = 0; i < 4; i++) { v += a * vnoise(p); p = p * 2.03 + 7.1; a *= 0.5; }
return v;
}
// an antialiased line at distance d (in world units)
float aline(float d, float wpx) { return 1.0 - smoothstep(0.0, wpx * uPx, abs(d)); }
// the district at q: nearest of a jittered set of centres, each with its own street angle
vec3 district(vec2 q) {
vec2 g = q / 0.28;
vec2 i0 = floor(g);
float best = 9.0;
vec2 bid = vec2(0.0);
for (int j = -1; j <= 1; j++)
for (int i = -1; i <= 1; i++) {
vec2 id = i0 + vec2(float(i), float(j));
vec2 c = id + hash2(id);
float d = length(g - c);
if (d < best) { best = d; bid = id; }
}
return vec3(bid, hash(bid + 3.7) * 1.5708);
}
// the city as lines: streets, highways and the river's banks; returns (lines, built-up, river)
vec3 city(vec2 q) {
vec2 o = q - vec2(0.85, 0.5);
float urban = smoothstep(0.45, 0.62, fbm(q * 1.5 + 3.0) * uDensity * 1.08);
vec3 dd = district(q);
float a = dd.z;
mat2 R = mat2(cos(a), -sin(a), sin(a), cos(a));
// streets wobble a little, like a real city laid over land
vec2 sq = R * (q + (vec2(fbm(q * 6.0), fbm(q * 6.0 + 4.0)) - 0.5) * 0.012);
float sp = mix(0.018, 0.011, hash(dd.xy + 9.1));
vec2 f = abs(fract(sq / sp + 0.5) - 0.5) * sp;
// streets come and go block by block, so the grid is broken
vec2 blk = floor(sq / (sp * 4.0));
float keepx = step(0.42, hash(blk + 1.3));
float keepy = step(0.42, hash(blk + 7.9));
float streets = max(aline(f.x, 0.6) * keepx, aline(f.y, 0.6) * keepy) * urban * 0.32;
// sparse country roads wandering through the open land
float country = 0.0;
for (int k = 0; k < 3; k++) {
float fk = float(k);
float y = o.y - (fk - 1.0) * 0.32 - (fbm(vec2(o.x * 1.5 + fk * 5.0, fk)) - 0.5) * 0.35;
float x = o.x - (fk - 1.0) * 0.5 - (fbm(vec2(o.y * 1.5 + fk * 9.0, fk + 3.0)) - 0.5) * 0.35;
country = max(country, max(aline(y, 0.7), aline(x, 0.7)));
}
streets = max(streets, country * (1.0 - urban) * 0.28);
// highways: long sweeping curves across the frame, brighter
float hw = 0.0;
for (int k = 0; k < 4; k++) {
float fk = float(k);
float ang = fk * 0.8 - 0.9;
vec2 r = mat2(cos(ang), -sin(ang), sin(ang), cos(ang)) * o;
float y = r.y - (fk - 1.5) * 0.28 - 0.1 * sin(r.x * 1.8 + fk * 2.0) - 0.03 * sin(r.x * 4.3 + fk);
hw = max(hw, aline(y, 1.3) * (0.55 + 0.35 * hash(vec2(fk, 2.0))));
}
// the river: a dark meandering band with pale banks, crossing the frame
float rv = o.y + 0.08 - 0.14 * sin(o.x * 1.6 + 0.5) - 0.05 * sin(o.x * 4.1);
float river = smoothstep(0.016, 0.008, abs(rv));
float banks = aline(abs(rv) - 0.013, 0.8) * 0.55;
float lines = max(max(streets, hw), banks) * (1.0 - river);
return vec3(lines, urban, river);
}
// a developed square: an aerial view of the same city, blocks of lit rooftops between dark streets
float aerial(vec2 q, vec3 c) {
vec3 dd = district(q);
float a = dd.z;
mat2 R = mat2(cos(a), -sin(a), sin(a), cos(a));
vec2 sq = R * q;
float bs = 0.016;
vec2 bid = floor(sq / bs);
vec2 bl = fract(sq / bs);
// buildings within each block, of varied size and height
vec2 sub = floor(bl * (2.0 + floor(hash(bid) * 3.0)));
float hgt = hash(bid * 3.1 + sub);
float edge = min(min(bl.x, 1.0 - bl.x), min(bl.y, 1.0 - bl.y));
float inBlock = smoothstep(0.06, 0.12, edge);
// each roof catches light on one side, with a soft cast shadow on the other
vec2 sl = fract(bl * (2.0 + floor(hash(bid) * 3.0)));
float lit = 0.65 + 0.35 * smoothstep(0.3, 0.9, sl.x * 0.6 + sl.y * 0.4);
float shade = 1.0 - 0.5 * smoothstep(0.75, 1.0, sl.x) * hgt;
float roofs = (0.38 + 0.7 * hgt) * lit * shade * inBlock;
float ground = 0.12 + 0.3 * fbm(q * 45.0) * (0.6 + 0.4 * fbm(q * 7.0));
float v = mix(ground, roofs, c.y * 0.9 + 0.1);
// the roads show pale in the photograph, the river dark with a glint
v = max(v, c.x * 0.9);
v = mix(v, 0.06 + 0.25 * fbm(q * 30.0 + uTime * 0.05), c.z);
return clamp(v, 0.0, 1.0);
}
void main() {
float H = uRes.y;
vec2 p = gl_FragCoord.xy / H;
vec2 q = p + uPan;
vec3 c = city(q);
// the survey grid, fixed to the screen
vec2 cellId = floor(p / uCell);
vec2 cellC = (cellId + 0.5) * uCell;
vec2 gf = abs(fract(p / uCell + 0.5) - 0.5) * uCell;
float grid = max(aline(gf.x, 0.8), aline(gf.y, 0.8));
// how developed this square is: on its own now and then, along the cursor's trail, under a pulse
float hc = hash(cellId + 5.3);
float idle = smoothstep(0.86, 0.985, sin(uTime * 0.19 * (0.6 + hc) + hc * 60.0)) * step(1.0 - 0.35 * uActivity, hash(cellId + 2.1));
float dev = idle;
for (int i = 0; i < ${TRAIL}; i++) {
vec3 t = uTrail[i];
if (t.z <= 0.0) continue;
vec2 d = (cellC - t.xy) / uCell;
dev = max(dev, t.z * smoothstep(1.35, 0.6, length(d)));
}
float pr = length(cellC - uPulseC) - uPulse * 1.8;
dev = max(dev, exp(-pr * pr / (uCell * uCell * 1.2)) * uPulseAmp);
dev = clamp(dev, 0.0, 1.0);
// the lines draw in on load, the streets after the highways
float lines = c.x * 1.0 * smoothstep(0.0, 0.4, uIn * 1.4 - hash(floor(q * 30.0)) * 0.4);
vec3 col = uBg + uInk * lines * 0.85;
// a developed square: the aerial view, framed crisply by the grid
float aer = aerial(q, vec3(c.x, c.y, c.z)) * uIntensity;
col = mix(col, uBg + uInk * aer, dev);
col += uInk * grid * (0.16 + 0.25 * dev);
// a faint survey circle round the centre of the frame
float rc = length(p - vec2(uRes.x / uRes.y * 0.62, 0.42)) - 0.46;
col += uInk * aline(rc, 0.8) * 0.12;
// the pulse ring itself
col += uInk * exp(-pr * pr / 0.0004) * uPulseAmp * 0.35;
col += (hash(gl_FragCoord.xy + fract(uTime) * 91.0) - 0.5) / 160.0;
gl_FragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
}`;
const isReducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function rgb(hex: string): [number, number, number] {
let h = hex.replace("#", "");
if (h.length === 3) h = h.replace(/./g, (c) => c + c);
const n = parseInt(h, 16) || 0;
return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
}
export function SurveyMap({
ink = "#e8e8e6",
background = "#000000",
cell = 105,
density = 1,
intensity = 1,
activity = 1,
speed = 1,
labels = true,
interactive = true,
scroller,
children,
className,
}: SurveyMapProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ ink, background, cell, density, intensity, activity, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { ink, background, cell, density, intensity, activity, speed, interactive };
redraw.current?.();
}, [ink, background, cell, density, intensity, activity, speed, interactive]);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
if (getComputedStyle(host).position === "static") host.style.position = "relative";
const still = isReducedMotion();
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y;";
host.prepend(canvas);
const gl = canvas.getContext("webgl", { alpha: false, antialias: false });
if (!gl) {
const p = props.current;
host.style.background = `linear-gradient(${p.ink}33 1px, transparent 1px) 0 0 / 105px 105px, linear-gradient(90deg, ${p.ink}33 1px, transparent 1px) 0 0 / 105px 105px, ${p.background}`;
canvas.remove();
return;
}
gl.getExtension("OES_standard_derivatives");
const prog = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, VERT],
[gl.FRAGMENT_SHADER, FRAG],
] as const) {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
gl.attachShader(prog, sh);
}
gl.linkProgram(prog);
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(prog));
gl.useProgram(prog);
const buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
const aPos = gl.getAttribLocation(prog, "aPos");
gl.enableVertexAttribArray(aPos);
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
const U = Object.fromEntries(
["uRes", "uPan", "uPulseC", "uTime", "uIn", "uCell", "uDensity", "uIntensity", "uActivity", "uPulse", "uPulseAmp", "uPx", "uInk", "uBg", "uTrail"].map((n) => [n, gl.getUniformLocation(prog, n)]),
) as Record<string, WebGLUniformLocation | null>;
let w = 1, h = 1, dpr = 1;
const resize = () => {
dpr = Math.min(window.devicePixelRatio || 1, 2);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
gl.viewport(0, 0, canvas.width, canvas.height);
};
resize();
// ---- state: every value GSAP moves (height units, y up) ----
const s = { in: still ? 1 : 0, px: 0, py: 0, scroll: 0, pulse: 0, pulseAmp: 0, pcx: 0, pcy: 0 };
const trail = new Float32Array(TRAIL * 3);
let trailHead = 0, trailClock = 0;
let time = still ? 40 : 0, drift = 0;
const draw = () => {
const p = props.current;
gl.uniform2f(U.uRes, canvas.width, canvas.height);
gl.uniform2f(U.uPan, s.px + drift * 0.01, s.py + s.scroll + drift * 0.004);
gl.uniform2f(U.uPulseC, s.pcx, s.pcy);
gl.uniform1f(U.uTime, time);
gl.uniform1f(U.uIn, s.in);
gl.uniform1f(U.uCell, Math.max(30, p.cell) / 1000);
gl.uniform1f(U.uDensity, p.density);
gl.uniform1f(U.uIntensity, p.intensity);
gl.uniform1f(U.uActivity, p.activity);
gl.uniform1f(U.uPulse, s.pulse);
gl.uniform1f(U.uPulseAmp, s.pulseAmp);
gl.uniform1f(U.uPx, 1 / canvas.height);
gl.uniform3fv(U.uInk, rgb(p.ink));
gl.uniform3fv(U.uBg, rgb(p.background));
gl.uniform3fv(U.uTrail, trail);
gl.drawArrays(gl.TRIANGLES, 0, 3);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the streets draw in ----
const intro = gsap.to(s, { in: 1, duration: 2.6, ease: "power2.inOut", delay: 0.1 });
// ---- cursor: squares develop along its trail and fade behind it; the map leans a touch ----
const pxTo = gsap.quickTo(s, "px", { duration: 1.6, ease: "power3" });
const pyTo = gsap.quickTo(s, "py", { duration: 1.6, ease: "power3" });
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: (e.clientX - r.left) / r.height, y: (r.bottom - e.clientY) / r.height, nx: (e.clientX - r.left) / r.width - 0.5, ny: 0.5 - (e.clientY - r.top) / r.height };
};
let last: { x: number; y: number } | null = null;
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
pxTo(p.nx * 0.04);
pyTo(p.ny * 0.04);
const cellSize = Math.max(30, props.current.cell) / 1000;
// drop a trail point each time the cursor has travelled about half a square
if (!last || Math.hypot(p.x - last.x, p.y - last.y) > cellSize * 0.5) {
trail.set([p.x, p.y, 1], trailHead * 3);
trailHead = (trailHead + 1) % TRAIL;
last = p;
} else {
// the newest point follows the cursor and stays fully developed
const k = ((trailHead - 1 + TRAIL) % TRAIL) * 3;
trail[k] = p.x;
trail[k + 1] = p.y;
trail[k + 2] = 1;
}
};
const leave = () => {
last = null;
pxTo(0);
pyTo(0);
};
// ---- click: a survey pulse ripples out, developing squares as it passes ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
s.pcx = p.x;
s.pcy = p.y;
gsap.killTweensOf(s, "pulse,pulseAmp");
gsap.fromTo(s, { pulse: 0 }, { pulse: 1, duration: 2.6, ease: "power1.out" });
gsap.timeline().fromTo(s, { pulseAmp: 0 }, { pulseAmp: 1, duration: 0.2, ease: "sine.out" }).to(s, { pulseAmp: 0, duration: 2.4, ease: "sine.in" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: pan across the city ----
const scrollTo = gsap.quickTo(s, "scroll", { duration: 1.2, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => scrollTo(self.progress * 0.6),
});
// ---- loop, only while on screen: the trail fades, the map drifts ----
let visible = true;
let prev = performance.now();
const loop = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
time += dt;
drift += dt * props.current.speed;
trailClock += dt;
for (let i = 0; i < TRAIL; i++) {
const k = i * 3 + 2;
if (i === (trailHead - 1 + TRAIL) % TRAIL && last) continue;
trail[k] = Math.max(0, trail[k] - dt / 1.6);
}
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
return () => {
gsap.ticker.remove(loop);
intro.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
const label = "pointer-events-none absolute select-none font-mono text-[11px] tracking-[0.2em]";
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
{labels && (
<div aria-hidden="true" className="pointer-events-none absolute inset-0 z-[1]" style={{ color: ink, opacity: 0.55 }}>
<span className={`${label} left-3 top-1/2 -translate-y-1/2`}>W</span>
<span className={`${label} right-3 top-1/2 -translate-y-1/2`}>E</span>
<span className={`${label} left-1/2 top-3 -translate-x-1/2`}>N</span>
<span className={`${label} bottom-3 left-1/2 -translate-x-1/2`}>S</span>
<div className="absolute bottom-8 left-6 flex items-end gap-0 font-mono text-[9px] tracking-wider">
{[0, 300, 600, 900, 1200].map((n) => (
<span key={n} className="flex w-12 flex-col items-start">
<span className="h-1.5 w-px" style={{ background: ink }} />
<span className="mt-1">{n}</span>
</span>
))}
</div>
</div>
)}
{children && <div className="relative z-10 h-full">{children}</div>}
</div>
);
}
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
12 propsinkstringColour of the lines and the developed squares.default "#e8e8e6"default "#e8e8e6"backgroundstringBackground colour.default "#000000"default "#000000"cellnumberSize of a grid square, in px at 1000px tall (scales with the height).default 105default 105densitynumberHow busy the city is.default 1default 1intensitynumberBrightness of the developed squares.default 1default 1activitynumberHow often squares develop on their own.default 1default 1speednumberSpeed of the drift.default 1default 1labelsbooleanShow the compass letters and scale bar.default truedefault trueinteractivebooleanCursor reveal, click pulse.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the map.classNamestringSize it, e.g. h-screen w-full.