Galileo

The library that renders vector tile maps via the galileo engine into an OpenGL texture, for use with KMP/CMP on Aurora OS.

Permissions

Permissions=Internet

Dependency libraries

  • ssl
  • crypto
  • fontconfig

Features

Map

  • Vector tile maps (OpenFreeMap by default, any {z}/{x}/{y} URL template).
  • Event-driven rendering into an OpenGL texture, drawn via Skia.
  • Continuous zoom, camera state (center, zoom, size).
  • Tap picking of map features (top-most first).
  • Geographic <-> screen coordinate conversion.
  • Attribution text for the current tile source.

Styles

  • Builtin preset styles: light, dark, mono.
  • Custom galileo VectorTileStyle JSON.
  • Style download by URL (MapLibre styles converted, subset) with disk cache.
  • Label language override ({name} -> {name:<lang>}).

Overlays

  • GeoJSON overlays (routes, zones, points) rendered in the same frame.
  • Add/replace/remove by caller-defined id.

Tile sources and cache

  • Local MBTiles files (first-file-wins order).
  • Persistent tile cache: enabled, disabled, offline (cached tiles only).
  • Cache clearing (tiles and downloaded styles).

Events

  • mapReady, tileLoad, stateChanged, featurePicked, needRedraw, errors.

Example

class AuroraMap {
    private val map = AuroraGalileo(
        width = 512,
        height = 512,
        tilesUrl = "https://tiles.openfreemap.org/planet/{z}/{x}/{y}",
        lat = 55.7558,
        lon = 37.6173,
        zoom = 10,
    )

    fun release() {
        map.release()
    }

    fun getState(): GalileoMapState = map.getState()

    fun setState(state: GalileoMapState) {
        map.setState(state)
    }

    fun setStyle(style: BuiltinStyle): Boolean {
        return map.setStyle(style)
    }

    fun setLanguage(language: String) {
        map.setLanguage(language)
    }

    fun getAttribution(): String {
        return map.getAttribution()
    }

    fun addRoute(id: String, geojson: String): Boolean {
        return map.addGeoJson(id, geojson)
    }

    fun removeRoute(id: String): Boolean {
        return map.removeGeoJson(id)
    }

    fun onTouch(x: Double, y: Double, phase: TouchPhase) {
        map.input(x, y, phase)
    }

    fun screenToLatlon(x: Double, y: Double): Pair<Double, Double>? {
        return map.screenToLatlon(x, y)
    }

    fun collectEvents() = runBlocking {
        launch { map.mapReady.collect { println("map ready") } }
        launch { map.tileLoad.collect { loading -> println("tiles loading: $loading") } }
        launch { map.stateChanged.collect { println("state: $it") } }
        launch { map.featurePicked.collect { features -> println("picked: $features") } }
        launch { map.errors.collect { error -> println("error: $error") } }
    }

    // Drawing: call from a Canvas draw scope on the render thread
    fun draw(canvas: Canvas, x: Float, y: Float, width: Float, height: Float) {
        map.drawFrame(canvas, x, y, width, height)
    }
}

object MapSettings {
    fun enableCache() {
        // per-instance
    }

    fun offlineMode(map: AuroraMap) {
        map.map.cacheEnable()
        map.map.cacheOffline()
    }

    fun clearCache() {
        AuroraGalileo.cacheClear()
    }

    fun localTiles(map: AuroraMap, paths: List<String>) {
        map.map.setTiles(*paths.toTypedArray())
    }
}