Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6d63e242b | ||
|
|
e94bfd1740 | ||
|
|
db586c0166 | ||
|
|
d810765de5 | ||
|
|
573e6b3455 |
No files matched your search
@@ -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"
|
||||
}
|
||||
|
||||
|
||||
@@ -90,11 +90,17 @@ module Maptool
|
||||
end
|
||||
|
||||
def self.relation_feature(relation, ways)
|
||||
lines = relation[:members]
|
||||
# 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| ways[member[:id]] }
|
||||
.select { |coords| coords.size >= 2 }
|
||||
return nil if lines.empty?
|
||||
.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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user