Package-level declarations

Types

Link copied to clipboard
class ArchiveChangedException : IOException

The remote archive was replaced partway through a download, so tiles already fetched may be from another build.

Link copied to clipboard

Marching-squares contour generation, ported from the sibling iOS app's ContourGenerator.swift.

Link copied to clipboard
data class ContourIntervalBand(val minorMeters: Float, val indexMeters: Float)

A zoom band's minor/index spacing, always in meters — ContourIntervals.forZoom's metric flag only picks which round-number family (meters vs. feet-converted-to-meters) generated the values.

Link copied to clipboard

The zoom-banded contour interval table, ported verbatim from the sibling iOS app's ContourGenerator.swift:38-58 (ContourIntervals.intervals(forZoom:metric:)). indexMeters is always 5 × minorMeters in every band; every 5th minor line is an index line.

Link copied to clipboard
data class ContourLine(val elevationMeters: Float, val points: List<ContourPoint>)

One contour line at elevationMeters, already chained into a single connected polyline.

Link copied to clipboard
data class ContourPoint(val x: Float, val y: Float)

A point in a tile's own [0,1]×[0,1] unit square — same convention as the base offline layer's tile-local math.

Link copied to clipboard
data class ContourStyle(val strokeHexColor: String, val strokeWidth: Float, val strokeOpacity: Float)

A contour line's style, expressed as simplestyle-spec property values (stroke, stroke-width, stroke-opacity) rather than a platform color type — both renderers already consume simplestyle properties for imported layers (MapLibre's CustomLayers.kt style expressions; Google's applySimpleStyleSpec()), so a contour feature carrying these properties styles itself identically on both flavors with no per-flavor color logic to keep in sync.

Link copied to clipboard
Link copied to clipboard
class ElevationTile(val width: Int, val height: Int, val elevations: FloatArray)

A decoded elevation grid in meters, row-major with (0,0) at the image's top-left — the same orientation as the source tile's own pixels, and as org.meshtastic.app.map.offline.pmtiles.WebMercatorTileMath's tile-local Y (top-to-bottom, matching XYZ tile convention).

Link copied to clipboard
data class GeoBounds(val south: Double, val west: Double, val north: Double, val east: Double)

A geographic bounding box, degrees.

Link copied to clipboard
object Hillshade

Horn's-method hillshade, ported from the sibling iOS app's HillshadeTileOverlay.swift: shadow-only output (black RGB, alpha = shadow depth) so it composites correctly over both light and dark basemaps without a separate light-mode palette, plus the three cleanup passes iOS added against real artifacts in Puget Sound data — despiked water, sea-surface noise, and flattened-valley noise all showing up as fake terrain.

Link copied to clipboard
data class LonLat(val longitude: Double, val latitude: Double)

A point in geographic space, degrees — what TerrainTileMath.lonLatAt converts a tile-local position into.

Link copied to clipboard

Mapterhorn's two-tier PMTiles layout, ported from the sibling iOS app's mapterhorn-data-contract.md: a single global archive always available at low zoom, plus per-region high-res archives keyed by their own z6 tile coordinate, present only where source data coverage allows.

Link copied to clipboard
class RangeCheckedHttpChannel(url: URL) : UrlFileChannel

A PMTiles channel over HTTP range requests that only accepts the bytes it asked for. A 200 that ignored the Range header and a 206 whose Content-Range names other bytes both throw IOException. An ETag that differs from the first one seen, or goes missing after it, and a 416 for a range that used to exist throw ArchiveChangedException. Only a 404 throws FileNotFoundException.

Link copied to clipboard
sealed interface TerrainDownloadState
Link copied to clipboard
class TerrainRegionExtractor(store: TerrainTileStore, openArchive: (pmtilesUrl: String) -> TerrainRegionExtractor.TileArchive? = ::remoteArchive)

Extracts a region's offline terrain: a global low-res layer (always, up to MapterhornEndpoints.GLOBAL_MAX_ZOOM) plus a regional high-res layer from every z6 regional archive the bounds touch, each clipped to its own z6 tile. A z6 tile with no published archive contributes nothing, and the renderer falls back to the global layer there. One tile per HTTP request, like the base offline layer's own extractor; see its README for why that bounds MAX_TILES well below iOS's own per-region cap.

Link copied to clipboard

Mapterhorn's two-tier archive split: a global low-res layer always present, a regional high-res layer sometimes.

Link copied to clipboard

Fetches individual tiles from a remote PMTiles archive by range request — never the whole archive, just the bytes of the tile asked for. Here it's pointed at Mapterhorn's Terrarium elevation archives.

Link copied to clipboard

Standard XYZ/slippy-map Web Mercator tile math. Depends on no map stack, so the terrain extractor, the Google flavor's offline maps and MapLibre's node clustering share it.

Link copied to clipboard
class TerrainTileStore(fileSystem: FileSystem, baseDir: Path)

Raw Terrarium WebP tiles as a plain file hierarchy under baseDir: <baseDir>/<source>/<zoom>/<x>/<y>.webp.

Link copied to clipboard
data class TileIndex(val zoom: Int, val x: Int, val y: Int)

A single XYZ (google/osm-convention, not TMS) slippy-map tile index.

Functions

Link copied to clipboard

Decodes a Terrarium-encoded WebP tile (Mapterhorn's format) into meters-above-sea-level.

Decodes a Terrarium-encoded WebP tile (Mapterhorn's format) into meters-above-sea-level.

Decodes a Terrarium-encoded WebP tile (Mapterhorn's format) into meters-above-sea-level.

Link copied to clipboard
fun gunzipBounded(bytes: ByteArray, maxBytes: Int): ByteArray

Inflates gzip bytes, throwing IOException past maxBytes of output. GZIPInputStream already rejects data that isn't gzip and a truncated or corrupt stream (its trailer CRC and length are checked at end of input).

Link copied to clipboard

Opens the remote PMTiles archive at pmtilesUrl, or returns null when the host has no archive there (404).

Opens the remote PMTiles archive at pmtilesUrl, or returns null when the host has no archive there (404).

Link copied to clipboard
fun terrainTileCount(bounds: GeoBounds, maxZoom: Int): Long

How many tiles TerrainRegionExtractor.download asks for over bounds up to maxZoom: the global tier, plus the regional tier for every tile past it. An upper bound, since a z6 tile with no regional archive fetches nothing. Counted from tile corners, O(1) per zoom, so it is safe to call before deciding whether a download fits.

Link copied to clipboard
fun terrariumElevationMeters(red: Int, green: Int, blue: Int): Float