mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
475 stars 132 forks source link

Offline mode has very low resolution for `Style.SATELLITE_STREETS` tiles. Does `TilesetDescriptorOptions` ignore `.maxZoom()`? #2407

Open askat opened 4 months ago

askat commented 4 months ago

Environment

Observed behavior and steps to reproduce

I'm trying to implement offline mode for my app. User can draw a polygon which will be downloaded and displayed when there is no internet connection. I'm using code from Mapbox's documentation to download Style.SATELLITE_STREETS tiles.

The problem is unless I zoom to max before downloading Style.SATELLITE_STREETS map the quality of downloaded tiles is very low.

 private fun downloadPolygon() {
        val polygon = Polygon.fromLngLats(listOf(points)) // Polygon that user drawn

        val stylePackLoadOptions = StylePackLoadOptions.Builder()
            .glyphsRasterizationMode(GlyphsRasterizationMode.IDEOGRAPHS_RASTERIZED_LOCALLY)
            .build()

        val tilesetDescriptor = offlineManager.createTilesetDescriptor(
            TilesetDescriptorOptions.Builder()
                .styleURI(Style.SATELLITE_STREETS) // <-- Trying to download SATELLITE_STREETS tiles
                .pixelRatio(2f)
                .minZoom(12)
                .maxZoom(16) // <-- This isn't working for SATELLITE_STREETS
                .build()
        )

        val tileRegionLoadOptions = TileRegionLoadOptions.Builder()
            .geometry(polygon)
            .descriptors(listOf(tilesetDescriptor))
            .acceptExpired(true)
            .networkRestriction(NetworkRestriction.NONE)
            .build()

        offlineManager.loadStylePack(
            Style.SATELLITE_STREETS,
            stylePackLoadOptions,
            { progress -> },
            { expected -> }
        )

        tileStore.loadTileRegion(
            UUID.randomUUID().toString(), // Random id for region
            tileRegionLoadOptions,
            { progress -> }
        ) { expected -> }
    }

After download I disconnect phone from internet and try to view map but the quality of map is very bad. If I connect to internet again map quality increases.

I tried to test with different values for maxZoom() but quality is still bad when no internet

Expected behavior

Map's quality in offline mode must be the same as in online mode

Quality without internet

Screenshot_20240620_160845_MapboxSandbox

Quality with internet

Screenshot_20240620_161045_MapboxSandbox

Additional links and references

I found similar issue for iOS: https://github.com/mapbox/mapbox-maps-ios/issues/1056

kiryldz commented 4 months ago

@askat can you please share the camera state for the blurry screenshot (mapboxMap.cameraState) + enable couple debug options:

val debugOptions: MutableList<MapDebugOptions> = mutableListOf(
    MapDebugOptions.TILE_BORDERS,
    MapDebugOptions.PARSE_STATUS,
  )
mapboxMap.setDebug(debugOptions, true)
askat commented 4 months ago

@kiryldz I hope I got it right. 1) Here is the mapboxMap.cameraState log

[center: Point{type=Point, bbox=null, coordinates=[55.130000000000024, 25.120000000000015]}, padding: [top: 0.0, left: 0.0, bottom: 0.0, right: 0.0], zoom: 12.0, bearing: -0.0, pitch: 0.0]

2) Here is screenshot with debug enabled and internet disabled

Screenshot_20240625_145247_MapboxSandbox

askat commented 4 months ago

@kiryldz Here another screenshots:

Without internet

Screenshot_20240625_152002_MapboxSandbox

Right after I enabled internet

Screenshot_20240625_152021_MapboxSandbox

kiryldz commented 4 months ago

@askat thanks for addition information! I've reached to needed team and turned out we already have an internal ticket tracking this issue. I do not have any timelines sadly but if any new information will pop up - we will add it here, in this GH issue.

AntoBouteiller commented 2 months ago

@askat same issue than this one https://github.com/mapbox/mapbox-maps-android/issues/1460

The issue is not the resolution, the saved map is just not loaded, what you are seeing is the cached maps, this is why the resolution is ok if you zoom before downloading.

You need to add .pixelRatio(2f) to the tilesetDescriptor

@kiryldz I don't know if this will be fixed one day, but in the meantime would it be possible to update the documentation ?

askat commented 2 months ago

@AntoBouteiller Thanks for your response, Antoine. I already added .pixelRatio(2f) to the TilesetDescriptor as you can see in the issue description. Unfortunately it didn't fix this problem. Or maybe I'm trying to download tileset incorrectly. Did you try this solution yourself?

AntoBouteiller commented 2 months ago

@askat Sorry I didn't see that. Yes, it fixed the issue for me.

paulsUsername commented 1 month ago

We are experiencing the exact same issue above. On devices that seem to return less than 2.0 for:

hApplication.resources.displayMetrics.density

i.e. return 1.75 then the issue happens. When a device returns 2.0 or more there is no issue. This is only observation, I have no idea about causation. We are passing 2f for pixel ration. The values passed for max zoom seem to have no affect.

paulsUsername commented 1 month ago

One thing we have found is that, you need to ensure the style pack download has finished before you download the tilesets. Seems to resolve the issue, no idea why.