TerrainTileMath

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.

Functions

Link copied to clipboard
fun ancestorAt(zoom: Int, tile: TileIndex): TileIndex

The tile at zoom that contains tile; zoom must not be deeper than tile's own.

Link copied to clipboard
fun lonLatAt(zoom: Int, tileX: Double, tileY: Double): LonLat

lonLatAt for a point given in fractional tile units at zoom, e.g. x = 3.25 is a quarter into column 3.

fun lonLatAt(tile: TileIndex, localX: Float, localY: Float): LonLat

Inverse of tileAt: the geographic point at a fractional position within tile — localX/localY in the tile's own [0,1]×[0,1] unit square, the same convention ContourPoint uses. Needed to place contour geometry (which ContourGenerator emits tile-local) on a real map; nothing here needed the inverse before.

Link copied to clipboard
fun tileAt(zoom: Int, latitude: Double, longitude: Double): TileIndex
Link copied to clipboard
fun tileCountAt(zoom: Int, bounds: GeoBounds): Long

How many tiles tilesAt would return for zoom/bounds, computed from the two corner indices rather than by materializing the list — stays O(1) per zoom regardless of how large the actual count is. Shared by TerrainRegionExtractor (to bound memory before enumerating) and :feature:map-maplibre's own pre-download estimate shown in the layers sheet.

Link copied to clipboard
fun tilesAt(zoom: Int, bounds: GeoBounds): List<TileIndex>

Every tile in bounds at zoom, inclusive of both corners' own tiles. Antimeridian-aware — see xRangesAt.

Link copied to clipboard
fun worldFraction(latitude: Double, longitude: Double): Pair<Double, Double>

Where a point falls on the Web Mercator world, from 0.0 at the northwest corner to 1.0 on each axis.