Skip to content

Commit 2a782d1

Browse files
committed
wip
1 parent 8cf2bf0 commit 2a782d1

File tree

3 files changed

+37
-35
lines changed

3 files changed

+37
-35
lines changed

src/app/(main)/community/events/map/engine.ts

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export type MarkerPoint = {
2323
id: string
2424
lon: number
2525
lat: number
26-
isHub?: boolean
2726
}
2827

2928
export type MapHandle = {
3029
dispose(): void
3130
setThemeColors(colors: MapColors): void
31+
setActiveMarker(id: string | null): void
3232
resetView(): void
3333
}
3434

@@ -46,7 +46,7 @@ export type BootOptions = {
4646
const MIN_ZOOM = 1
4747
const MAX_ZOOM = 20
4848
const MARKER_TYPE_REGULAR = 1
49-
const MARKER_TYPE_HUB = 2
49+
const MARKER_TYPE_ACTIVE = 2
5050
const POINTER_TRAIL_CAPACITY = 8
5151
const POINTER_TRAIL_LIFETIME_MS = 480
5252
const POINTER_TRAIL_MIN_DISTANCE = 6
@@ -117,7 +117,8 @@ class MapEngine implements MapHandle {
117117
private markerCount: number
118118
private markerCapacityWarned = false
119119
private readonly markerColor: Float32Array
120-
private readonly hubMarkerColor: Float32Array
120+
private readonly markerIndexById: Map<string, number>
121+
private activeMarkerIndex = -1
121122
private readonly resizeObserver: ResizeObserver
122123
private readonly diagnostics: Diagnostics | null
123124
private lastRenderState: {
@@ -163,7 +164,10 @@ class MapEngine implements MapHandle {
163164
this.markerData = new Float32Array(MARKER_CAPACITY * 4)
164165
this.markerCount = this.packMarkers(this.markerPoints, this.markerData)
165166
this.markerColor = new Float32Array(options.theme.marker)
166-
this.hubMarkerColor = new Float32Array(options.theme.marker)
167+
this.markerIndexById = new Map()
168+
this.markerPoints.forEach((marker, index) => {
169+
this.markerIndexById.set(marker.id, index)
170+
})
167171

168172
this.fullscreenVAO = this.gl.createVertexArray() as WebGLVertexArrayObject
169173
this.uploadMarkerUniforms()
@@ -180,6 +184,9 @@ class MapEngine implements MapHandle {
180184
: null
181185
this.loop()
182186
}
187+
setActiveMarker(id: string | null): void {
188+
throw new Error("Method not implemented.")
189+
}
183190

184191
dispose() {
185192
if (this.destroyed) return
@@ -197,7 +204,21 @@ class MapEngine implements MapHandle {
197204
this.seaColor.set(colors.sea)
198205
this.landColor.set(colors.land)
199206
this.markerColor.set(colors.marker)
200-
this.hubMarkerColor.set(colors.marker)
207+
}
208+
209+
setActiveMarker(id: string | null) {
210+
const nextIndex = typeof id === "string" ? this.markerIndexById.get(id) ?? -1 : -1
211+
if (nextIndex === this.activeMarkerIndex) return
212+
if (this.activeMarkerIndex >= 0) {
213+
const prevBase = this.activeMarkerIndex * 4
214+
this.markerData[prevBase + 2] = MARKER_TYPE_REGULAR
215+
}
216+
this.activeMarkerIndex = nextIndex
217+
if (nextIndex >= 0) {
218+
const base = nextIndex * 4
219+
this.markerData[base + 2] = MARKER_TYPE_ACTIVE
220+
}
221+
this.uploadMarkerUniforms()
201222
}
202223

203224
private uploadMarkerUniforms() {
@@ -243,7 +264,7 @@ class MapEngine implements MapHandle {
243264
const base = i * 4
244265
target[base + 0] = uv[0]
245266
target[base + 1] = 1 - uv[1]
246-
target[base + 2] = marker.isHub ? MARKER_TYPE_HUB : MARKER_TYPE_REGULAR
267+
target[base + 2] = MARKER_TYPE_REGULAR
247268
target[base + 3] = 0
248269
}
249270
if (markers.length > capacity && !this.markerCapacityWarned) {
@@ -571,9 +592,6 @@ class MapEngine implements MapHandle {
571592
const panY = this.pan[1]
572593
const deviceCell = this.cellSize * this.pixelRatio
573594
const deviceSquare = this.squareSize * this.pixelRatio
574-
let pointerActive = 0
575-
let pointerCenterX = 0
576-
let pointerCenterY = 0
577595
const pointerTrailBuffer = this.pointerTrailBuffer
578596
pointerTrailBuffer.fill(0)
579597
let pointerTrailCount = 0
@@ -584,13 +602,8 @@ class MapEngine implements MapHandle {
584602
this.hoverPointer.y,
585603
)
586604
if (pointerDevice) {
587-
pointerActive = 1
588605
const pointerPx = pointerDevice[0]
589606
const pointerPy = pointerDevice[1]
590-
const cellX = Math.floor(pointerPx / deviceCell)
591-
const cellY = Math.floor(pointerPy / deviceCell)
592-
pointerCenterX = (cellX + 0.5) * deviceCell
593-
pointerCenterY = (cellY + 0.5) * deviceCell
594607
this.pushPointerTrail(pointerPx, pointerPy, now)
595608
}
596609
}
@@ -639,23 +652,7 @@ class MapEngine implements MapHandle {
639652
this.markerColor[1],
640653
this.markerColor[2],
641654
)
642-
setUniform3f(
643-
gl,
644-
this.dotsProgram,
645-
"uHubMarkerColor",
646-
this.hubMarkerColor[0],
647-
this.hubMarkerColor[1],
648-
this.hubMarkerColor[2],
649-
)
650655
setUniform1i(gl, this.dotsProgram, "uMarkerCount", this.markerCount)
651-
setUniform1i(gl, this.dotsProgram, "uPointerActive", pointerActive)
652-
setUniform2f(
653-
gl,
654-
this.dotsProgram,
655-
"uPointerCenter",
656-
pointerCenterX,
657-
pointerCenterY,
658-
)
659656
setUniform1i(gl, this.dotsProgram, "uPointerTrailCount", pointerTrailCount)
660657
const pointerTrailLocation = gl.getUniformLocation(
661658
this.dotsProgram,

src/app/(main)/community/events/map/shaders.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,20 @@ void main() {
8888
float markerType = markerTypeAtCellCenterPx(center);
8989
float pointerHalo = 0.0;
9090
float pointerTrail = 0.0;
91+
const float trailDecay = 1.2;
9192
for (int i = 0; i < 8; i++) {
9293
if (i >= uPointerTrailCount) {
9394
break;
9495
}
9596
vec4 entry = uPointerTrail[i];
9697
vec2 trailPos = entry.xy;
9798
float age = clamp(entry.z, 0.0, 1.0);
98-
float fade = 1.0 - age;
99+
float fade = exp(-trailDecay * age);
99100
float centerDist = length(center - trailPos);
100101
float centerInfluence = clamp(1.0 - centerDist / (uCell * 8.0), 0.0, 1.0);
101-
pointerTrail = max(pointerTrail, fade * centerInfluence);
102+
pointerTrail += fade * centerInfluence;
102103
if (markerType > 0.5) {
103-
float haloRadius = 0.5 * uSquare + 3.5 * uCell;
104+
float haloRadius = 0.5 * uSquare + 1.5 * uCell;
104105
float haloDist = length(fragPx - trailPos);
105106
float haloInfluence = clamp(1.0 - haloDist / haloRadius, 0.0, 1.0);
106107
pointerHalo = max(pointerHalo, fade * haloInfluence * haloInfluence * 0.35);
@@ -124,6 +125,7 @@ void main() {
124125
} else if (markerType > 0.5) {
125126
color = uMarkerColor;
126127
}
128+
pointerTrail = clamp(pointerTrail, 0.0, 1.0);
127129
float halfSquare = 0.5 * uSquare;
128130
if (pointerTrail > 0.0 && markerType <= 0.5) {
129131
float shrink = clamp(1.0 - pointerTrail * 0.12, 0.9, 1.0);

src/app/(main)/community/events/meetups-map.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { asRgbString, MAP_COLORS, MapColors } from "./map/map-colors"
1212

1313
const CELL_SIZE = 8
1414
const SQUARE_SIZE = 6
15-
const HUB_MEETUP_IDS = new Set(["paris"])
1615
const LAND_MASK_URL = new URL("./map/land-mask.png", import.meta.url).toString()
1716
const ASPECT_RATIO = 1.65
1817

@@ -22,7 +21,6 @@ const markerPoints: MarkerPoint[] = meetups.map(({ node }) => ({
2221
id: node.id,
2322
lon: node.longitude,
2423
lat: node.latitude,
25-
isHub: HUB_MEETUP_IDS.has(node.id),
2624
}))
2725

2826
type MapStatus = "loading" | "ready" | "error"
@@ -45,6 +43,11 @@ export function MeetupsMap() {
4543
initialThemeRef.current = themeColors
4644
}, [themeColors])
4745

46+
useEffect(() => {
47+
if (!handleRef.current) return
48+
handleRef.current.setActiveMarker(activeMeetupId)
49+
}, [activeMeetupId])
50+
4851
useEffect(() => {
4952
const canvas = canvasRef.current
5053
if (!canvas) return

0 commit comments

Comments
 (0)