Compare commits
5
Commits
43119cfdae
...
a6d63e242b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6d63e242b | ||
|
|
e94bfd1740 | ||
|
|
db586c0166 | ||
|
|
d810765de5 | ||
|
|
573e6b3455 |
No files matched your search
@@ -31,9 +31,13 @@ os.replace(path + ".tmp", path)
|
|||||||
PY
|
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
|
config() { # dir
|
||||||
valhalla_build_config --mjolnir-tile-dir "$1/tiles" --mjolnir-tile-extract "$1/tiles.tar" \
|
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 ))}" \
|
--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"
|
> "$1/valhalla.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,11 +90,17 @@ module Maptool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.relation_feature(relation, ways)
|
def self.relation_feature(relation, ways)
|
||||||
lines = relation[:members]
|
# A "forward"/"backward" member is walked one way only, along / against
|
||||||
.select { |member| member[:type] == "w" }
|
# the way's own direction; reversed here so every line runs the way
|
||||||
.filter_map { |member| ways[member[:id]] }
|
# it's walked, and listed in oneway_lines (indexes into the lines).
|
||||||
.select { |coords| coords.size >= 2 }
|
members = relation[:members]
|
||||||
return nil if lines.empty?
|
.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"] }
|
distance = lines.sum { |coords| TrackStats.compute(coords)["distance_meters"] }
|
||||||
tags = relation[:tags]
|
tags = relation[:tags]
|
||||||
@@ -102,6 +108,7 @@ module Maptool
|
|||||||
"id" => relation[:id],
|
"id" => relation[:id],
|
||||||
"name" => tags["name"] || tags["description"],
|
"name" => tags["name"] || tags["description"],
|
||||||
"distance_meters" => distance.round(1),
|
"distance_meters" => distance.round(1),
|
||||||
|
"oneway_lines" => oneway.empty? ? nil : oneway,
|
||||||
}
|
}
|
||||||
ROUTE_TAGS.each { |key| properties[key] ||= tags[key] }
|
ROUTE_TAGS.each { |key| properties[key] ||= tags[key] }
|
||||||
|
|
||||||
@@ -140,7 +147,8 @@ module Maptool
|
|||||||
return [] if raw.empty?
|
return [] if raw.empty?
|
||||||
|
|
||||||
raw.split(",").map do |member|
|
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
|
||||||
end
|
end
|
||||||
private_class_method :members_field
|
private_class_method :members_field
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ export class HikingTrailsControl {
|
|||||||
const features = [...this._selectedCountries].flatMap((code) => this._trailData.get(code)?.features || []);
|
const features = [...this._selectedCountries].flatMap((code) => this._trailData.get(code)?.features || []);
|
||||||
let graph = null;
|
let graph = null;
|
||||||
if (features.length > 0) {
|
if (features.length > 0) {
|
||||||
graph = buildLineGraph(features, { routeProperty: "id" });
|
graph = buildLineGraph(features.flatMap(splitOneway), { routeProperty: "id", onewayProperty: "oneway" });
|
||||||
await orderLanesAsync(graph);
|
await orderLanesAsync(graph);
|
||||||
}
|
}
|
||||||
if (this._lanesBuild !== build) return;
|
if (this._lanesBuild !== build) return;
|
||||||
@@ -448,3 +448,17 @@ function routeHtml(info) {
|
|||||||
);
|
);
|
||||||
return parts.join("");
|
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"]
|
assert_equal "Rysy", feature["properties"]["name"]
|
||||||
end
|
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
|
def test_parse_opl_skips_relations_that_are_not_route_hiking
|
||||||
opl = <<~OPL
|
opl = <<~OPL
|
||||||
w1 Thighway=path Nn10x20.087y49.179,n11x20.088y49.18
|
w1 Thighway=path Nn10x20.087y49.179,n11x20.088y49.18
|
||||||
|
|||||||
Reference in new issue
Block a user