Build terrain.pmtiles from Mapterhorn instead of fetching tiles ourselves
Mapterhorn (mapterhorn.com, Protomaps-affiliated) publishes pre-built Terrarium-encoded terrain as PMTiles: a global planet.pmtiles (z0-12) plus ~450 regional chunks (z13+). Same pmtiles extract --bbox=... mechanism offline.pmtiles already uses, just against their files — confirmed live against their real manifest and the documented Interlaken example. Replaces fetching every individual tile ourselves (even after this session's earlier concurrency fix, still tens of minutes for a real region) with 1-3 extract calls plus a merge when the bbox spans more than one chunk: seconds, not minutes. Removes CONCURRENT_TILE_FETCHES, write_terrarium_mbtiles, tile_range, lng/lat_to_tile_x/y, fetch_terrarium_tile, and the sqlite3 gem entirely — none of it is needed once the tiles arrive pre-packaged. dem.js's point-elevation lookup (shadow.js's terrain-shadow overlay) hardcoded a 256px PNG tile assumption that Mapterhorn's 512px WebP tiles would have silently broken — now reads the actually-decoded tile's own size and mime type instead of assuming either.
This commit is contained in:
1 parent
d041c21270
commit
f89dea5805
8 files changed
+224
-234
No files matched your search
+28
-12
@@ -58,13 +58,28 @@ no API key). For it to work offline too, place a PMTiles archive of
|
||||
Terrarium-encoded `raster-dem` tiles at `data/terrain.pmtiles`
|
||||
(`GET /api/terrain-tiles` reports `available: true` once it's there,
|
||||
same pattern as offline map data above). Also generatable in-app (see
|
||||
below) or by hand — build one locally from a DEM source (e.g.
|
||||
Copernicus GLO-30 or SRTM) with a tool like
|
||||
https://github.com/mapbox/rio-rgbify[rio-rgbify] (GeoTIFF ->
|
||||
Terrarium-encoded PNG tiles in an `.mbtiles`), then
|
||||
`pmtiles convert out.mbtiles data/terrain.pmtiles` with
|
||||
https://github.com/protomaps/go-pmtiles[go-pmtiles], same as
|
||||
`data/offline.pmtiles`.
|
||||
below) or by hand, the same `go-pmtiles extract` mechanism as
|
||||
`data/offline.pmtiles` above — but from
|
||||
https://mapterhorn.com[Mapterhorn], a Protomaps-affiliated project
|
||||
publishing pre-built Terrarium-encoded terrain as PMTiles (a global
|
||||
`planet.pmtiles`, z0-12, plus ~450 regional chunks covering z13 and up
|
||||
— see https://mapterhorn.com/data-access/[their own data-access page]
|
||||
for the full manifest and per-source license/attribution details, CC-BY-4.0
|
||||
and similar, varying by region):
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
pmtiles extract https://download.mapterhorn.com/planet.pmtiles planet-extract.pmtiles --bbox=west,south,east,north --maxzoom=15
|
||||
# only if a regional chunk covers the bbox too (see download_urls.json) —
|
||||
# most bboxes hit exactly one, a bbox straddling a chunk boundary hits two:
|
||||
pmtiles extract https://download.mapterhorn.com/<chunk>.pmtiles chunk-extract.pmtiles --bbox=west,south,east,north --maxzoom=15
|
||||
pmtiles merge planet-extract.pmtiles chunk-extract.pmtiles data/terrain.pmtiles
|
||||
----
|
||||
|
||||
Tiles are 512px WebP, not the 256px PNG this app's *online* Terrarium
|
||||
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.
|
||||
|
||||
== In-app regeneration
|
||||
|
||||
@@ -78,11 +93,12 @@ wraps exactly the manual `go-pmtiles` workflows documented above
|
||||
(`lib/maptool/pmtiles_builder.rb`) — the server needs the
|
||||
https://github.com/protomaps/go-pmtiles[go-pmtiles] CLI installed and
|
||||
on `PATH` (override with the `PMTILES_BIN` env var if it lives
|
||||
somewhere else); regenerating terrain.pmtiles this way fetches
|
||||
individual Terrarium tiles itself and packs them into an MBTiles file
|
||||
(the `sqlite3` gem) before the same `pmtiles convert` step, since no
|
||||
public Terrarium-encoded PMTiles archive exists to `extract` from the
|
||||
way offline.pmtiles above can.
|
||||
somewhere else). Fetches Mapterhorn's own small JSON manifest to work
|
||||
out which regional chunk(s), if any, intersect the bbox, `extract`s
|
||||
each (plus `planet.pmtiles`, always), then `merge`s them if there was
|
||||
more than one — typically seconds, not the tens of minutes an earlier
|
||||
version of this (fetching every individual Terrarium tile itself) used
|
||||
to take for a real-sized region.
|
||||
|
||||
A build runs in the background (`POST /api/offline-tiles/build` /
|
||||
`/api/terrain-tiles/build`, polled via the matching `*/build-status`
|
||||
|
||||
@@ -82,6 +82,15 @@ The online map style (not vendored, fetched at runtime when the
|
||||
https://tiles.openfreemap.org/styles/liberty[OpenFreeMap "liberty"],
|
||||
built from https://www.openstreetmap.org[OpenStreetMap] data.
|
||||
|
||||
`terrain.pmtiles` (`lib/maptool/pmtiles_builder.rb`'s in-app
|
||||
regeneration, or the manual recipe in `docs/development.adoc`) is
|
||||
extracted at build time, not vendored, from
|
||||
https://mapterhorn.com[Mapterhorn] — a Protomaps-affiliated project
|
||||
publishing pre-built Terrarium-encoded terrain as PMTiles. Per-region
|
||||
source licenses vary (CC-BY-4.0 and similar); see
|
||||
https://download.mapterhorn.com/attribution.json[their own attribution
|
||||
list] for the full provenance.
|
||||
|
||||
Not a frontend asset like the above, but also baked into this app's own
|
||||
Docker image (not a separate container the way kiwix-serve/gpsd are —
|
||||
see `docs/deployment.adoc`/`docs/development.adoc`): the `pmtiles` CLI
|
||||
|
||||
Reference in new issue
Block a user