Mapbox-gl-native: [android] Fragment add two map and second map is being transparent

Created on 27 Jan 2017  路  11Comments  路  Source: mapbox/mapbox-gl-native

Platform: Android
Mapbox SDK version: 4.2.2 and latest

Steps:

  1. Create single activity
  2. Create first fragment include full screen map (for example dark style)
  3. Add first fragment via SupportFragmentManager to "main_container"
    ...All correct
  4. Create second fragment with half map (in top side) and half semi transparent layout (in bottom side for example)
  5. Add second fragment via SupportFragmentManager to "main_container"
    ...
    Result: Map in second fragment fully transparent but mapbox logo is showed. And we see map from first fragment.

If don't add first layout, second layout is working correctly.
I created demo application for show
See: https://github.com/vacxe/MapboxMultilayerProblem

@bleege @tobrun folks, please help me

Most helpful comment

You can enable TextureView with either xml attributes:

    <com.mapbox.mapboxsdk.maps.MapView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:mapbox_renderTextureMode="true"/>

or MapboxMapOptions:

    MapboxMapOptions options = new MapboxMapOptions().textureMode(true);
    mapView = new MapView(this, options);

All 11 comments

@vacxe what you are noticing is a result of using a SurfaceView:

Provides a dedicated drawing surface embedded inside of a view hierarchy. The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it. This can be used to place overlays such as buttons on top of the Surface, though note however that it can have an impact on performance since a full alpha-blended composite will be performed each time the Surface changes.

This explains the issue a bit as the surfaces behind the Activity window are in front of each other and this isn't something that can be fixed with the views found in the viewhiearchy. One workaround for this is enabling texture mode on the one that isn't visible atm (you can do this through xml or MapboxMapOptions).

Closing as this is how gl surfaces work and we do not provide support for z ordering mulitple surfaces,

@tobrun thanks for explaining

@tobrun texture mode is deprecated though, right?

We use SurfaceView as preferred rendering surface as it's more performant in general (Android SDK View syncing is actually better on a TextureView). We keep the option of TextureView open as long as we can support it without too much trouble. Note that for 5.0.0 we are aiming to move from SurfaceView to GLSurfaceView. This moves rendering to a separate render thread and we are hoping on delivering improved performance. As a side effect the setup is very different than with SurfaceView/TextureView so we will probably remove support for TextureView if that feature lands. PR for that in #7736.

This bug still exists painfully!

@mhr9o20 this is worked as designed when using a SurfaceView, please use TextureView instead.
Update on depreciation notice, this is no longer deprecated and we will continue to support this.

@mhr9o2o actually it's not a bug. U can handle only one SurfaceView in yours view tree

Thanks for your responses, the problem is that this bug only exists on devices running <7 Androids.
Actually, this bug enforced us to change our single-activity paradigm and that was the painful part.
We're using the latest android arch-components, loading our fragments, sometimes in front of each other, using navigation component.
In our use-case, as a ride-hailing application, our main screen is a map, then for some other interactions we need to show another map to the user [which is another fragment], previously we've worked with google maps and we hadn't faced any issue, also, myself running the app on an Android Pie device, I hadn't encountered the issue until our QA team reported it.
So my question is, how should I use a TextureView in my view tree hierarchy? we're using the latest stable SDK version [6.5.0].

You can enable TextureView with either xml attributes:

    <com.mapbox.mapboxsdk.maps.MapView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:mapbox_renderTextureMode="true"/>

or MapboxMapOptions:

    MapboxMapOptions options = new MapboxMapOptions().textureMode(true);
    mapView = new MapView(this, options);

Thanks a million, I'll try this way as soon as possible and I'll inform you if anything was wrong.

As long as I could check, from API 17 to 28, using TextureView solved the issue. Thanks again.

Was this page helpful?
0 / 5 - 0 ratings