From db586c0166a25f31a07eaed9275fedd043f73c45 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Sun, 15 Nov 2026 10:16:45 +0100 Subject: [PATCH] One-way hiking route members (forward/backward roles) kept in their direction by maplibre-gl-lanes; raise Valhalla trace limits for the per-country route summary --- bin/routing-service.sh | 4 ++++ lib/maptool/hiking_trails.rb | 20 ++++++++++++++------ public/js/hiking_trails.js | 16 +++++++++++++++- test/test_hiking_trails.rb | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/bin/routing-service.sh b/bin/routing-service.sh index 92abc43..43ef2c7 100755 --- a/bin/routing-service.sh +++ b/bin/routing-service.sh @@ -31,9 +31,13 @@ os.replace(path + ".tmp", path) PY } +# trace limits: maptool reads the per-country km of a whole route (up to +# 5000 km, like route's own auto limit) from /trace_attributes; the +# defaults (200 km, 16000 points) are meant for GPS traces. config() { # dir valhalla_build_config --mjolnir-tile-dir "$1/tiles" --mjolnir-tile-extract "$1/tiles.tar" \ --mjolnir-admin "$1/admins.sqlite" --mjolnir-concurrency "${BUILD_THREADS:-$(( $(nproc) / 2 ))}" \ + --service-limits-trace-max-distance 5000000 --service-limits-trace-max-shape 500000 \ > "$1/valhalla.json" } diff --git a/lib/maptool/hiking_trails.rb b/lib/maptool/hiking_trails.rb index c891fcf..13b5d22 100644 --- a/lib/maptool/hiking_trails.rb +++ b/lib/maptool/hiking_trails.rb @@ -90,11 +90,17 @@ module Maptool end def self.relation_feature(relation, ways) - lines = relation[:members] - .select { |member| member[:type] == "w" } - .filter_map { |member| ways[member[:id]] } - .select { |coords| coords.size >= 2 } - return nil if lines.empty? + # A "forward"/"backward" member is walked one way only, along / against + # the way's own direction; reversed here so every line runs the way + # it's walked, and listed in oneway_lines (indexes into the lines). + members = relation[:members] + .select { |member| member[:type] == "w" } + .filter_map { |member| (coords = ways[member[:id]]) && [coords, member[:role]] } + .select { |coords, _| coords.size >= 2 } + return nil if members.empty? + + lines = members.map { |coords, role| role == "backward" ? coords.reverse : coords } + oneway = members.each_index.select { |i| %w[forward backward].include?(members[i][1]) } distance = lines.sum { |coords| TrackStats.compute(coords)["distance_meters"] } tags = relation[:tags] @@ -102,6 +108,7 @@ module Maptool "id" => relation[:id], "name" => tags["name"] || tags["description"], "distance_meters" => distance.round(1), + "oneway_lines" => oneway.empty? ? nil : oneway, } ROUTE_TAGS.each { |key| properties[key] ||= tags[key] } @@ -140,7 +147,8 @@ module Maptool return [] if raw.empty? raw.split(",").map do |member| - { type: member[0], id: member[1..].split("@", 2).first.to_i } + id, role = member[1..].split("@", 2) + { type: member[0], id: id.to_i, role: unescape(role.to_s) } end end private_class_method :members_field diff --git a/public/js/hiking_trails.js b/public/js/hiking_trails.js index 814829a..919ae95 100644 --- a/public/js/hiking_trails.js +++ b/public/js/hiking_trails.js @@ -229,7 +229,7 @@ export class HikingTrailsControl { const features = [...this._selectedCountries].flatMap((code) => this._trailData.get(code)?.features || []); let graph = null; if (features.length > 0) { - graph = buildLineGraph(features, { routeProperty: "id" }); + graph = buildLineGraph(features.flatMap(splitOneway), { routeProperty: "id", onewayProperty: "oneway" }); await orderLanesAsync(graph); } if (this._lanesBuild !== build) return; @@ -448,3 +448,17 @@ function routeHtml(info) { ); return parts.join(""); } + +// A route's one-way lines (oneway_lines, already pointing the way they're +// walked: lib/maptool/hiking_trails.rb) as a feature of their own marked +// oneway, so maplibre-gl-lanes keeps the route on them in that direction. +function splitOneway(feature) { + const oneway = new Set(feature.properties.oneway_lines); + if (oneway.size === 0) return [feature]; + const lines = feature.geometry.coordinates; + const part = (coordinates, properties) => ({ ...feature, properties, geometry: { type: "MultiLineString", coordinates } }); + return [ + part(lines.filter((_, i) => !oneway.has(i)), feature.properties), + part(lines.filter((_, i) => oneway.has(i)), { ...feature.properties, oneway: "yes" }), + ].filter((f) => f.geometry.coordinates.length > 0); +} diff --git a/test/test_hiking_trails.rb b/test/test_hiking_trails.rb index 92e1e1d..b44f523 100644 --- a/test/test_hiking_trails.rb +++ b/test/test_hiking_trails.rb @@ -24,6 +24,20 @@ class HikingTrailsTest < Minitest::Test assert_equal "Rysy", feature["properties"]["name"] end + def test_forward_and_backward_members_are_one_way_and_point_the_way_walked + opl = <<~OPL + w1 Thighway=path Nn10x20.0y49.0,n11x20.1y49.1 + w2 Thighway=path Nn11x20.1y49.1,n12x20.2y49.2 + w3 Thighway=path Nn13x20.3y49.3,n12x20.2y49.2 + r1 Troute=hiking,type=route,name=Loop Mw1@,w2@forward,w3@backward + OPL + + feature = Maptool::HikingTrails.parse_opl(opl)["features"].first + assert_equal [1, 2], feature["properties"]["oneway_lines"] + assert_equal [[20.2, 49.2], [20.3, 49.3]], feature["geometry"]["coordinates"][2] + assert_nil Maptool::HikingTrails.parse_opl(opl.sub("forward,w3@backward", ",w3@"))["features"].first["properties"]["oneway_lines"] + end + def test_parse_opl_skips_relations_that_are_not_route_hiking opl = <<~OPL w1 Thighway=path Nn10x20.087y49.179,n11x20.088y49.18