@@ -23,12 +23,12 @@ export type MarkerPoint = {
2323 id : string
2424 lon : number
2525 lat : number
26- isHub ?: boolean
2726}
2827
2928export 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 = {
4646const MIN_ZOOM = 1
4747const MAX_ZOOM = 20
4848const MARKER_TYPE_REGULAR = 1
49- const MARKER_TYPE_HUB = 2
49+ const MARKER_TYPE_ACTIVE = 2
5050const POINTER_TRAIL_CAPACITY = 8
5151const POINTER_TRAIL_LIFETIME_MS = 480
5252const 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 ,
0 commit comments