Add steepness labels#726
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances the MapLibre GeoJSON rendering pipeline by adding labeled route-extras (steepness/surface) and redesigning kilometer marker rendering to use combined icon+text symbol layers, with updated layer filtering and sorting to keep rendering order correct.
Changes:
- Add point-label features for route extras (steepness/surface) and a dedicated symbol layer to render them.
- Redesign km marker styling to use dynamically generated colored marker images plus text in a single symbol layer (including end marker).
- Update point-style filters and global layer sorting so extras labels and km marker layers render in the intended order without unintended point styling.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| app/javascript/maplibre/styles/styles.js | Excludes route-extras-label point features from generic point/click-hit styling. |
| app/javascript/maplibre/map.js | Updates layer sorting to position route-extras labels and km end markers appropriately. |
| app/javascript/maplibre/layers/geojson/route_extras.js | Generates label point features for steepness/surface and adds a new symbol layer for rendering them. |
| app/javascript/maplibre/layers/geojson/km_markers.js | Generates per-color marker images and replaces multi-layer km marker styling with combined symbol layers. |
| app/javascript/maplibre/layers/geojson.js | Initializes the new extras label style layer for GeoJSON layers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| filter: ['has', 'route-extras-label'], | ||
| layout: { | ||
| 'text-field': ['get', 'route-extras-label'], | ||
| 'text-font': ['noto_sans_bold'], |
There was a problem hiding this comment.
initializeExtrasLabelStyles hard-codes text-font to ['noto_sans_bold']. The rest of the MapLibre styling uses the basemap-provided/default font via labelFont / defaultFont; hard-coding a specific stack can cause labels to silently not render on basemaps whose glyphs don’t include noto_sans_bold. Use the same font stack as other labels (e.g., labelFont or [basemaps()[mapProperties.base_map].font || defaultFont]) to keep label rendering consistent across basemaps.
| 'text-font': ['noto_sans_bold'], |
| // Calculate segment length by summing consecutive point distances | ||
| let segmentLength = 0 | ||
| for (let i = startIdx; i < end; i++) { | ||
| segmentLength += distance(point(coords[i]), point(coords[i + 1]), { units: 'meters' }) | ||
| } |
There was a problem hiding this comment.
createExtrasLabelFeatures recomputes segment length by iterating over every coordinate pair and calling Turf distance() for each segment. For long routes with many extras segments this becomes expensive (nested loops), and similar distance computations are already performed elsewhere (e.g., totals/legend). Consider precomputing cumulative distances once per coords array and deriving each segment length in O(1), which will significantly reduce render-time work when toggling route extras.
| 'text-size': 12, | ||
| 'text-font': ['noto_sans_bold'], | ||
| 'text-justify': 'center', |
There was a problem hiding this comment.
The km end marker layer hard-codes text-font to ['noto_sans_bold'] while other km marker layers use labelFont (which is set from the active basemap). Hard-coding a specific font stack can break label rendering on basemaps whose glyph set doesn’t include noto_sans_bold. Prefer using labelFont here as well for consistent, basemap-compatible rendering.
|
@copilot check again |
All three review comments have already been addressed in commit 45cc0d0:
|
This pull request introduces significant improvements to the map rendering of kilometer markers and route extras in the MapLibre integration. The main changes include redesigning kilometer marker rendering with custom SVG icons, adding dynamic labels for route extras (such as steepness and surface segments), and updating layer sorting and style logic to accommodate these enhancements.
Map Rendering Enhancements:
Kilometer Markers:
Route Extras Labels:
Style and Layer Management:
styles.jsto prevent point styles from being applied to features with route extras labels, avoiding visual clutter or incorrect rendering. [1] [2] [3]These changes collectively enhance the usability and visual quality of the map, making route details and kilometer markers clearer and more informative for users.