@@ -354,7 +354,7 @@ <h6 class="card-title mb-0">Selected Segment</h6>
354354 legendDropdown . appendChild ( pathInfo ) ;
355355 }
356356
357- // Function to switch color scheme
357+ // Function to switch color scheme (OPTIMIZED VERSION)
358358 function switchColorScheme ( scheme ) {
359359 currentColorScheme = scheme ;
360360
@@ -373,8 +373,33 @@ <h6 class="card-title mb-0">Selected Segment</h6>
373373 // Update legend
374374 updateLegend ( ) ;
375375
376- // Reload segments with new colors
377- loadSegmentsWithOverlapHandling ( ) ;
376+ // OPTIMIZED: Just update colors instead of reloading everything
377+ updateSegmentColors ( ) ;
378+ }
379+
380+ // OPTIMIZED: Efficient function to update only segment colors without recreation
381+ function updateSegmentColors ( ) {
382+ segmentLayers . forEach ( ( layer , segmentId ) => {
383+ // Find the segment data
384+ const segment = segmentsData . find ( s => s . id . toString ( ) === segmentId . toString ( ) ) ;
385+ if ( ! segment ) return ;
386+
387+ // Get the new color based on current scheme
388+ const newColor = getSegmentColor ( segment ) ;
389+
390+ // Update the layer style based on layer type
391+ if ( layer instanceof L . Polyline ) {
392+ // For simple polylines (fallback lines)
393+ layer . setStyle ( { color : newColor } ) ;
394+ } else if ( layer . eachLayer ) {
395+ // For GeoJSON layers, need to iterate through sublayers
396+ layer . eachLayer ( function ( subLayer ) {
397+ if ( subLayer . setStyle ) {
398+ subLayer . setStyle ( { color : newColor } ) ;
399+ }
400+ } ) ;
401+ }
402+ } ) ;
378403 }
379404
380405
0 commit comments