Loading cardinal-android/app/src/main/assets/style_dark.json +2 −2 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ "maxzoom": 6 } }, "sprite": "https://maps.earth/tileserver/styles/basic/sprite", "glyphs": "https://maps.earth/tileserver/fonts/{fontstack}/{range}.pbf", "sprite": "https://demotiles.maplibre.org/styles/osm-bright-gl-style/sprite", "glyphs": "https://tiles.openstreetmap.us/fonts/{fontstack}/{range}.pbf", "layers": [ { "id": "background", Loading cardinal-android/app/src/main/assets/style_light.json +2 −2 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ "maxzoom": 6 } }, "sprite": "https://maps.earth/tileserver/styles/basic/sprite", "glyphs": "https://maps.earth/tileserver/fonts/{fontstack}/{range}.pbf", "sprite": "https://demotiles.maplibre.org/styles/osm-bright-gl-style/sprite", "glyphs": "https://tiles.openstreetmap.us/fonts/{fontstack}/{range}.pbf", "layers": [ { "id": "background", Loading cardinal-android/app/src/main/java/earth/maps/cardinal/tileserver/LocalMapServer.kt +23 −9 Original line number Diff line number Diff line Loading @@ -269,7 +269,7 @@ class LocalMapServer( TAG, "Serving tile /openmaptiles/$z/$x/$y.pbf, size: ${tileData.size} bytes, gzipped: $isGzipped" ) // Only set gzip header for built-in database tiles // MapLibre needs this header when the tile bytes are still gzip-compressed. if (isGzipped) { call.response.header("content-encoding", "gzip") } Loading Loading @@ -520,15 +520,16 @@ class LocalMapServer( // First try to get tile from built-in database val tileData = basemapDatabase?.let { getTileData(it, z, x, tmsY) } if (tileData != null) { Log.d(TAG, "Tile found in basemap database") return Pair(tileData, true) // gzipped val isGzipped = tileData.isGzipCompressed() Log.d(TAG, "Tile found in basemap database, gzipped: $isGzipped") return Pair(tileData, isGzipped) } // If not found, try offline databases Log.d(TAG, "Tile not found in basemap database, checking offline databases") val offlineTileData = getTileDataFromOfflineDatabases(z, x, y) if (offlineTileData != null) { return Pair(offlineTileData, false) // not gzipped return Pair(offlineTileData, offlineTileData.isGzipCompressed()) } // Check if we should fetch from the internet (not in offline mode) Loading @@ -540,9 +541,9 @@ class LocalMapServer( if (internetTileData != null) { Log.d( TAG, "Successfully fetched tile from internet: size: ${internetTileData.size} bytes" "Successfully fetched tile from internet: size: ${internetTileData.first.size} bytes, gzipped: ${internetTileData.second}" ) return Pair(internetTileData, false) // not gzipped return internetTileData } } Loading @@ -559,7 +560,7 @@ class LocalMapServer( /** * Fetch tile data from the internet */ private suspend fun fetchTileFromInternet(z: Int, x: Long, y: Long): ByteArray? { private suspend fun fetchTileFromInternet(z: Int, x: Long, y: Long): Pair<ByteArray, Boolean>? { return try { val urlTemplate = context.getString(R.string.tile_url_template) val url = urlTemplate.replace("{z}", z.toString()).replace("{x}", x.toString()) Loading @@ -570,8 +571,13 @@ class LocalMapServer( if (response.status == HttpStatusCode.OK) { val bytes = response.bodyAsBytes() Log.d(TAG, "Successfully fetched tile from internet, size: ${bytes.size} bytes") bytes val isGzipped = bytes.isGzipCompressed() Log.d( TAG, "Successfully fetched tile from internet, size: ${bytes.size} bytes, gzipped: $isGzipped" ) Pair(bytes, isGzipped) } else { Log.w(TAG, "Failed to fetch tile from internet, status: ${response.status}") null Loading @@ -582,8 +588,16 @@ class LocalMapServer( } } private fun ByteArray.isGzipCompressed(): Boolean { return size >= 2 && this[0] == GZIP_MAGIC_FIRST_BYTE.toByte() && this[1] == GZIP_MAGIC_SECOND_BYTE.toByte() } companion object { private const val TAG = "LocalMapServer" private const val OFFLINE_DATABASE_NAME = "offline_areas.mbtiles" private const val GZIP_MAGIC_FIRST_BYTE = 0x1f private const val GZIP_MAGIC_SECOND_BYTE = 0x8b } } Loading
cardinal-android/app/src/main/assets/style_dark.json +2 −2 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ "maxzoom": 6 } }, "sprite": "https://maps.earth/tileserver/styles/basic/sprite", "glyphs": "https://maps.earth/tileserver/fonts/{fontstack}/{range}.pbf", "sprite": "https://demotiles.maplibre.org/styles/osm-bright-gl-style/sprite", "glyphs": "https://tiles.openstreetmap.us/fonts/{fontstack}/{range}.pbf", "layers": [ { "id": "background", Loading
cardinal-android/app/src/main/assets/style_light.json +2 −2 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ "maxzoom": 6 } }, "sprite": "https://maps.earth/tileserver/styles/basic/sprite", "glyphs": "https://maps.earth/tileserver/fonts/{fontstack}/{range}.pbf", "sprite": "https://demotiles.maplibre.org/styles/osm-bright-gl-style/sprite", "glyphs": "https://tiles.openstreetmap.us/fonts/{fontstack}/{range}.pbf", "layers": [ { "id": "background", Loading
cardinal-android/app/src/main/java/earth/maps/cardinal/tileserver/LocalMapServer.kt +23 −9 Original line number Diff line number Diff line Loading @@ -269,7 +269,7 @@ class LocalMapServer( TAG, "Serving tile /openmaptiles/$z/$x/$y.pbf, size: ${tileData.size} bytes, gzipped: $isGzipped" ) // Only set gzip header for built-in database tiles // MapLibre needs this header when the tile bytes are still gzip-compressed. if (isGzipped) { call.response.header("content-encoding", "gzip") } Loading Loading @@ -520,15 +520,16 @@ class LocalMapServer( // First try to get tile from built-in database val tileData = basemapDatabase?.let { getTileData(it, z, x, tmsY) } if (tileData != null) { Log.d(TAG, "Tile found in basemap database") return Pair(tileData, true) // gzipped val isGzipped = tileData.isGzipCompressed() Log.d(TAG, "Tile found in basemap database, gzipped: $isGzipped") return Pair(tileData, isGzipped) } // If not found, try offline databases Log.d(TAG, "Tile not found in basemap database, checking offline databases") val offlineTileData = getTileDataFromOfflineDatabases(z, x, y) if (offlineTileData != null) { return Pair(offlineTileData, false) // not gzipped return Pair(offlineTileData, offlineTileData.isGzipCompressed()) } // Check if we should fetch from the internet (not in offline mode) Loading @@ -540,9 +541,9 @@ class LocalMapServer( if (internetTileData != null) { Log.d( TAG, "Successfully fetched tile from internet: size: ${internetTileData.size} bytes" "Successfully fetched tile from internet: size: ${internetTileData.first.size} bytes, gzipped: ${internetTileData.second}" ) return Pair(internetTileData, false) // not gzipped return internetTileData } } Loading @@ -559,7 +560,7 @@ class LocalMapServer( /** * Fetch tile data from the internet */ private suspend fun fetchTileFromInternet(z: Int, x: Long, y: Long): ByteArray? { private suspend fun fetchTileFromInternet(z: Int, x: Long, y: Long): Pair<ByteArray, Boolean>? { return try { val urlTemplate = context.getString(R.string.tile_url_template) val url = urlTemplate.replace("{z}", z.toString()).replace("{x}", x.toString()) Loading @@ -570,8 +571,13 @@ class LocalMapServer( if (response.status == HttpStatusCode.OK) { val bytes = response.bodyAsBytes() Log.d(TAG, "Successfully fetched tile from internet, size: ${bytes.size} bytes") bytes val isGzipped = bytes.isGzipCompressed() Log.d( TAG, "Successfully fetched tile from internet, size: ${bytes.size} bytes, gzipped: $isGzipped" ) Pair(bytes, isGzipped) } else { Log.w(TAG, "Failed to fetch tile from internet, status: ${response.status}") null Loading @@ -582,8 +588,16 @@ class LocalMapServer( } } private fun ByteArray.isGzipCompressed(): Boolean { return size >= 2 && this[0] == GZIP_MAGIC_FIRST_BYTE.toByte() && this[1] == GZIP_MAGIC_SECOND_BYTE.toByte() } companion object { private const val TAG = "LocalMapServer" private const val OFFLINE_DATABASE_NAME = "offline_areas.mbtiles" private const val GZIP_MAGIC_FIRST_BYTE = 0x1f private const val GZIP_MAGIC_SECOND_BYTE = 0x8b } }