2

I try to put the current location indicator above everything else in my map.

I was sent to look into "layerAbove" but i have no layers, just style with icons generated using a symbol manager.

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
    // ...
    mapView.getMapAsync { mapboxMap ->

        //...
        mapboxMap.setStyle(getStyleBuilder(MAPBOX_STYLE)) { style ->
            val locationComponent = mapboxMap.locationComponent
            context?.let { context ->

                locationComponent.activateLocationComponent(context,style)
            }
            locationComponent.isLocationComponentEnabled = true
            val image: String = IMAGE_CONST
            val symbolManager = SymbolManager(mapView, mapboxMap, style)
            val symbolOptions = SymbolOptions()
                   .withLatLng(LatLng(myItem.latitude, myItem.longitude))
                   .withIconImage(image)
                   .withIconSize(1.1f)
                   .withZIndex(0)
            symbolManager.create(symbolOptions)            }

    }
}

private fun getStyleBuilder(styleUrl: String): Style.Builder {
    var builder = Style.Builder().fromUrl(styleUrl)
    builder = withImage(R.drawable.icon, IMAGE_CONST, builder)
    //...
    return builder

}

private fun withImage(image: Int, imageKey: String, builder: Style.Builder): Style.Builder {
    val generateBitmap = generateBitmap(image)
    return generateBitmap?.let {
        builder.withImage(imageKey, it)
    } ?: builder
}`

The result is that the added symbols are placed above the locationComponent, instead of below it.

shanih
  • 71
  • 4

0 Answers0