From eada464fb359d9535db3be092e23b960e251be0a Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Sun, 13 Sep 2026 20:17:48 +0200 Subject: [PATCH] Highlight trails in their own color instead of recoloring to yellow --- public/js/hiking_trails.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/public/js/hiking_trails.js b/public/js/hiking_trails.js index 9d9312d..df9226b 100644 --- a/public/js/hiking_trails.js +++ b/public/js/hiking_trails.js @@ -202,7 +202,7 @@ export class HikingTrailsControl { const matched = features.filter((feature, i) => features.findIndex((f) => f.properties.id === feature.properties.id) === i); const html = matched.map((feature) => routeHtml(feature.properties)).join("
"); - this._setHighlight(matched.map((feature) => feature.geometry)); + this._setHighlight(matched.map((feature) => ({ geometry: feature.geometry, color: feature.properties.color }))); const popup = new Popup({ closeButton: true, maxWidth: "260px" }).setLngLat(event.lngLat).setHTML(html).addTo(this._map); this._trackPopup(popup); } @@ -249,7 +249,8 @@ export class HikingTrailsControl { // A newer click may have replaced this popup while Overpass was still // answering — don't paint a highlight for a selection that's already // stale. - if (this._activePopup === popup) this._setHighlight(relations.map(routeGeometry)); + if (this._activePopup === popup) + this._setHighlight(relations.map((relation) => ({ geometry: routeGeometry(relation), color: normalizedTrailColor(relation.tags?.colour) }))); } _addOnlineLayer() { @@ -313,13 +314,16 @@ export class HikingTrailsControl { if (this._map.getSource(offlineSourceId(code))) this._map.removeSource(offlineSourceId(code)); } - // geometries: an array of GeoJSON geometry objects (LineString or - // MultiLineString, mixed is fine) — everything the last click matched, - // drawn as one highlight layer on top of the base trail rendering. - _setHighlight(geometries) { + // features: an array of { geometry, color } — geometry a GeoJSON + // LineString or MultiLineString (mixed is fine), color the trail's own + // (already-normalized) colour — everything the last click matched, drawn + // as one highlight layer (a wider outline in the trail's own color, + // rather than a fixed color that would repaint it) on top of the base + // trail rendering. + _setHighlight(features) { const data = { type: "FeatureCollection", - features: geometries.map((geometry) => ({ type: "Feature", properties: {}, geometry })), + features: features.map(({ geometry, color }) => ({ type: "Feature", properties: { color }, geometry })), }; const source = this._map.getSource(HIGHLIGHT_SOURCE_ID); if (source) { @@ -332,7 +336,7 @@ export class HikingTrailsControl { type: "line", source: HIGHLIGHT_SOURCE_ID, layout: { "line-cap": "round", "line-join": "round" }, - paint: { "line-color": "#fff176", "line-width": 5, "line-opacity": 0.9 }, + paint: { "line-color": ["get", "color"], "line-width": 5, "line-opacity": 0.9 }, }); }