mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.38k stars 1.32k forks source link

Map is completely dark in dialogfragment, Android #13131

Closed Pieter-127 closed 6 years ago

Pieter-127 commented 6 years ago

Making use of the mapbox snapshotter to take a picture of the map I need, on click of the map trying to show a dialog fragment with the entire mapview. The snapshotter works perfectly fine, but the dialog i'm creating more often than not just shows the mapview entirely blacked out. Occasionally it works, although mostly it goes black.

Steps to reproduce

  1. Image view being populated with map snapshotter
  2. OnClick listener for image
  3. Show DialogFragment

class MapDialogFragment : DialogFragment() {

private lateinit var mapProperties: MapProperties

private var mapBoxView: MapView? = null
private var mapBoxMap: MapboxMap? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val view = inflater.inflate(R.layout.map_dialog_fragment, container, false)
    mapBoxView = view.findViewById(R.id.mapBoxViewInFragment)

    return view
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    toolbar.setNavigationOnClickListener {
        dismissAllowingStateLoss()
    }

    mapProperties = arguments?.getParcelable(MAP_PROPERTIES) ?: return

    toolbar.title = mapProperties.title

    mapBoxView?.getMapAsync {
        mapBoxMap = it

        mapBoxMap?.setStyleUrl(mapProperties.style)

        mapBoxMap?.clear()

        mapProperties.markers?.forEach { entry ->
            mapBoxMap?.addMarker(MarkerOptions()
                    .position(LatLng(entry.value.lat, entry.value.lon)))
        }

        mapBoxMap?.cameraPosition = CameraPosition.Builder()
                .target(LatLng(mapProperties.latitude, mapProperties.longitude))
                .zoom(mapProperties.zoom)
                .build()
    }
}

companion object {
    fun newInstance(mapProperties: MapProperties): MapDialogFragment {

        val extras = Bundle().apply { putParcelable(MAP_PROPERTIES, mapProperties) }

        return MapDialogFragment().apply {
            setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_Dialog)
            arguments = extras
        }
    }

    private const val MAP_PROPERTIES = "MAP_PROPERTIES"
}

}

Expected behavior

Map shows mapboxcapture

Actual behavior

Map goes entirely dark image

Configuration

Android versions: API 23 Device models: Pixel 2 Mapbox SDK versions: 6.2.0 - 6.5.0

tobrun commented 6 years ago

@PieterVenter77 this issue will stem from using GLSurfaceView as render surface. For this use-case you will need to use a TextureView instead. You can enable this feature by either in xml attributes:

mapbox_renderTextureMode=true

or

programatically with:

 MapboxMapOptions#textureMode(true)

This should fix your use-case, let us know if it didn't, closing as answered.