mapbox / mapbox/mapbox-maps-android

Offline: Downloaded tileRegion with specific pixelRatio in TileDescriptor wont show in the MapboxMap if it has a different pixelRatio

Open
#2,462 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Kotlin
Stars
578
Forks
161
PR merge metrics
No merged PRs in 30d

Description

## Environment

- Android OS version: Android 14
- Devices affected: Samsung Galaxy S24
- Maps SDK Version: 11.6.0 (both on Compose, and Views)

## Observed behavior and steps to reproduce

This is a problem, because the screen density may change at runtime. If an app downloads a tile region with the screen density at the time of download and if the screen density changes later, the downloaded region wont be able to show

To reproduce, download the style pack and tile region as in the example. One can modify the OfflineActivity example to easier reproduce the problem (go to [OfflineActivity sample, line 225](https://github.com/mapbox/mapbox-maps-android/blob/21bf717c3ea37403d492d7faad626ce1c536fe00/app/src/main/java/com/mapbox/maps/testapp/examples/OfflineActivity.kt#L225), and set the value to 1.0f and execute on a device with a pixel ratio different than 1.0f). The following code shows how to reproduce on Compose :

```
offlineManager.loadStylePack(
Style.SATELLITE_STREETS,
// Build Style pack load options
StylePackLoadOptions.Builder()
.glyphsRasterizationMode(GlyphsRasterizationMode.IDEOGRAPHS_RASTERIZED_LOCALLY)
.metadata(Value(STYLE_PACK_METADATA))
.build(),
{ progress ->
...
},
{ expected ->
...
}
)

val tilesetDescriptor = offlineManager.createTilesetDescriptor(
TilesetDescriptorOptions.Builder()
.styleURI(Style.SATELLITE_STREETS)
.pixelRatio(1f) <------------------------ Set to 1f to reproduce problem
.minZoom(0)
.maxZoom(16)
.build()
)

tileStore.loadTileRegion(
TILE_REGION_ID,
TileRegionLoadOptions.Builder()
.geometry(TOKYO)
.descriptors(listOf(tilesetDescriptor))
.metadata(Value(TILE_REGION_METADATA))
.acceptExpired(true)
.networkRestriction(NetworkRestriction.NONE)
.build(),
{ progress ->
...
},
{ expected ->
...
},
)
```

```
ExampleScaffold {
val density = LocalDensity.current

OfflineSwitch.getInstance().isMapboxStackConnected = false

val composeMapInitOptions = remember {
ComposeMapInitOptions(
mapOptions = MapOptions.Builder()
.applyDefaultParams(density.density) <--------- Using the default screen density, which may change at runtime
.contextMode(ContextMode.SHARED)
.build(),
)
}

val mapViewportState = rememberMapViewportState {
setCameraOptions(
CameraOptions.Builder()
.zoom(ZOOM)
.center(TOKYO)
.build()
)
}

val mapState = rememberMapState {
}

val rasterDemSourceState = rememberRasterDemSourceState {
url = StringValue("mapbox://mapbox.mapbox-terrain-dem-v1")
}

val customTerrainState = rememberTerrainState(rasterDemSourceState) {
exaggeration = DoubleValue(1.25)
}

val currentTerrainState by rememberSaveable(stateSaver = TerrainState.Saver) {
mutableStateOf(customTerrainState)
}

MapboxMap(
composeMapInitOptions = composeMapInitOptions,
compass = { },
scaleBar = {
ScaleBar(
alignment = Alignment.BottomStart,
contentPadding = PaddingValues(
start = 4.dp,
bottom = 32.dp,
),
isMetricUnit = true,
ratio = 0.3f,
)
},
logo = {
Logo()
},
attribution = {
Attribution(
)
},
mapViewportState = mapViewportState,
mapState = mapState,
style = {
MapStyle(
projection = Projection.GLOBE,
style = Style.SATELLITE_STREETS,
terrainState = currentTerrainState,
)
},
modifier = Modifier.fillMaxSize(),
) {
CircleAnnotation(
point = TOKYO,
) {
circleColor = androidx.compose.ui.graphics.Color.Blue
}
}
}
```

![Screenshot_20240820_163559_Mapbox_Maps_SDK_Test_App 1](https://github.com/user-attachments/assets/0e00d123-0a47-4399-a96c-0cea36057643)

![Screenshot_20240820_162149_Compose_Mapbox_Map_Test_App 1](https://github.com/user-attachments/assets/e8334880-33b0-48af-beff-b814b094bde7)

## Expected behavior

The map tiles should show correctly

![Screenshot_20240820_162552_Compose_Mapbox_Map_Test_App 1](https://github.com/user-attachments/assets/0eb76052-16d5-4a26-b6b7-75dbc6c6e18e)

## Notes / preliminary analysis

## Additional links and references

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with app/src/main/java/com/mapbox/maps/testapp/examples/OfflineActivity.kt around line 225 and trace the TilesetDescriptorOptions.pixelRatio used by the offline TileRegionLoadOptions. Reproduce with pixelRatio set to 1.0f on a device with a different density, then compare the Compose and Views paths. Done means the downloaded region's tiles display correctly after the runtime screen density differs from the download ratio.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.