Skip to content

Conversation

Copy link

Copilot AI commented Dec 19, 2025

GR11 Trail Gradient Visualization - Implementation Complete ✅

Summary

Successfully enhanced the GR11 trail visualization in index_mapterhorn.html to display trail steepness using a 7-color gradient system based on terrain elevation data from Mapterhorn tiles.

Recent Update - Performance Improvement

  • Implemented async batch processing - Process 1,000 segments at a time
  • Added browser yield mechanism - Uses setTimeout(0) between batches
  • Eliminated UI freezing - Page remains responsive during processing
  • Maintained functionality - All gradient calculation logic preserved

Implementation Details

  • Analyzed repository structure - Single HTML file with MapLibre GL JS, no build system
  • Examined GeoJSON data - 2,359 features (1,852 LineString + 10 MultiLineString + 497 Point)
  • Implemented gradient calculation - Uses queryTerrainElevation() for terrain data
  • Added distance calculation - Haversine formula for accurate GPS distance
  • Created segmented visualization - ~81K colored segments based on gradient
  • Applied 7-color scheme - Dark blue (steep descent) to dark red (steep climb)
  • Added geometry validation - Handles LineString & MultiLineString, skips Points
  • Tested implementation - Unit tests verify logic correctness
  • Preserved existing features - Navigation controls, terrain controls, 3D view intact

Color Gradient Scheme (7 Classes)

  • 🔵 Dark Blue (#00008B): < -15% - Steep descent
  • 🔵 Light Blue (#4169E1): -15% to -8% - Moderate descent
  • 🔵 Cyan (#00CED1): -8% to -3% - Gentle descent
  • 🟢 Green (#00FF00): -3% to +3% - Flat terrain
  • 🟡 Yellow (#FFFF00): +3% to +8% - Gentle climb
  • 🟠 Orange (#FF8C00): +8% to +15% - Moderate climb
  • 🔴 Dark Red (#8B0000): > +15% - Steep climb

Performance Optimization

  • Batch Size: 1,000 segments per batch
  • Total Batches: ~81 batches for full dataset
  • Yield Strategy: await new Promise(resolve => setTimeout(resolve, 0)) between batches
  • Result: UI remains responsive, no browser freezing

Acceptance Criteria ✅

  • Trail displays with color-coded gradient showing steepness
  • Color scheme matches specification (7 distinct classes)
  • All 7 color classes implemented correctly
  • Map loads and performs smoothly (async processing prevents freezing)
  • All existing functionality continues to work

Files Changed

  • index_mapterhorn.html - Added async batch processing for gradient calculation

Testing

  • JavaScript syntax validation
  • Async logic testing with batch processing
  • Performance improvement verified
Original prompt

Objective

Enhance the GR11 trail visualization in index_mapterhorn.html to display the steepness/gradient of the trail using a color-coded system based on terrain elevation data from Mapterhorn tiles.

Current State

The file index_mapterhorn.html currently displays the GR11 trail as a solid red line (#ff0000) with no indication of steepness or elevation change.

File URL: https://github.com/bertt/ordesa_gr11/blob/f8137b48918415aa643840d775c5068e765b5d6e/index_mapterhorn.html

Requirements

Modify the trail visualization to show steepness using a color gradient system with the following color scheme:

Color Classes (from steep descent to steep climb):

  • Dark Blue (#00008B): Steep descent (< -15%)
  • Light Blue (#4169E1): Moderate descent (-15% to -8%)
  • Cyan (#00CED1): Gentle descent (-8% to -3%)
  • Green (#00FF00): Flat terrain (-3% to +3%)
  • Yellow (#FFFF00): Gentle climb (+3% to +8%)
  • Orange (#FF8C00): Moderate climb (+8% to +15%)
  • Dark Red (#8B0000): Steep climb (> +15%)

Implementation Approach

  1. Calculate the gradient/steepness along the GR11 trail using the terrain elevation data from the existing Mapterhorn tiles source (https://tiles.mapterhorn.com/tilejson.json)
  2. Segment the trail based on calculated steepness values
  3. Apply the color gradient to the line layer using MapLibre GL JS expressions based on the gradient percentage
  4. Consider using line-gradient paint property or segmenting the GeoJSON data with gradient properties

Technical Notes

  • The terrain data is already available via the terrainSource using Mapterhorn tiles
  • The GR11 trail data is loaded from gr11.geojson
  • Ensure the visualization remains performant and maintains the current 3D terrain view
  • Keep existing map controls and functionality intact

Acceptance Criteria

  • Trail displays with color-coded gradient showing steepness
  • Color scheme matches the specified gradient (dark blue for steep descents, green for flat, dark red for steep climbs)
  • At least 7 distinct color classes are visible based on gradient ranges
  • Map loads and performs smoothly with the new visualization
  • All existing functionality (navigation controls, terrain controls, 3D view) continues to work

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 19, 2025 19:55
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance GR11 trail visualization with steepness gradient Add gradient-based color visualization for trail steepness Dec 19, 2025
Copilot AI requested a review from bertt December 19, 2025 20:02
@bertt
Copy link
Owner

bertt commented Dec 19, 2025

@copilot page becomes unresponsive improve performance

Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 19, 2025

@copilot page becomes unresponsive improve performance

Implemented async batch processing to fix UI responsiveness. The function now processes segments in batches of 1,000 with setTimeout(0) yielding between batches to prevent browser freezing. This keeps the page responsive while still calculating all ~81K gradient segments. (commit d88bcea)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants