@@ -165,77 +165,3 @@ export function getResolutionForZoom(zoom: number): ResolutionKey {
165165 if ( zoom >= 6 ) return '5km' // province/state level
166166 return '10km' // country/region level
167167}
168-
169- /**
170- * Calculate most common labels at multiple resolutions
171- * Items are sorted by frequency (most common first) for better Mapbox clustering
172- */
173- function calculateMultiResolutionLabels ( items : Item [ ] ) : MultiResolutionLabels {
174- const RESOLUTION_TO_METERS : Record < ResolutionKey , number > = {
175- '100m' : 1000 ,
176- '300m' : 300 ,
177- '1.5km' : 67 ,
178- '5km' : 20 ,
179- '10km' : 10 ,
180- }
181-
182- const labels = new Map < string , Map < ResolutionKey , string > > ( )
183- const itemFrequency = new Map < string , number > ( )
184-
185- // Process each resolution
186- Object . entries ( RESOLUTION_TO_METERS ) . forEach ( ( [ resolution , multiplier ] ) => {
187- const resKey = resolution as ResolutionKey
188-
189- // Group items by this resolution's grid
190- const grouped = items . reduce ( ( acc , item ) => {
191- const { latitude, longitude, isInvalidPoint } = validatePoint ( item . coordinates )
192- if ( isInvalidPoint ) return acc
193-
194- const gridKey = `${ Math . round ( latitude * multiplier ) / multiplier } ,${ Math . round ( longitude * multiplier ) / multiplier } `
195- if ( ! acc [ gridKey ] ) acc [ gridKey ] = [ ]
196- acc [ gridKey ] . push ( item )
197- return acc
198- } , { } as Record < string , Item [ ] > )
199-
200- // For each grid cell, find most common label
201- Object . entries ( grouped ) . forEach ( ( [ gridKey , group ] ) => {
202- const labelCounts : Record < string , number > = { }
203- group . forEach ( item => {
204- // Use resolution-appropriate label
205- const label = getLabelForResolution ( item , resKey )
206- if ( label && label !== 'Unknown' ) {
207- labelCounts [ label ] = ( labelCounts [ label ] || 0 ) + 1
208- }
209- } )
210-
211- const mostCommon = Object . entries ( labelCounts )
212- . sort ( ( [ , a ] , [ , b ] ) => b - a ) [ 0 ] ?. [ 0 ] || 'Unknown'
213-
214- // Store how frequent each item's label is in this grid (for sorting)
215- group . forEach ( item => {
216- const { latitude, longitude } = validatePoint ( item . coordinates )
217- const coordKey = `${ Math . round ( latitude * multiplier ) / multiplier } ,${ Math . round ( longitude * multiplier ) / multiplier } `
218-
219- // Use resolution-appropriate label for frequency counting too
220- const itemLabel = getLabelForResolution ( item , resKey )
221- const frequency = labelCounts [ itemLabel ] || 0
222-
223- // Track max frequency across all resolutions
224- const currentFreq = itemFrequency . get ( coordKey ) || 0
225- if ( frequency > currentFreq ) {
226- itemFrequency . set ( coordKey , frequency )
227- }
228-
229- // Initialize map if needed
230- if ( ! labels . has ( coordKey ) ) {
231- labels . set ( coordKey , new Map < ResolutionKey , string > ( ) )
232- }
233-
234- // Store label for this resolution
235- labels . get ( coordKey ) ! . set ( resKey , mostCommon )
236- } )
237- } )
238- } )
239-
240- return { labels, itemFrequency }
241- }
0 commit comments