Wire offline hiking trails into the real build, API, and renderer
data/hiking_trails.geojson now generates automatically as the last step of every offline.pmtiles build (PmtilesBuilder.extract_hiking_trails, best-effort — a failure here doesn't fail the whole build), merged across all selected countries with cross-border dedup by OSM relation id (HikingTrails.extract_merged). Served at GET /tiles/hiking_trails.geojson and GET /api/hiking-trails, fetched client-side only once the overlay is actually toggled on. hiking_trails.js now prefers this local file whenever it exists, regardless of which base map (online/offline) is active — same "prefer local when available" story as HillshadeControl already uses for terrain. Offline click hit-tests the real vector layer directly (queryRenderedFeatures) instead of querying Overpass — instant, no network. Coordinates are rounded to 5dp to keep the combined file smaller; colour tag values are normalized against a known-safe set before ever reaching a style paint property. Verified extract_merged (new: combines multiple countries' extracts, dedupes overlapping relations) against two real cached country PBFs on brick directly, not just fixtures.
This commit is contained in:
1 parent
b35ace9734
commit
079ac37787
11 files changed
+370
-25
No files matched your search
@@ -89,6 +89,43 @@ class HikingTrailsTest < Minitest::Test
|
||||
assert_empty Maptool::HikingTrails.parse_opl(opl)["features"]
|
||||
end
|
||||
|
||||
def test_parse_opl_carries_the_osm_relation_id_for_cross_country_dedup
|
||||
opl = <<~OPL
|
||||
w1 Thighway=path Nn10x20.087y49.179,n11x20.088y49.18
|
||||
r1246205 Troute=hiking,type=route,name=Trail Mw1@
|
||||
OPL
|
||||
|
||||
feature = Maptool::HikingTrails.parse_opl(opl)["features"].first
|
||||
|
||||
assert_equal 1246205, feature["properties"]["id"]
|
||||
end
|
||||
|
||||
def test_parse_opl_rounds_coordinates_to_5_decimal_places
|
||||
opl = <<~OPL
|
||||
w1 Thighway=path Nn10x20.0876543210y49.1791234567,n11x20.0880000001y49.1800000009
|
||||
r1 Troute=hiking,type=route,name=Trail Mw1@
|
||||
OPL
|
||||
|
||||
coords = Maptool::HikingTrails.parse_opl(opl)["features"].first["geometry"]["coordinates"]
|
||||
|
||||
assert_equal [[[20.08765, 49.17912], [20.088, 49.18]]], coords
|
||||
end
|
||||
|
||||
def test_extract_merged_deduplicates_by_relation_id_across_files
|
||||
feature = ->(id) {
|
||||
{ "type" => "Feature", "properties" => { "id" => id, "name" => "Trail #{id}" }, "geometry" => { "type" => "MultiLineString", "coordinates" => [] } }
|
||||
}
|
||||
# Relation 1 shows up in both "country" files (a cross-border trail);
|
||||
# relation 2 only in the second.
|
||||
per_file = { "at.osm.pbf" => [feature.call(1)], "cz.osm.pbf" => [feature.call(1), feature.call(2)] }
|
||||
extract = ->(pbf_path) { { "type" => "FeatureCollection", "features" => per_file.fetch(pbf_path) } }
|
||||
|
||||
merged = Maptool::HikingTrails.extract_merged(%w[at.osm.pbf cz.osm.pbf], extract: extract)
|
||||
ids = merged["features"].map { |f| f["properties"]["id"] }.sort
|
||||
|
||||
assert_equal [1, 2], ids
|
||||
end
|
||||
|
||||
def test_parse_opl_ignores_a_dangling_member_reference_but_keeps_the_rest
|
||||
opl = <<~OPL
|
||||
w1 Thighway=path Nn10x20.087y49.179,n11x20.088y49.18
|
||||
|
||||
Reference in new issue
Block a user