@@ -7,7 +7,11 @@ import { useStorage } from '@store/useStorage'
77
88import { RouteTile } from './RouteTile'
99import { routeMarker } from './routeMarker'
10- import { useRouteStore , ROUTE_COORD_EPSILON } from './useRouteStore'
10+ import {
11+ useRouteStore ,
12+ ROUTE_COORD_EPSILON ,
13+ getRouteCoordKey ,
14+ } from './useRouteStore'
1115
1216const ACTIVE_Z_INDEX = 1800
1317const INACTIVE_Z_INDEX = 900
@@ -97,27 +101,42 @@ export function RouteLayer({ routes }) {
97101 } ,
98102 } )
99103
104+ const destinationCoords = React . useMemo ( ( ) => {
105+ if ( ! compactView ) return new Set ( )
106+ const keys = new Set ( )
107+ activeRoutes . forEach ( ( selection ) => {
108+ const route = routeCache [ selection . routeId ]
109+ if ( ! route ) return
110+ const isForward = selection . orientation === 'forward'
111+ const lat = isForward ? route . end_lat : route . start_lat
112+ const lon = isForward ? route . end_lon : route . start_lon
113+ keys . add ( getRouteCoordKey ( lat , lon ) )
114+ } )
115+ return keys
116+ } , [ activeRoutes , routeCache , compactView ] )
117+
100118 const anchors = React . useMemo ( ( ) => {
101119 if ( ! compactView ) return [ ]
102120 const values = Object . values ( poiIndex )
103121 return values . map ( ( entry ) => {
104- const seen = new Set ( )
105- let count = 0
122+ const uniqueRoutes = new Set ( )
106123 values . forEach ( ( candidate ) => {
107124 if (
108125 Math . abs ( candidate . lat - entry . lat ) <= ROUTE_COORD_EPSILON &&
109126 Math . abs ( candidate . lon - entry . lon ) <= ROUTE_COORD_EPSILON
110127 ) {
111128 candidate . routes . forEach ( ( ref ) => {
112- const id = `${ ref . routeId } -${ ref . orientation } `
113- if ( ! seen . has ( id ) && routeCache [ ref . routeId ] ) {
114- seen . add ( id )
115- count += 1
129+ if ( routeCache [ ref . routeId ] ) {
130+ uniqueRoutes . add ( ref . routeId )
116131 }
117132 } )
118133 }
119134 } )
120- return { entry, routeCount : count || entry . routes . length || 1 }
135+ return {
136+ entry,
137+ routeCount :
138+ uniqueRoutes . size || new Set ( entry . routes . map ( ( r ) => r . routeId ) ) . size ,
139+ }
121140 } )
122141 } , [ compactView , poiIndex , routeCache ] )
123142
@@ -137,15 +156,21 @@ export function RouteLayer({ routes }) {
137156
138157 return (
139158 < >
140- { anchors . map ( ( { entry, routeCount } ) => (
141- < RouteAnchor
142- key = { entry . key }
143- entry = { entry }
144- selected = { entry . key === activePoiId }
145- onSelect = { selectPoi }
146- routeCount = { routeCount }
147- />
148- ) ) }
159+ { anchors . map ( ( { entry, routeCount } ) => {
160+ const entryCoordKey = getRouteCoordKey ( entry . lat , entry . lon )
161+ if ( destinationCoords . has ( entryCoordKey ) && entry . key !== activePoiId ) {
162+ return null
163+ }
164+ return (
165+ < RouteAnchor
166+ key = { entry . key }
167+ entry = { entry }
168+ selected = { entry . key === activePoiId }
169+ onSelect = { selectPoi }
170+ routeCount = { routeCount }
171+ />
172+ )
173+ } ) }
149174 { activeRoutes . map ( ( selection ) => (
150175 < ActiveRoute
151176 key = { `${ selection . routeId } -${ selection . orientation } ` }
0 commit comments