Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bamsbamx opened this issue Aug 20, 2024 · 1 comment
Labels
bug 🪲 Something isn't working

Comments

@bamsbamx
Copy link

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, 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

Screenshot_20240820_162149_Compose_Mapbox_Map_Test_App 1

Expected behavior

The map tiles should show correctly

Screenshot_20240820_162552_Compose_Mapbox_Map_Test_App 1

Notes / preliminary analysis

Additional links and references

@bamsbamx bamsbamx added the bug 🪲 Something isn't working label Aug 20, 2024
@kiryldz
Copy link
Contributor

kiryldz commented Aug 21, 2024

@bamsbamx can you provide a bit more context how can screen density change in runtime? This seems to be more of a hardware property and usually should be set as context.resources.displayMetrics.density.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants