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
@@ -101,6 +101,50 @@ source uses — `public/js/dem.js`'s own point-elevation lookups
|
||||
(`shadow.js`'s terrain-shadow overlay) read the actual decoded tile
|
||||
size rather than assuming one, so this isn't a problem either way.
|
||||
|
||||
== Offline hiking trails
|
||||
|
||||
The sidebar's "Hiking trails" overlay works online out of the box
|
||||
(waymarkedtrails.org raster tiles, `public/js/hiking_trails.js`) —
|
||||
clicking a trail fires a one-off Overpass query for its name/colour/
|
||||
network/distance. For it to work offline too, `data/hiking_trails.geojson`
|
||||
is generated automatically as the last step of every `offline.pmtiles`
|
||||
build (`Maptool::HikingTrails`, `lib/maptool/hiking_trails.rb`), straight
|
||||
from the *same* per-country `.osm.pbf` files already downloaded for
|
||||
`offline.pmtiles` itself — no separate download, no third-party service:
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
osmium tags-filter country.osm.pbf r/route=hiking -o hiking.osm.pbf
|
||||
osmium add-locations-to-ways hiking.osm.pbf -o hiking-located.osm.pbf
|
||||
osmium cat hiking-located.osm.pbf -f opl,locations_on_ways=true,add_metadata=false -o hiking.opl
|
||||
----
|
||||
|
||||
`add-locations-to-ways` matters: a plain Geofabrik PBF's ways only carry
|
||||
bare node *references*, not coordinates, so skipping this step silently
|
||||
produces ways with empty x/y in the OPL output and every route gets
|
||||
dropped for having no usable geometry — not an error, just wrong output
|
||||
(verified against a real extract before this was caught). No general OSM
|
||||
tool stitches a route relation's member ways into one line for you
|
||||
(routes are a semantic grouping, not a geometry type), so
|
||||
`HikingTrails.parse_opl` does that walk itself — the same thing
|
||||
waymarkedtrails.org and this app's own online Overpass click handler
|
||||
already do.
|
||||
|
||||
Best-effort: a hiking-trails extraction problem on one country's PBF
|
||||
logs a warning and is skipped rather than failing the whole
|
||||
`offline.pmtiles` build over what's a bonus overlay, not the core map
|
||||
(`PmtilesBuilder.extract_hiking_trails`). Coordinates are rounded to 5
|
||||
decimal places (~1m, plenty for a rendered line) to keep the combined
|
||||
file smaller — for a many-country selection it can still be a sizeable
|
||||
GeoJSON (Slovakia alone: ~3000 routes, ~30MB unrounded), fetched
|
||||
client-side only once the overlay is actually toggled on, not on page
|
||||
load. `rake hiking:trails[pbf,out]` runs the extraction by hand against
|
||||
one `.osm.pbf` for testing.
|
||||
|
||||
`DELETE /api/offline-tiles` removes this file along with `offline.pmtiles`
|
||||
and the Geofabrik cache — there's no separate delete/rebuild route for it,
|
||||
since it's not an independent build.
|
||||
|
||||
== In-app regeneration
|
||||
|
||||
A logged-in user can also generate both files above from the app
|
||||
|
||||
Reference in new issue
Block a user