mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
createGlobe() implements the Globe API in mobile/DESIGN.md: Esri day imagery blended with NASA Black Marble night lights across the terminator, Google 3D tiles below 25 km when keyed, a single-pass grade with half-res bloom and lenses, an adaptive quality governor, live layers on the repo's /api routes and parsers, time scrubbing, picking, AR contact queries and live situation cards. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVYRAqiQj9Y1V9ZfG1RcDH
254 lines
6.3 KiB
JavaScript
254 lines
6.3 KiB
JavaScript
/**
|
|
* Small canvas glyphs for billboards. Drawn once in white at 2x, tinted per
|
|
* layer through `billboard.color`, and shared through a fixed `imageId` so the
|
|
* texture atlas holds each glyph exactly once however many billboards use it.
|
|
*/
|
|
|
|
const SIZE = 48; // drawn at 2x, displayed at scale 0.5 → 24 css px
|
|
const cache = new Map();
|
|
|
|
function canvas(size = SIZE) {
|
|
const c = document.createElement('canvas');
|
|
c.width = c.height = size;
|
|
return c;
|
|
}
|
|
|
|
function stroke(ctx, width = 3) {
|
|
ctx.lineJoin = 'round';
|
|
ctx.lineCap = 'round';
|
|
ctx.strokeStyle = 'rgba(0,0,0,0.55)';
|
|
ctx.lineWidth = width;
|
|
ctx.stroke();
|
|
ctx.fillStyle = '#fff';
|
|
ctx.fill();
|
|
}
|
|
|
|
const painters = {
|
|
dot(ctx, s) {
|
|
const g = ctx.createRadialGradient(s / 2, s / 2, 0, s / 2, s / 2, s / 2);
|
|
g.addColorStop(0, 'rgba(255,255,255,1)');
|
|
g.addColorStop(0.18, 'rgba(255,255,255,0.95)');
|
|
g.addColorStop(0.4, 'rgba(255,255,255,0.35)');
|
|
g.addColorStop(1, 'rgba(255,255,255,0)');
|
|
ctx.fillStyle = g;
|
|
ctx.fillRect(0, 0, s, s);
|
|
},
|
|
plane(ctx) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(24, 3);
|
|
ctx.lineTo(27.5, 9);
|
|
ctx.lineTo(27.5, 19);
|
|
ctx.lineTo(44, 29);
|
|
ctx.lineTo(44, 33);
|
|
ctx.lineTo(27.5, 28);
|
|
ctx.lineTo(27, 38);
|
|
ctx.lineTo(33, 43);
|
|
ctx.lineTo(33, 45.5);
|
|
ctx.lineTo(24, 43);
|
|
ctx.lineTo(15, 45.5);
|
|
ctx.lineTo(15, 43);
|
|
ctx.lineTo(21, 38);
|
|
ctx.lineTo(20.5, 28);
|
|
ctx.lineTo(4, 33);
|
|
ctx.lineTo(4, 29);
|
|
ctx.lineTo(20.5, 19);
|
|
ctx.lineTo(20.5, 9);
|
|
ctx.closePath();
|
|
stroke(ctx);
|
|
},
|
|
heli(ctx) {
|
|
ctx.beginPath();
|
|
ctx.ellipse(24, 22, 6.5, 9, 0, 0, Math.PI * 2);
|
|
ctx.rect(22.5, 28, 3, 15);
|
|
ctx.rect(18, 41, 12, 3);
|
|
stroke(ctx);
|
|
ctx.beginPath();
|
|
ctx.lineWidth = 2.5;
|
|
ctx.strokeStyle = '#fff';
|
|
ctx.moveTo(7, 7);
|
|
ctx.lineTo(41, 37);
|
|
ctx.moveTo(41, 7);
|
|
ctx.lineTo(7, 37);
|
|
ctx.stroke();
|
|
},
|
|
ship(ctx) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(24, 4);
|
|
ctx.quadraticCurveTo(34, 16, 32, 42);
|
|
ctx.lineTo(16, 42);
|
|
ctx.quadraticCurveTo(14, 16, 24, 4);
|
|
ctx.closePath();
|
|
stroke(ctx);
|
|
},
|
|
sat(ctx) {
|
|
ctx.beginPath();
|
|
ctx.rect(19, 18, 10, 12);
|
|
ctx.rect(3, 20, 14, 8);
|
|
ctx.rect(31, 20, 14, 8);
|
|
stroke(ctx, 2.5);
|
|
},
|
|
iss(ctx) {
|
|
ctx.beginPath();
|
|
ctx.rect(21, 14, 6, 20);
|
|
ctx.rect(3, 8, 6, 14);
|
|
ctx.rect(11, 8, 6, 14);
|
|
ctx.rect(31, 8, 6, 14);
|
|
ctx.rect(39, 8, 6, 14);
|
|
ctx.rect(3, 26, 6, 14);
|
|
ctx.rect(11, 26, 6, 14);
|
|
ctx.rect(31, 26, 6, 14);
|
|
ctx.rect(39, 26, 6, 14);
|
|
ctx.rect(9, 22.5, 30, 3);
|
|
stroke(ctx, 2);
|
|
},
|
|
ring(ctx, s) {
|
|
ctx.beginPath();
|
|
ctx.arc(s / 2, s / 2, s / 2 - 5, 0, Math.PI * 2);
|
|
ctx.lineWidth = 3;
|
|
ctx.strokeStyle = '#fff';
|
|
ctx.shadowColor = 'rgba(0,0,0,0.6)';
|
|
ctx.shadowBlur = 3;
|
|
ctx.stroke();
|
|
for (let i = 0; i < 4; i++) {
|
|
const a = (i * Math.PI) / 2;
|
|
ctx.beginPath();
|
|
ctx.moveTo(
|
|
s / 2 + Math.cos(a) * (s / 2 - 1),
|
|
s / 2 + Math.sin(a) * (s / 2 - 1),
|
|
);
|
|
ctx.lineTo(
|
|
s / 2 + Math.cos(a) * (s / 2 - 12),
|
|
s / 2 + Math.sin(a) * (s / 2 - 12),
|
|
);
|
|
ctx.stroke();
|
|
}
|
|
},
|
|
quake(ctx, s) {
|
|
for (const [r, a] of [
|
|
[20, 0.45],
|
|
[13, 0.8],
|
|
]) {
|
|
ctx.beginPath();
|
|
ctx.arc(s / 2, s / 2, r, 0, Math.PI * 2);
|
|
ctx.lineWidth = 3;
|
|
ctx.strokeStyle = `rgba(255,255,255,${a})`;
|
|
ctx.stroke();
|
|
}
|
|
ctx.beginPath();
|
|
ctx.arc(s / 2, s / 2, 6, 0, Math.PI * 2);
|
|
ctx.fillStyle = '#fff';
|
|
ctx.fill();
|
|
},
|
|
fire(ctx) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(24, 4);
|
|
ctx.bezierCurveTo(34, 16, 40, 24, 36, 34);
|
|
ctx.bezierCurveTo(33, 43, 15, 43, 12, 34);
|
|
ctx.bezierCurveTo(9, 26, 16, 22, 18, 14);
|
|
ctx.bezierCurveTo(21, 20, 24, 20, 24, 4);
|
|
ctx.closePath();
|
|
stroke(ctx);
|
|
},
|
|
cyclone(ctx, s) {
|
|
ctx.lineWidth = 5;
|
|
ctx.strokeStyle = '#fff';
|
|
ctx.lineCap = 'round';
|
|
for (let k = 0; k < 2; k++) {
|
|
ctx.beginPath();
|
|
for (let t = 0; t <= 1.0001; t += 0.05) {
|
|
const a = k * Math.PI + t * Math.PI * 1.25;
|
|
const r = 4 + t * 17;
|
|
const x = s / 2 + Math.cos(a) * r;
|
|
const y = s / 2 + Math.sin(a) * r;
|
|
if (t === 0) ctx.moveTo(x, y);
|
|
else ctx.lineTo(x, y);
|
|
}
|
|
ctx.stroke();
|
|
}
|
|
ctx.beginPath();
|
|
ctx.arc(s / 2, s / 2, 5, 0, Math.PI * 2);
|
|
ctx.fillStyle = '#fff';
|
|
ctx.fill();
|
|
},
|
|
rocket(ctx) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(24, 3);
|
|
ctx.bezierCurveTo(31, 10, 31, 22, 30, 32);
|
|
ctx.lineTo(36, 40);
|
|
ctx.lineTo(29, 39);
|
|
ctx.lineTo(27, 44);
|
|
ctx.lineTo(21, 44);
|
|
ctx.lineTo(19, 39);
|
|
ctx.lineTo(12, 40);
|
|
ctx.lineTo(18, 32);
|
|
ctx.bezierCurveTo(17, 22, 17, 10, 24, 3);
|
|
ctx.closePath();
|
|
stroke(ctx);
|
|
},
|
|
camera(ctx) {
|
|
ctx.beginPath();
|
|
ctx.roundRect(7, 15, 26, 18, 4);
|
|
ctx.moveTo(33, 20);
|
|
ctx.lineTo(42, 15);
|
|
ctx.lineTo(42, 33);
|
|
ctx.lineTo(33, 28);
|
|
ctx.closePath();
|
|
stroke(ctx);
|
|
},
|
|
volcano(ctx) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(4, 42);
|
|
ctx.lineTo(18, 16);
|
|
ctx.lineTo(30, 16);
|
|
ctx.lineTo(44, 42);
|
|
ctx.closePath();
|
|
stroke(ctx);
|
|
ctx.beginPath();
|
|
ctx.arc(24, 9, 5, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
},
|
|
pin(ctx) {
|
|
ctx.beginPath();
|
|
ctx.arc(24, 18, 12, Math.PI, 0);
|
|
ctx.bezierCurveTo(36, 28, 28, 34, 24, 45);
|
|
ctx.bezierCurveTo(20, 34, 12, 28, 12, 18);
|
|
ctx.closePath();
|
|
stroke(ctx);
|
|
ctx.beginPath();
|
|
ctx.arc(24, 18, 4.5, 0, Math.PI * 2);
|
|
ctx.fillStyle = 'rgba(0,0,0,0.6)';
|
|
ctx.fill();
|
|
},
|
|
port(ctx) {
|
|
ctx.beginPath();
|
|
ctx.arc(24, 10, 5, 0, Math.PI * 2);
|
|
ctx.moveTo(24, 15);
|
|
ctx.lineTo(24, 42);
|
|
ctx.moveTo(14, 22);
|
|
ctx.lineTo(34, 22);
|
|
ctx.moveTo(8, 30);
|
|
ctx.quadraticCurveTo(10, 42, 24, 42);
|
|
ctx.quadraticCurveTo(38, 42, 40, 30);
|
|
ctx.lineWidth = 7;
|
|
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
|
|
ctx.lineCap = 'round';
|
|
ctx.stroke();
|
|
ctx.lineWidth = 3.5;
|
|
ctx.strokeStyle = '#fff';
|
|
ctx.stroke();
|
|
},
|
|
};
|
|
|
|
/** `{ image, imageId }` for a named glyph. */
|
|
export function glyph(name) {
|
|
let entry = cache.get(name);
|
|
if (entry) return entry;
|
|
const paint = painters[name] || painters.dot;
|
|
const size = name === 'dot' ? 32 : SIZE;
|
|
const c = canvas(size);
|
|
paint(c.getContext('2d'), size);
|
|
entry = { image: c, imageId: `gev-mobile-glyph-${name}` };
|
|
cache.set(name, entry);
|
|
return entry;
|
|
}
|